After n multi-research, finally selected OpenCV (Emgu CV)
* * As for DirectShow, OpenCV and so on other people can Baidu, here I will not repeat
Environment: VS2010 vs2012 vs2013 are available
OPENCV official website is: EMGU CV
can also go to my Baidu network disk download installation package: libemgucv-windows-universal-cuda-2.4.10.1940
Then you can think how to play, how to play.
After installation:
One of my demos, used to turn on the camera:
: C # calls the camera
Code structure:
Operating effect:
Core code Explanation:
namespacecameracapture{ Public Partial classCameracapture:form {Private ReadOnlyCapture _capture; Private BOOL_captureinprogress; Publiccameracapture ()//constructor {InitializeComponent (); Try{_capture=NewCapture ();//construct a camera instance _capture. Imagegrabbed+=processframe;//image Capture Event}Catch(NullReferenceException excpt) {MessageBox.Show (excpt. Message); } } Private voidProcessframe (Objectsender, EventArgs Arg) {Image<BGR, byte> frame =_capture. Retrievebgrframe ();//Get video frame Image<gray, byte> grayframe = frame. Convert<gray, byte>(); Image<gray, byte> smallgrayframe =Grayframe.pyrdown (); Image<gray, byte> smoothedgrayframe =Smallgrayframe.pyrup (); Image<gray, byte> cannyframe = Smoothedgrayframe.canny ( -, -); Captureimagebox.image=frame; Grayscaleimagebox.image=Grayframe; Smoothedgrayscaleimagebox.image=Smoothedgrayframe; Cannyimagebox.image=cannyframe;//turn into a picture and display it on the main screen}Private voidCapturebuttonclick (Objectsender, EventArgs e) { if(_capture! =NULL) { if(_captureinprogress) {//Stop the CaptureCapturebutton.text ="Start Capture"; _capture. Pause (); } Else { //Start the CaptureCapturebutton.text ="Stop"; _capture. Start (); } _captureinprogress= !_captureinprogress; } } Private voidreleasedata ()//release resource {if(_capture! =NULL) _capture. Dispose (); } Private voidFliphorizontalbuttonclick (Objectsender, EventArgs e) { if(_capture! =NULL) _capture. FlipHorizontal =!_capture. FlipHorizontal; } Private voidFlipverticalbuttonclick (Objectsender, EventArgs e) { if(_capture! =NULL) _capture. FlipVertical =!_capture. flipvertical; } }}
Extended
EMGUCV can not only control the camera, but also can play the local video directly, but need some configuration
PublicCameracapture () {InitializeComponent (); Try { //_capture = new Capture (); varFileName ="file Address"; _capture=NewCapture (fileName); _capture. Imagegrabbed+=Processframe; } Catch(NullReferenceException excpt) {MessageBox.Show (excpt. Message); } }
There are two third-party files to download:
Opencv_ffmpeg.dll
Opencv_ffmpeg_64.dll
Three-way plugin can go to github opencv download three-party control, my Baidu network disk: Opencv_ffmpeg
These two files need to re-change the name (because add in error, always can not afford, Google long time):
Opencv_ffmpeg.dll opencv_ffmpegVersion. dll, Opencv_ffmpeg2410_64.dll
Opencv_ffmpeg_64.dll opencv_ffmpegVersion_64.dll-opencv_ffmpeg2410_64.dll
The last copy is added to the bin directory under X86,x64 to play the local video.
The effect is as follows:
If you have any questions, you can stand inside.
C # Remote monitoring (2) Camera research