Window freezing even after using waitKey() and destroyAllwindows() in Opencv

北慕城南 提交于 2021-01-27 18:36:05

问题


ENVIRONMENT

OS- mint Linux, using opencv3.1,using spyder through anaconda

ISSUE

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?

CODE:-

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()

回答1:


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 hangs/freeze when camera disconnected instead of returning "False"

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



来源:https://stackoverflow.com/questions/48868348/window-freezing-even-after-using-waitkey-and-destroyallwindows-in-opencv

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