【问题标题】:Retrieving every 3rd frame from video file in opencv c++从opencv c ++中的视频文件中检索每第三帧
【发布时间】:2014-03-13 09:58:34
【问题描述】:

我正在编写一个逻辑来从 opencv c++ 中的视频中检索每 3 帧,在执行时,当我尝试 print(cout) 'i' 输出时,我在第一个'for'循环中遇到了一个问题,输出仅高达 687 ,之后出现“Error: Insufficient memory (Failed to allocate 2764804 bytes) out of memory”错误。

int main(){

string path = "C:/vid_frames/Highway_Hamilton.avi";
VideoCapture capture(path); 

Mat matImage[1000];


cout<<"initalization done";

//obtaining frames from the video into matimage variable

for(int i=0;i<1000;i++) {

    char filename[30]="Existing frame";

    capture >> matImage[i];

    cout<<"i:"<<i;

    if ( matImage[i].empty()) 
    {
         cout << "Cannot load image!,runnig application might abort exit,press any key:" << endl;
        getchar();
    }

    char frame_id[30];
    itoa(i, frame_id, 15);
    strcat(filename, frame_id);
}

int num=0;

for(int i=0;num<1000;i++) {

    char filename[30]="Required frame";

    char frame_id[30];
    itoa(num, frame_id, 10);
    strcat(filename, frame_id);

    num=num+3;
}
} 

建议我如何访问超过 687 的 Mat 变量数组,并请让我知道是否存在任何其他逻辑可用于从视频中检索每 3 帧,以便我可以摆脱这个问题,解决这个问题是肯定是可观的。提前致谢。

【问题讨论】:

  • 您要在内存中缓存 2.7 mb 的 1000 张图像?为什么 ?你实际上想对每第三帧做什么?

标签: c++ opencv video-capture frames mat


【解决方案1】:

您可以使用CV_CAP_PROP_POS_FRAMES 宏设置接下来要解码/捕获的帧位置。

喜欢,

VideoCapture::set(CV_CAP_PROP_POS_FRAMES ,framePosition);

详情请见OpenCV Doc

【讨论】:

  • 嘿哈里斯感谢你这么快回复,你的意思是我需要使用“VideoCapture::set(int propId, double value)”函数来检索每第三帧。例如:VideoCapture::set(CV_CAP_PROP_POS_FRAMES,3),这会起作用,对吧?请纠正我,如果我穿坏了。再次感谢。
  • 要么读后跳帧,要么用上面的方法,上面我没测试过自己试试。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-19
  • 2013-02-05
  • 2016-02-05
  • 1970-01-01
相关资源
最近更新 更多