Opencv VideoCapture集CV_CAP_PROP_POS_FRAMES不起作用 [英] Opencv VideoCapture set CV_CAP_PROP_POS_FRAMES not working

查看:954
本文介绍了Opencv VideoCapture集CV_CAP_PROP_POS_FRAMES不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用opencv使用mpeg压缩从Vivotek摄像机的视频输出中读取帧.我正在尝试使用该功能从特定位置开始播放视频,如下所示,其中开始是我要跳过的帧数.

I am using opencv to read frames from a video output from a Vivotek Camera using the mpeg compression. I am trying to use the function to start the video from a particular position., shown below where start is the number of frames I want to skip.

inputVideo.set(CV_CAP_PROP_POS_FRAMES, start); 

但是我遇到了一个问题,因为捕获的帧不正确,发生在开始时的帧之前.

However I am having a problem with this as the incorrect frame is being captured which happens before the frame at start.

我正在使用Opencv 2.4.2版

I am using opencv version 2.4.2

有人可以帮助解决这个问题吗?

Can someone please help with this issue?

推荐答案

有点晚了,但搜索的是同一主题(不是特定于Vivotek Camera,而是更多有关openCV的mpeg问题):

A bit too late but searching on same topic (not specific to Vivotek Camera but more on mpeg problem with openCV) :

  • 视频已编码
  • OpenCV使用FFMPEG
  • 编码使用关键帧
  • 跳过某些帧时,编码无法为您提供所需的确切帧

看到类似的问题:

如何从视频文件中获取一帧?

问题设置CV_CAP_PROP_POS_FRAMES设置下一帧号

desired position        key frame (this is where the cursor will stop)
 |   |                       |                    |
 |   >                       |                    |
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

使用带有跟踪栏的openCV 2.4.8/VS2013的示例代码:

Sample code using openCV 2.4.8 / VS2013 with trackbar :

使用MPG格式[MPEG1/MPEG2]测试:设置帧位置效果很好

tested with MPG format [MPEG1/MPEG2] : setting frame position works fine

double currentPos = capture.get(CV_CAP_PROP_POS_FRAMES);
std::cout << "CV_CAP_PROP_POS_FRAMES = " << currentPos << std::endl;

// position_slider 0 - 100
double noFrame = position_slider*nbFrames / 100;

// solution 1
bool success = capture.set(CV_CAP_PROP_POS_FRAMES, noFrame);
// solution 2
double frameRate = capture.get(CV_CAP_PROP_FPS);
double frameTime = 1000.0 * noFrame / frameRate;
bool success = capture.set(CV_CAP_PROP_POS_MSEC, frameTime);

if (!success) {
    std::cout << "Cannot set frame position from video file at " << noFrame << std::endl;       
    return;
}

currentPos = capture.get(CV_CAP_PROP_POS_FRAMES);
if (currentPos != noFrame) {
    std::cout << "Requesting frame " << noFrame << " but current position == " << currentPos << std::endl;
}

success = capture.read(frame_aux);
if (!success) {
    std::cout << "Cannot get frame from video file " << std::endl;
    return;
}
imshow("test", frame_aux);

这篇关于Opencv VideoCapture集CV_CAP_PROP_POS_FRAMES不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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