"EMGU" read video AVI file + save any frame as Picture

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.