简体   繁体   English

在OpenCV C ++中从视频文件中检索每3帧

[英]Retrieving every 3rd frame from video file in opencv c++

I'm writing a logic to retrieve every 3rd frame from a video in opencv c++, while executing I am facing a problem in first 'for' loop when I try print(cout) 'i' value ouput is only upto 687, after which "Error: Insufficient memory (Failed to allocate 2764804 bytes) out of memory" error occurs. 我正在编写逻辑以从opencv c ++中的视频中检索每个第3帧,而在执行时我尝试打印(cout)'i'值时,第一个for循环遇到一个问题,输出最多只能达到687,之后发生“错误:内存不足(无法分配2764804字节)”。错误。

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;
}
} 

suggest me how I can access a array of Mat variable beyond 687,and kindly let me know if any other logic exists for retrieving every 3rd frame from a video, so that I can move out of this prob,solving this prob is surely appreciable. 建议我如何访问超过687的Mat变量数组,并让我知道是否存在用于从视频中检索第3帧的任何其他逻辑,以便我可以移出该概率,肯定可以解决这个概率。 thanks in advance. 提前致谢。

You can use CV_CAP_PROP_POS_FRAMES macro to set frame position to be decoded/captured next. 您可以使用CV_CAP_PROP_POS_FRAMES宏来设置接下来要解码/捕获的帧位置。

Like, 喜欢,

VideoCapture::set(CV_CAP_PROP_POS_FRAMES ,framePosition);

See OpenCV Doc for more details 有关更多详细信息,请参见OpenCV Doc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM