有没有办法设置cvQueryFrame或cvGrabFrame的起始帧

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

本文关键字:cvGrabFrame 设置 cvQueryFrame 有没有      更新时间:2023-10-16

使用OpenCV(HighGUI.h),我主要有以下代码:

int frame_count = 0;  
while( (frame=cvQueryFrame(capture)) != NULL && (frame_count <= max_frame)) {
        //If the current frame 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++;
    }

它查询捕获帧,并且只有当帧在min_frame和max_frame这两个整数的范围内时才写入。该代码工作得很好,但对于处理非常大的视频来说效率不够,因为它必须查询捕获到min_frame之前的帧,但它没有编写这些帧。我想知道是否有一种方法可以让cvQueryFrame从min_frame开始,而不必一直到它。当它达到max_frame时,它已经停止了,因为我移动了

frame_count <= max_frame

转换为while条件。有什么建议吗?

您可以通过设置要读取的下一帧

cvSetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES, min_frame);

当然只适用于视频而不适用于相机。下一个帧读取将是min_frame,如果不再次设置帧位置,读取将从此处正常进行(min_frame之后的帧将被读取)。所以这是一个完美的配合,因为你只需要在一开始就称之为它。