As the Windows operating system evolves and the API interface for capturing video evolves, Microsoft offers the VFW, DirectShow and Mediafoundation interfaces. VFW has long been replaced by DirectShow, and the latest mediafoundation is supported by Windows Vista and Windows 7. Unfortunately, the above interfaces are based on COM technology and are very flexible and are not easy to use directly in. Net.
. NET Encapsulation
Foreigners have a lot of live Lei Feng, they dedicated a lot of open source projects, Directshow.net is the DirectShow encapsulation, and Mediafoundation.net is the mediafoundation encapsulation. They can all be found on the http://sourceforge.net. The class library after these two packages is basically a relationship with the original COM one by one, and can be used for video capture, but it's not easy to use.
Through constant Google searches, I think the following libraries are good for capturing video capture: Directx.capture, OpenCv, EMGUCV, and Aforge.
Directx.capture
Directx.capture is a project published on CodeProject that can easily capture video and audio, preview the window, and save the results to a file. Examples of using directx.capture are as follows:
Directx.capture
Capture capture = new Capture( Filters.VideoInputDevices [0],
Filters.AudioInputDevices[1] );
capture.Filename = "C:\MyVideo.avi";
capture.Start();
//...
capture.Stop();
However, it does not provide a way to get the contents of a frame separately. If you just need to preview and save the video, it works fine.
OpenCv
OpenCV the VFW and DirectShow video capture part of the good encapsulation, can easily get the content of a frame, you can also save the results to the video file. Examples of using OpenCV are as follows:
OpenCv
IntPtr ptrCapture = CvInvoke.cvCreateCameraCapture (param.deviceInfo.Index);
while (!stop)
{
IntPtr ptrImage = CvInvoke.cvQueryFrame (ptrCapture);
lock (lockObject)
{
stop = stopCapture;
}
}
CvInvoke.cvReleaseCapture(ref ptrCapture);