1 | initial version |
here's the problem:
cvtColor(inputImg,inputImg,CV_8UC1); // CV_8UC1 is the wrong constant.
what you need instead is:
cvtColor(inputImg,inputImg,COLOR_BGR2GRAY);
CV_8UC1 evaluates to 0, so you did the same as:
cvtColor(inputImg,inputImg, COLOR_BGR2BGRA);
thus equalizeHist complains, - the input is still 3-channel, not 1channel.
but, since you already got a grayscale image above, why not use that instead ?
Mat gray;
// i'm sure, you do *not* want alpha to influence your grayscale.
if(img.channels() > 0){
cvtColor(img, gray, CV_BGR2GRAY);
}
else{
gray = img;
}
Mat inputImg;
float scale = img.cols/(float)scaledWidth;
if(img.cols > scaledWidth){
int scaledHeight = cvRound(img.rows / scale);
resize(gray, inputImg, Size(scaledWidth, scaledHeight)); //use grayscale img
}
else{
inputImg = gray; //use grayscale img
}
//cvtColor(inputImg, inputImg, COLOR_BGR2GRAY); // no more needed.
Mat equalizedImg;
equalizeHist(inputImg, equalizedImg);
2 | No.2 Revision |
here's the problem:
cvtColor(inputImg,inputImg,CV_8UC1); // CV_8UC1 is the wrong constant.
what you need instead is:
cvtColor(inputImg,inputImg,COLOR_BGR2GRAY);
CV_8UC1 evaluates to 0, so you did the same as:
cvtColor(inputImg,inputImg, COLOR_BGR2BGRA);
thus equalizeHist complains, - the input is still 3-channel, not 1channel.
but, since you already got a grayscale image above, why not use that instead ?
Mat gray;
// i'm sure, you do *not* want alpha to influence your grayscale.
if(img.channels() > 0){
1){
cvtColor(img, gray, CV_BGR2GRAY);
}
else{
gray = img;
}
Mat inputImg;
float scale = img.cols/(float)scaledWidth;
if(img.cols > scaledWidth){
int scaledHeight = cvRound(img.rows / scale);
resize(gray, inputImg, Size(scaledWidth, scaledHeight)); //use grayscale img
}
else{
inputImg = gray; //use grayscale img
}
//cvtColor(inputImg, inputImg, COLOR_BGR2GRAY); // no more needed.
Mat equalizedImg;
equalizeHist(inputImg, equalizedImg);
3 | No.3 Revision |
here's the problem:
cvtColor(inputImg,inputImg,CV_8UC1); // CV_8UC1 is the wrong constant.
what you need instead is:
cvtColor(inputImg,inputImg,COLOR_BGR2GRAY);
CV_8UC1 evaluates to 0, so you did the same as:
cvtColor(inputImg,inputImg, COLOR_BGR2BGRA);
thus equalizeHist complains, - the input is still 3-channel, not 1channel.
but, since you already got a grayscale image above, why not use that instead ?
Mat gray;
// i'm sure, you do *not* want alpha to influence your grayscale.
if(img.channels() > 1){
== 3){
cvtColor(img, gray, CV_BGR2GRAY);
}
}
else if(img.channels() == 4){
cvtColor(img, gray, CV_BGRA2GRAY);
}
else{
gray = img;
}
Mat inputImg;
float scale = img.cols/(float)scaledWidth;
if(img.cols > scaledWidth){
int scaledHeight = cvRound(img.rows / scale);
resize(gray, inputImg, Size(scaledWidth, scaledHeight)); //use grayscale img
}
else{
inputImg = gray; //use grayscale img
}
//cvtColor(inputImg, inputImg, COLOR_BGR2GRAY); // no more needed.
Mat equalizedImg;
equalizeHist(inputImg, equalizedImg);