The article Introduction: To capture the video need to manually intercept or frame to intercept the picture, this article intends to implement this function. Can be intercepted multiple times, arbitrary frames. Operating instructions: The space bar began to intercept, enter the exit video. Development environment: EMGU2.4.9 + VS2010 +win7 (64).
public void Videocatch (string filepath) {try {IntPtr CATCHFR Ame =cvinvoke.cvcreatefilecapture (filepath); Cvinvoke.cvnamedwindow ("open video"); Get the total number of frames Cvinvoke.cvgetcaptureproperty (Catchframe, Emgu.CV.CvEnum.CAP_PROP. Cv_cap_prop_frame_count); Video width int wd = (int) cvinvoke.cvgetcaptureproperty (Catchframe, Emgu.CV.CvEnum.CAP_PROP. Cv_cap_prop_frame_width); Video height int hg = (int) cvinvoke.cvgetcaptureproperty (Catchframe, Emgu.CV.CvEnum.CAP_PROP. Cv_cap_prop_frame_height); Current frame position Cvinvoke.cvgetcaptureproperty (Catchframe, Emgu.CV.CvEnum.CAP_PROP. Cv_cap_prop_pos_frames); Frame frequency cvinvoke.cvgetcaptureproperty (Catchframe, Emgu.CV.CvEnum.CAP_PROP. CV_CAP_PROP_FPS); while (true) {var frameimg = Cvinvoke.cvqueryframe (catchframe); Cvinvoke.cvshowimage ("Open video", frameimg); IMAGE<BGR, byte> framepic = new IMAGE<BGR, byte> (WD,HG); Cvinvoke.cvcopy (Frameimg,framepic,intptr.zero); int c = Cvinvoke.cvwaitkey (20); if (c = =) break; if (c = =) {Random rd = new random (); Bitmap BT = new Bitmap (Framepic.tobitmap ()); string picname = Rd. Next () + ". jpg"; Bt. Save (Picname); Console.WriteLine ("Saved successfully! "+picname); }}} catch (Exception ex) {MessageBox.Show (ex). ToString ()); } }
————————————————————————————————————————————————————————————————————————————— run, press the SPACEBAR and display the saved file name at the command line:
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————Validation results:
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
Issues to be aware of:1. To save the video frame as a picture, first create a picture instance, the width and height of the image must be consistent with the original video, that is, IMAGE<BGR, byte> framepic = new IMAGE<BGR, byte> ( WD,HG);
2. Among them, WD and HG are based on the properties of the video to extract and note data conversion, Double--int. //Video width
int WD = (int) cvinvoke.cvgetcaptureproperty (Catchframe, Emgu.CV.CvEnum.CAP_PROP. Cv_cap_prop_frame_width);
Video height
int HG = (int) cvinvoke.cvgetcaptureproperty (Catchframe, Emgu.CV.CvEnum.CAP_PROP. Cv_cap_prop_frame_height);
3. The same principle, need other processing video frame is also very fast and convenient.
"EMGU" read video AVI file + save any frame as Picture