Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Windows imshow sometimes showing gray image

I have done a bit of research on this topic, apparently Windows OpenCV builds might have an error using imshow. This problem varies a bit but the result is a gray image instead of the correct RGB image stored in a Mat structure.

Here it's suggested that it could be due to the jpeg codecs. It's also mentioned as a bug in the developer zone, that it's related to namedWindows.

I'm using the stitching_detailed example. The relevant part is the final panorama, which is stored in the result Mat. When saving it to a file it works correctly.

imwrite(result_name, result); // works

If I show the image either like this:

imshow("result", result);
waitKey(0);

or like this:

namedWindow("result", CV_WINDOW_NORMAL);
imshow("result", result);
waitKey(0);

I get a gray image displayed.

But if I do the following:

imwrite(result_name, result);
Mat pano = imread(result_name , CV_LOAD_IMAGE_COLOR);
namedWindow("result", CV_WINDOW_NORMAL); //works without this line too
imshow("result", pano);
waitKey(0);

I get the correct image displayed, i.e. Saving it to a file and then reading it works. But not the live rendering of the generated image.

What can be the cause?