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.