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:
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()
I'm running on macOS 10.11, python 3.6.1
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.