【发布时间】:2014-03-19 06:07:42
【问题描述】:
我在最后一帧出现断言失败错误,同时逐帧读取和写入视频。错误只显示在最后一帧,不知道为什么。看到这个答案here,建议给waitkey,我的代码已经有wait key了。
我的简单代码如下
int main()
{
CvCapture *capture=cvCaptureFromFile("C:\\vid\\op.mp4");
if(capture==NULL)
{
printf("can't open video");
}
Mat frame, first_frame,current_frame;
char buffer[100];
int frame_count=1,p=1;
while(1)
{
/*Getting the current frame from the video*/
frame=cvQueryFrame(capture);
cv::cvtColor(frame,current_frame,1); //saving current frame
sprintf(buffer,"C:\\frames\\image%u.jpg",p);
imwrite(buffer,current_frame);
p++;
waitKey(1);
}
return 0;
}
请大家帮忙
解决方案:我在读取每个文件后添加了一个检查-
if(frame.empty()){
fprinf("cannot access frame");
return -1;
}
【问题讨论】:
标签: c opencv video-capture