我一直在尝试使用C ++中的OpenCV查找/实现查找和快退功能(用于视频(.avi)),但是除了找到整个文件一次并保存之外,我找不到其他方法.每个图像.还有其他办法吗?
I've been trying to find/implement a seek and rewind function (for video (.avi)) using OpenCV in C++, but I cant find a way of doing it, other than going through the entire file once and saving each image. Is there any other way?
任何帮助将不胜感激;提前谢谢!
Any help would be much appreciated; Thanks ahead of time!
推荐答案使用cvSetCaptureProperty(),您可以以毫秒为单位或按顺序的帧号在帧之间循环.
Using cvSetCaptureProperty() you can cycle through frames, either in miliseconds or by ordinal frame number.
int cvSetCaptureProperty( CvCapture* capture, int property_id, double value );property_id 是您需要使用的属性.可以是以下之一:
property_id is a property you would need to use. It can be one of the following:
前两个是您感兴趣的.
更多信息:)
您可以通过重复调用具有各种帧索引的上述功能来循环浏览帧.
You can cycle through frames just by repeatedly calling the mentioned function with various frame indices.
cvSetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES, frameIndex);示例:
IplImage* frame; CvCapture* capture = cvCreateFileCapture("test.avi"); /* iterate through first 10 frames */ for (int i = 0; i < 10; i++) { /* set pointer to frame index i */ cvSetCaptureProperty(capture, CV_CAP_POS_FRAMES, i); /* capture the frame and do sth with it */ frame = cvQueryFrame(capture); }您可以在用户每次单击按钮以前进/后退视频时放置类似的代码来执行.
You could put similar code to execute each time user clicks a button to forward/rewind the video.
C ++方法(OpenCV 2和更高版本)将改用具有相同property_id和value的此方法.
The C++ method (OpenCV 2 and higher) would be to use this method instead with the same property_id and value.
bool VideoCapture::set(int property_id, double value)更多推荐
OpenCV搜索功能/倒带
发布评论