[英]cvtColor assertion failed ( OpenCV with C++ )
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) 这是我读取图像的方式(通过具有成员cv :: Mat m_image的imagehandler类)
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: 尝试使用不同的dst图像:
cv::Mat grayImage;
cv::cvtColor(image, grayImage, CV_RGB2GRAY);
尝试使用image.clone()来处理图像
if(!image.empty()) {
//your_code
} else
std::cout<<"Emty "
check the matrix before you convert. 在转换之前检查矩阵。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.