开发者

Is there are way to set the start frame for cvQueryFrame or cvGrabFrame?

Using OpenCV (HighGUI.h), I have this code in main:

int frame_count = 0;  
while( (frame=cvQueryFrame(capture)) != NULL && (frame_count <= max_frame)) {
        //If the current frame开发者_Python百科 is within the bouds min_frame and max_frame, write it to the new video, else do nothing
        if (frame_count >= min_frame){
            cvWriteFrame( writer, frame );
        }
        frame_count++;
    }

which queries capture for the frame, and only writes it if the frame is within the bounds min_frame and max_frame, both integers. The code works great, but it is not efficient enough for handling very large videos because it has to query capture for the frames leading up to min_frame, but it doesn't write them. I am wondering if there's a way I can just get cvQueryFrame to start at min_frame instead of having to work its way up to it. It already stops when it gets up to max_frame, since I moved

frame_count <= max_frame

into the while conditional. Any suggestions?


You can set the next frame to read by means of

cvSetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES, min_frame);

of course only for videos and not for cameras. The next frame read will be min_frame and the reading will go on normally from there (the frames after min_frame will be read) if you don't set the frame position again. So it's a perfect fit, as you just need to call it at the start.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜