# Cv::imshow displays gray image -opencv 3.4

**URL:** <https://forum.opencv.org/t/cv-imshow-displays-gray-image-opencv-3-4/10541>\
**Category:** C++\
**Tags:** build\
**Created:** [October 13, 2022, 8:37am UTC](https://forum.opencv.org/t/cv-imshow-displays-gray-image-opencv-3-4/10541 "2022-10-13T08:37:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Swetha\_Sharma](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/swetha_sharma/32/5026_2.png) [@Swetha\_Sharma](https://forum.opencv.org/u/Swetha_Sharma)\
**Post date:** [October 13, 2022, 8:37am UTC](https://forum.opencv.org/t/cv-imshow-displays-gray-image-opencv-3-4/10541/1 "2022-10-13T08:37:27Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![FilipBaas](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/filipbaas/32/802_2.png) [@FilipBaas](https://forum.opencv.org/u/FilipBaas)\
**Post date:** [October 13, 2022, 10:09am UTC](https://forum.opencv.org/t/cv-imshow-displays-gray-image-opencv-3-4/10541/2 "2022-10-13T10:09:48Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![Swetha\_Sharma](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/swetha_sharma/32/5026_2.png) [@Swetha\_Sharma](https://forum.opencv.org/u/Swetha_Sharma)\
**Post date:** [October 13, 2022, 10:56am UTC](https://forum.opencv.org/t/cv-imshow-displays-gray-image-opencv-3-4/10541/3 "2022-10-13T10:56:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [October 13, 2022, 11:12am UTC](https://forum.opencv.org/t/cv-imshow-displays-gray-image-opencv-3-4/10541/4 "2022-10-13T11:12:49Z")

</div>

what does `img.empty()` return?

you must present a [MRE](https://stackoverflow.com/help/minimal-reproducible-example). your piece of code is surely not the whole story.

---

<div class="post-metadata">

**Author:** ![Swetha\_Sharma](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/swetha_sharma/32/5026_2.png) [@Swetha\_Sharma](https://forum.opencv.org/u/Swetha_Sharma)\
**Post date:** [October 13, 2022, 1:30pm UTC](https://forum.opencv.org/t/cv-imshow-displays-gray-image-opencv-3-4/10541/5 "2022-10-13T13:30:39Z")

</div>

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
