Ask Your Question

Revision history [back]

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.

Thank you.

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.