Reputation: 2607
I am getting an assertion error when I try to convert an input image to grayscale. I have seen lots of posts around the same issue but none seem to give a reason why it is erroring. In the code below, input is NOT NULL and has been loaded from an image "test.jpg" on my drive using imgRead.
Mat img_gray;
cvtColor(input, img_gray, CV_BGR2GRAY);
Assertion Error:
OpenCV Automatic Number Plate Recognition working with file: test OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /opt/local/var/macports/build/_opt_mports_dports_graphics_opencv/opencv/work/opencv-2.4.9/modules/imgproc/src/color.cpp, line 3737 libc++abi.dylib: terminate called throwing an exception
The code is taken from https://github.com/MasteringOpenCV/code/blob/master/Chapter5_NumberPlateRecognition/DetectRegions.cpp
check out line 72.
I have tried multiple pictures with no luck. Any suggestions would be appreciated. Thanks
Upvotes: 0
Views: 3109
Reputation: 11951
That assertion message means that the image you passed in is not 3 or 4 channel. E.g. if you pass in a one channel grayscale image it will fail.
try putting in
std::cerr << "image chans : " << image.channels() << std::endl;
immediately before cvtColor()
. I am sure that it won't output 3 or 4.
Upvotes: 4