This Python code displayed an image in full screen:
blank_image = cv2.imread('blank.jpg')
cv2.namedWindow("bw", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("bw", cv2.WND_PROP_FULLSCREEN, cv2.cv.CV_WINDOW_FULLSCREEN)
cv2.imshow("bw", blank_image)
cv2.waitKey(0)
The problem is the code is going to run on a Linux machine without keyboard. Calling waitKey means the UI processing will not be done until a key event occurs, and thus the contradiction.
Is there any way beside the waitKey, then?
waitKey() , the NOTE section mentions that 'This function is the only method in HighGUI that can fetch and handle events, so it needs to be called periodically for normal event processing unless HighGUI is used within an environment that takes care of event processing. ' You can notice that without the cv2.
waitKey(0) will pause your screen because it will wait infinitely for keyPress on your keyboard and will not refresh the frame( cap. read() ) using your WebCam.
waitkey() function of Python OpenCV allows users to display a window for given milliseconds or until any key is pressed. It takes time in milliseconds as a parameter and waits for the given time to destroy the window, if 0 is passed in the argument it waits till any key is pressed.
Just to clarify: from the docs you can see that
Python: cv2.waitKey([delay]) → retval
The function waitKey waits for a key event infinitely (when delay <= 0 ) or for delay milliseconds, when it is positive.
If you use the delay = 0
, then your program waits for a key event infinitely, blocking the execution. As @Miki said, you can use delay = 1
, so that waitKey
won't block.
You can use matplotlib
library for displaying images in python.
In [9]: blank_image = cv2.imread('blank.jpg')
In [10]: import matplotlib.pyplot as plt
In [11]: plt.ion()
In [12]: plt.imshow(blank_image)
Out[12]: <matplotlib.image.AxesImage at 0x7fb3cf31bf10>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With