Use opencv to read the specified frame number of a video clip.

Source: Internet
Author: User

When using opencv to read a video, you often need to read the video from the part of the specified frame number.CvsetcapturepropertyCombined ParametersCv_cap_prop_pos_framesFor exampleCodeAs follows:

 Bool   Picksomeframes ( Const   Char * Filename , Int   Start , Int   End , Char * Savepath ){ Cvcapture * Capture = Cvcapturefromavi (filename ); //  Read video files Cvsetcaptureproperty (capture, cv_cap_prop_pos_frames, start ); Int   Count = Start; While (Cvgrabframe (capture) & count <= END ){ Iplimage * Pframe = Cvretrieveframe (capture ); //  Get current frame          Char   Test [1, 100]; sprintf (test, "% S \ % d % s" , Savepath, count, ". Jpg" ); Cvsaveimage (test, pframe); count ++;} cvreleasecapture (& capture ); Return   False ;}

The preceding method supports multiple threads to read and write clips starting from different frame numbers. These codes are particularly useful when multithreading is used to accelerate video processing.

Related Article

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.