cvtColor assertion failed ( OpenCV with C++ )
c++, opencv
Solution
Try using different dst image:
cv::Mat grayImage;
cv::cvtColor(image, grayImage, CV_RGB2GRAY);
Problem
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; } } ```