opencv cvtColor断言失败c++

opencv cvtColor assertion failed C++

本文关键字:c++ 失败 断言 cvtColor opencv      更新时间:2023-10-16

当我尝试将输入图像转换为灰度时,我得到一个断言错误。我见过很多帖子都围绕着同样的问题,但似乎没有人给出错误的原因。在下面的代码中,输入不是NULL,并且是从我的驱动器上的图像"test.jpg"加载的使用imgRead。

Mat img_gray;
cvtColor(input, img_gray, CV_BGR2GRAY);

断言错误:

OpenCV自动车牌识别使用file: testOpenCV错误:断言失败(scn == 3 || scn == 4)在cvtColor,文件/opt/local/var/macports/build/_opt_mports_dports_graphics_opencv/OpenCV/work/OpenCV -2.4.9/modules/imgproc/src/color.cpp,行3737libc + + abi。终止调用抛出异常

代码取自https://github.com/MasteringOpenCV/code/blob/master/Chapter5_NumberPlateRecognition/DetectRegions.cpp

检查第72行。

我试了很多照片都没有运气。任何建议都将不胜感激。由于

该断言消息意味着您传入的图像不是3或4通道。例如,如果你传入一个通道灰度图像,它将失败。

试着输入

std:: cerr & lt; & lt;image changes: " <<image.channels () & lt; & lt;std:: endl;

紧接cvtColor()。我确信它不会输出3或4。