Opencv shows images totally white?
Hi guys, can any of you tell me if there's a bug in the convertTo function?
With reference to this question, I'm running that code and I'm getting the pictures shown.
The code I'm running is this one:
int testImageAndGradients(int argc, char **argv) {
if (argc != 2) {
std::cout << "Need filename..." << std::endl;
return 1;
}
Mat im = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
Mat imfloat, dx, dy;
im.convertTo(imfloat, CV_32FC1);
Mat u(imfloat.size(), imfloat.type());
int & X = im.cols;
int & Y = im.rows;
Sobel(imfloat, dx, CV_32F, 1, 0, 3);
Sobel(imfloat, dy, CV_32F, 0, 1, 3);
Mat tmp, output(Size(3*X,Y),CV_8UC1);
double minval, maxval;
minMaxLoc(imfloat, &minval, &maxval);
imfloat.convertTo(tmp, CV_8UC1, 255 / (maxval - minval), -minval);
tmp.copyTo(output(Rect(0, 0, X, Y)));
minMaxLoc(dx, &minval, &maxval);
dx.convertTo(tmp, CV_8UC1, 255 / (maxval - minval), -minval);
tmp.copyTo(output(Rect(X, 0, X, Y)));
minMaxLoc(dy, &minval, &maxval);
dy.convertTo(tmp, CV_8UC1, 255 / (maxval - minval), -minval);
tmp.copyTo(output(Rect(2*X, 0, X, Y)));
namedWindow("Img/Dx/Dy", WINDOW_AUTOSIZE);
imshow("Img/Dx/Dy", output);
waitKey(0);
return 1;
}
And my suspect is eventually a misuse of the method convertTo
, but I can't figure out why.
Thank you.
Why the downvote?
May be you shoud read convertTo doc :
I read the doc, and I don't get what am I missing.
I think I got the problem... my
beta
argument inconvertTo
is wrong, I should scale it as well. I'll update the question with a better description, and I'll post an answer.Downvote Try to give a link on stackoverflow as a question...
beta = -255*minval / (maxval - minval)
I did figure at last...
Did try to post an answer, but apparently I can't. But anyway yes, that was the issue... I should learn how to read a formula again.