Displaying image without waitKey

放肆的年华 提交于 2021-02-20 06:50:30

问题


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?


回答1:


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.




回答2:


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>


来源:https://stackoverflow.com/questions/32560289/displaying-image-without-waitkey

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!