cv2.imshow command doesn't work properly in opencv-python cv2.imshow command doesn't work properly in opencv-python python python

cv2.imshow command doesn't work properly in opencv-python


imshow() only works with waitKey():

import cv2img = cv2.imread('C:/Python27/03323_HD.jpg')cv2.imshow('ImageWindow', img)cv2.waitKey()

(The whole message-loop necessary for updating the window is hidden in there.)


I found the answer that worked for me here:http://txt.arboreus.com/2012/07/11/highgui-opencv-window-from-ipython.html

If you run an interactive ipython session, and want to use highgui windows, do cv2.startWindowThread() first.

In detail: HighGUI is a simplified interface to display images and video from OpenCV code. It should be as easy as:

import cv2img = cv2.imread("image.jpg")cv2.startWindowThread()cv2.namedWindow("preview")cv2.imshow("preview", img)


You must use cv2.waitKey(0) after cv2.imshow("window",img). Only then will it work.

import cv2img=cv2.imread('C:/Python27/03323_HD.jpg')cv2.imshow('Window',img)cv2.waitKey(0)