即使在Opencv中使用waitKey()和destroyAllwindows()之后,窗口也会冻结 [英] Window freezing even after using waitKey() and destroyAllwindows() in Opencv
问题描述
环境
OS-薄荷Linux,使用opencv3.1,通过anaconda使用spyder
OS- mint Linux, using opencv3.1,using spyder through anaconda
问题
下面提到的代码将打开一个名称框窗口,并显示通过便携式摄像机捕获的视频.但是,如代码中所述,当我按"q"键时,它将停止并终止该窗口.但是,在此窗口停止显示捕获的任何其他帧,并且不会终止.然后手动强制退出该过程.
The code mentioned below opens a window of name frame and display the video captured through laptop camera.But when I press 'q', as mentioned in code, it should stop and terminate the window. But,here the window stops to display any further frames captured and do not terminates.then manually I force Quit the process.
有什么问题,为什么不终止窗口?
What is the problem, why is it not terminating the window?
代码:-
import cv2
import numpy as np
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()
推荐答案
此问题有一个未解决的错误:
There is an open bug with this issue:
https://github.com/opencv/opencv/issues/7343
还有类似的问题,没有好的解决方案:
There are also similar questions without a good solution:
当断开相机连接时,opencv videocapture挂起/冻结返回"False"
在此处尝试解决方案: DestroyWindow可以在Mac上使用Python和OpenCV关闭窗口多次调用waitKey似乎对许多人都有效.您也可以尝试不使用release()
Try the solutions here: DestroyWindow does not close window on Mac using Python and OpenCV Calling several times waitKey seems to work for many people. You can try without the release() as well
这篇关于即使在Opencv中使用waitKey()和destroyAllwindows()之后,窗口也会冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!