Reputation: 11
I'm trying to create a Lpr algorithm in Opencv. I'm applying to the image things like grayscale and canny; but also I need to apply saturation to the image, and that is my issue:
This is the code (I extract this code from this page http://hasanaga.info/tag/opencv-saturation/):
void saturation(cv::Mat &img)
{
Mat imagen;
cvtColor(img,imagen,CV_RGB2HSV);
for(int y=0; y<imagen.cols; y++)
{
for(int x=0; x<imagen.rows; x++)
{
int cur2 = imagen.at<Vec3b>(Point(y,x))[1];
cur2 += 41;
if(cur2 < 0) cur2= 0; else if(cur2 > 255) cur2 = 255;
imagen.at<Vec3b>(Point(y,x))[1] = cur2;
}
}
cvtColor(imagen,img,CV_HSV2RGB);
}
(I change a little bit the code, cause I don't need to change the other parameters)
But when I try to create the executable, this happen:
OpenCV Error: Assertion failed ((scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F)) in cvtColor, file /home/guerrero/opencv2.4.9/opencv-2.4.9/modules/imgproc/src/color.cpp, line 3959 terminate called after throwing an instance of 'cv::Exception' what(): /home/guerrero/opencv2.4.9/opencv-2.4.9/modules/imgproc/src/color.cpp:3959: error: (-215) (scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F) in function cvtColor
May I know what cause the error?
Upvotes: 1
Views: 3440
Reputation: 1088
Number of channels or depth of input Image is not correct..
src channels should be 3 or 4, depth should be either CV_8U or CV_32F
((scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F))
Upvotes: 1