1

I'm getting a weird issue (but no error) when loading in an image and trying to display it. Here's the code I'm using:

import numpy as np  
import cv2  

# I'm using the full-path in the actual document   
img = cv2.imread('shapes.jpg')  
gray = cv2.imread('shapes.jpg',0)  

#not displaying anything currently  
cv2.imshow('gray', img)  
cv2.waitKey(0)  
cv2.destroyAllWindows()  

What I do get is the top part of a window. When using cv2.namedWindow('gray', cv2.WINDOW_NORMAL), I'm able to maximize the image and I can see that it does load the image, but it's surrounded by gray.

Any thoughts?

alkasm
  • 22,094
  • 5
  • 78
  • 94
Baron
  • 15
  • 1
  • 4
  • Try `waitKey(200)` or some other longer time than `0` and see if that changes anything. If you use `namedWindow()`, to confirm, you can only see the gray unless you maximize, correct? – alkasm Jun 19 '17 at 21:43
  • @AlexanderReynolds [`0` means forever](http://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html?highlight=waitkey#waitkey) -- can't wait any longer that that. The code lacks any validation that `imread` succeeds, although I don't think that's the issue here. Those window decorations look like a Mac, and I recall seeing some questions about something similar. – Dan Mašek Jun 19 '17 at 23:25
  • @Baron Can you specify what OS you're using and which version of Python and OpenCV this happens with? – Dan Mašek Jun 19 '17 at 23:25
  • 1
    @DanMašek thanks for the link. There was a recent question similar, the issue was never resolved. The OP ended up using Matplotlib for display. – alkasm Jun 19 '17 at 23:26
  • @AlexanderReynolds Ya, this smells like a bug or some conflict in OpenCV, so extra details from OP woudl be really useful. – Dan Mašek Jun 19 '17 at 23:32
  • 1
    @DanMašek here was the other recent question: https://stackoverflow.com/questions/44603844/opencv-python-cv2-imshow-only-showing-top-bar-on-mac. He was on macOS, showed that he installed with the [pyImageSearch guide for OpenCV 3 and Python 3.5](http://www.pyimagesearch.com/2016/12/05/macos-install-opencv-3-and-python-3-5). – alkasm Jun 19 '17 at 23:52
  • @DanMašek, I'm on OSX Sierra. And you're right I was using that guide. I'm using python 2.7 and OpenCV 3, though but this is the exact issue I'm running into. It seems like they can get the image to show using plt, but not cv2. I wonder if there's a fix for this...I guess in the end using plt isn't the worst. Thanks for the link to the other issue. – Baron Jun 20 '17 at 12:28
  • Related bug report: https://github.com/opencv/opencv/issues/8885 – Dan Mašek Jun 22 '17 at 17:18
  • I ran into a similar issue a while ago and [this](https://stackoverflow.com/a/44553641/4962554) was my solution – eshirima Jun 27 '17 at 22:03

0 Answers0