Cv::imshow displays gray image -opencv 3.4

Hi,
The following code displays a gray image even though img has the correct pixel values. what is missing in this code

      cv::Mat img = cv::imread("brain.jpg");
      cv::imshow("img", img);
      cv::waitKey(0);

Code works for me. Try changing first row to this:

cv::Mat img = cv::imread("brain.jpg", cv::IMREAD_COLOR);

thankyou Filip. I have changed it as per your suggestion still ,it is the same behaviour. Strange! I included opencv2\opencv.hpp in the header should i include some other files too

what does img.empty() return?

you must present a MRE. your piece of code is surely not the whole story.

Found the problem i had included both opencv_world310d.lib and opencv_world3416d.lib in the linker after I removed the opencv_world310d.lib it worked. Thanks

1 Like