【发布时间】: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