OpenCV的错误:断言失败(SCN == || 3 SCN == 4) [英] openCV Error: Assertion failed (scn == 3 || scn == 4)

查看:1806
本文介绍了OpenCV的错误:断言失败(SCN == || 3 SCN == 4)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有断言在最​​后一帧失败的错误,同时读取和写入一帧的视频帧。只显示最后一帧的错误,不知道为什么。看到这个答案这里,伟驰建议给予waitkey,我的code已经有等待键就可以了。

我简单的code是如下:

  INT的main()
{
  CvCapture *捕获= cvCaptureFromFile(C:\\\\ \\\\ VID op.mp4);
  如果(捕获== NULL)
   {
 的printf(不能打开视频);
   }
   垫架,FIRST_FRAME,current_frame;
  炭缓冲器[100];
  INT frame_count = 1,p为1;
  而(1)
   {
   / *从视频获取当前帧* /
    帧= cvQueryFrame(捕捉);
    CV :: cvtColor(帧,current_frame,1); //保存当前帧
    sprintf的(缓冲,C:\\\\ \\\\帧图像%u.jpg,P);
    imwrite(缓冲,current_frame);
    p ++;     waitKey(1);
   }
   返回0;
}

有人请帮助

解决方法:我添加了一个检查只是读每一个文件后 -

 如果(frame.empty){
fprinf(不能访问框架);
retun -1;
}


解决方案

您需要检查你的框架是空的或不是每次查询后

如同

  FRAME = cvQueryFrame(捕捉);
     如果(frame.empty())破;

您是因为你正试图转换的空席最后一帧后,灰度,所以如果帧是空的退出循环得到这样的错误。

I am having Assertion failed error at the last frame , while reading and writing a video frame by frame. The errors only shows at the last frame, don't know why. saw this answer here, whichs suggests to give waitkey, my code already have wait key on it.

my simple code is as follows

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

Anybody please help

Solution: I added a check just after reading every file as-

if(frame.empty){
fprinf("cannot access frame");
retun -1;
}

解决方案

You need to check your frame is empty or not after each query

Like

   frame=cvQueryFrame(capture);
     if (frame.empty()) break;

You are getting such an error because you are trying to convert an empty Mat to grayscale after last frame, so exit the loop if frame is empty.

这篇关于OpenCV的错误:断言失败(SCN == || 3 SCN == 4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆