I have
cv::Mat image;
which I downloaded to the file from the file, it reads it correctly and thatβs it.
Now I have written a function to convert it to gray.
cv::cvtColor(image, image, CV_RGB2GRAY);
And this error occurs:
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 (via the imagehandler class, which has a cv :: Mat m_image member)
imagehandler::imagehandler(const std::string& fileName) : m_image(imread(fileName, CV_LOAD_IMAGE_COLOR)) { if(!m_image.data) { cout << "Failed loading " << fileName << endl; } }
source share