OpenCV搜索功能/倒带 [英] OpenCV Seek Function/Rewind

查看:131
本文介绍了OpenCV搜索功能/倒带的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用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:

  1. CV_CAP_PROP_POS_MSEC -从文件开始的位置(以毫秒为单位)
  2. CV_CAP_PROP_POS_FRAMES -帧中的位置
  3. CV_CAP_PROP_POS_AVI_RATIO-相对单位的位置(0-文件开始,1-文件结束)
  4. CV_CAP_PROP_FRAME_WIDTH-视频流中的帧宽度(仅适用于摄像机)
  5. CV_CAP_PROP_FRAME_HEIGHT-视频流中帧的高度(仅适用于摄像机)
  6. CV_CAP_PROP_FPS-帧速率(仅适用于相机)
  7. CV_CAP_PROP_FOURCC-编解码器的4个字符的代码(仅适用于摄像机).
  1. CV_CAP_PROP_POS_MSEC - position in milliseconds from the file beginning
  2. CV_CAP_PROP_POS_FRAMES - position in frames
  3. CV_CAP_PROP_POS_AVI_RATIO - position in relative units (0 - start of the file, 1 - end of the file)
  4. CV_CAP_PROP_FRAME_WIDTH - width of frames in the video stream (only for cameras)
  5. CV_CAP_PROP_FRAME_HEIGHT - height of frames in the video stream (only for cameras)
  6. CV_CAP_PROP_FPS - frame rate (only for cameras)
  7. CV_CAP_PROP_FOURCC - 4-character code of codec (only for cameras).

前两个是您感兴趣的.

更多信息:)

您可以通过重复调用具有各种帧索引的上述功能来循环浏览帧.

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搜索功能/倒带的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆