相关疑难解决方法(0)

openCV错误:断言失败(scn == 3 || scn == 4)

我在最后一帧时有Assertion失败错误,同时逐帧读取和写入视频.错误只显示在最后一帧,不知道为什么.在这里看到这个答案,这建议给waitkey,我的代码已经有等待键.

我的简单代码如下

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;
}  
Run Code Online (Sandbox Code Playgroud)

有人请帮忙

解决方案:我在读完每个文件后添加了一个检查 -

if(frame.empty()){
    fprinf("cannot access frame");
    return -1;
}
Run Code Online (Sandbox Code Playgroud)

c opencv video-capture

15
推荐指数
1
解决办法
4万
查看次数

标签 统计

c ×1

opencv ×1

video-capture ×1