0

cv2.imshow seems to not work correctly when running on Python3 but no errors are logged and it works correctly when I use opencv3 with python 2.7.

running this:

import cv2

cap = cv2.VideoCapture(0)

while True:
    ret, frame = cap.read()
    cv2.imshow('frame', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

simply displays:

image description

even creating a blank image doesn't work:

import numpy as np
import cv2

blank_image = np.zeros((600,600,3), np.uint8)
cv2.imshow("blank image", blank_image)
cv2.waitKey(0)

cv2.destroyAllWindows()

image description

I'm running on macOS 10.11, python 3.6.1

leakybytes
  • 359
  • 4
  • 12
  • Have you tried running your program from command line? Is there any difference if you increase the `waitKey` parameter? – alkasm Jun 09 '17 at 06:01
  • remove the `if` command inside the `while` loop and run it again. – Ramesh-X Jun 09 '17 at 15:52
  • Command line is the same, messing with waitkey() also made no difference. I also tried using opencv with c++, compiled and got the same thing. The only solution I found was coding up a qt GUI and passing the cv2 image as a Qimage – leakybytes Jun 09 '17 at 16:54

1 Answers1

0

I ran into the same problem with a similar setup (OpenCV 3.2.0-dev, Python 3.6.1, OS X 10.11.6).

For me at least, it seems to be rendering the image, but failing to resize the window to the correct dimensions. Try creating a namedWindow first, then use resizeWindow to set the dimensions:

cv2.namedWindow('image', cv2.WINDOW_NORMAL)
cv2.imshow('image', img)
cv2.resizeWindow('image', img.shape[0], img.shape[1])
cv2.waitKey(0)
cv2.destroyAllWindows()