是否有能力倒回 VideoCapture 中的多个帧

is there an ability to rewind a number of frames in a VideoCapture

在某种情况下,我需要能够将视频倒回10 帧。 到目前为止,我有一个 VideoCapture cap,我从中提取帧以使用 cap >> frame 进行编辑和显示,其中 frame 属于 Mat 类型(这是我所有剩余的帧编辑是建立在.

我发现您可以使用

倒带帧
int cvSetCaptureProperty( CvCapture* capture, int property_id, double value );

但问题是,这与我的 VideoCapture cap 不兼容,编译器说:

min.cpp:158:72: error: cannot convert ‘cv::VideoCapture’ to ‘CvCapture*’ for argument ‘1’ to ‘int cvSetCaptureProperty(CvCapture*, int, double)’
             cvSetCaptureProperty(cap,CV_CAP_PROP_POS_FRAMES, i-TRCK_MRG);
                                                                        ^
min.cpp:159:37: error: cannot convert ‘cv::VideoCapture’ to ‘CvCapture*’ for argument ‘1’ to ‘IplImage* cvQueryFrame(CvCapture*)’
             frame = cvQueryFrame(cap);

并且如果我使用 VideoCapture *cap 将帧捕获为 IplImage* frame,我的程序的其余部分也需要修改,除非我将帧转换回 Mat 类型。

因此,是否可以在 VideoCapture 中倒回多个帧?

cvSetCapturePropertyCvCaptureIplImage 来自已弃用的 C 接口,除非绝对必要,否则不应使用。

但是您可以使用与 C++ 接口相同的函数,更准确地说是 this one。代码看起来像:

cv::VideoCapture cap("moviefile.mp4");

// read 200 frames
for (int i =0; i < 200; ++i)
 cap.read();

// get the current position
auto pos = cap.get(cv::CV_CAP_PROP_POS_FRAMES);
// set the new position
cap.set(cv::CV_CAP_PROP_POS_FRAMES, pos-10);

我还没有试过这个,但我认为这是你最好的选择。使用实时摄像机而不是文件,我怀疑它根本无法工作。