cvtColor断言失败(OpenCV与C ++) [英] cvtColor assertion failed ( OpenCV with C++ )
本文介绍了cvtColor断言失败(OpenCV与C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个
cv :: Mat image;
对象,我从一个文件加载图像,它正确读取所有。 p>
现在我写了一个函数将它转换为灰色。
cv :: cvtColor(image,image,CV_RGB2GRAY);
此错误出现:
OpenCV错误:断言失败(scn == 3 || scn == 4)在cvtColor,文件/build/buildd/opencv-2.3.1/modules/imgproc/src/color.cpp ,line 2834
在抛出cv :: Exception的实例后调用终止
what():/build/buildd/opencv-2.3.1/modules/imgproc/src/color.cpp:2834 :error:(-215)scn == 3 || scn == 4在函数cvtColor
可能是什么问题?
这是我如何读取图像(通过imagehandler类有成员cv :: Mat m_image)
imagehandler :: imagehandler(const std :: string& fileName)
:m_image(imread(fileName,CV_LOAD_IMAGE_COLOR))
{
if(!m_image.data)
{
cout<< 加载失败<< fileName<< endl;
}
}
解决方案
尝试使用其他dst图片:
cv :: Mat grayImage;
cv :: cvtColor(image,grayImage,CV_RGB2GRAY);
I have a
cv::Mat image;
object, which I loaded an image to from a file, it reads it correctly and all.
Now I have written a function to transform it to grey color.
cv::cvtColor(image, image, CV_RGB2GRAY);
And this error comes up:
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /build/buildd/opencv-2.3.1/modules/imgproc/src/color.cpp, line 2834
terminate called after throwing an instance of 'cv::Exception'
what(): /build/buildd/opencv-2.3.1/modules/imgproc/src/color.cpp:2834: error: (-215) scn == 3 || scn == 4 in function cvtColor
what could be the problem?
This is how I read the image (through an imagehandler class which has a member cv::Mat m_image)
imagehandler::imagehandler(const std::string& fileName)
: m_image(imread(fileName, CV_LOAD_IMAGE_COLOR))
{
if(!m_image.data)
{
cout << "Failed loading " << fileName << endl;
}
}
解决方案
Try using different dst image:
cv::Mat grayImage;
cv::cvtColor(image, grayImage, CV_RGB2GRAY);
这篇关于cvtColor断言失败(OpenCV与C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文