是否可以多次打开和关闭同一个cv2窗口?

时间:2019-10-22 19:37:23

标签: python python-3.x opencv

我的程序是关于在python上打开cv2的情况下显示来自摄像机的图像。

用户可以多次打开和关闭同一窗口(按窗口名称)。

第一次尝试关闭所有内容的用户运行正常,但是在第二次尝试关闭时,python冻结。

我正在使用cv2.destroyWindow(windowName),但在销毁之前尝试过cv2.destroyAllWindows()cv2.waitKey(1),但这些方法均无效。

我在Windows操作系统上,我看到此问题在MAC OS上很常见

用户选择:

s1 = View()

while is_true:
    print("1 -> Start Camera")
    print("2 -> Close Camera")
    print("3 -> End")

    usr_input = input()


    if usr_input == "1":
        s1.show("topic1", frame) #frame is the image from camera"  
    elif usr_input == "2":  
        s1.close("topic1")
    elif usr_input == "3":
        is_true = False
    else: 
        print("Invalid month")

查看课程:

class View:        
    def show(self, name, frame):
        cv2.imshow(name, frame)
        cv2.waitKey(1)

    def close(self, name):
        cv2.destroyWindow(name)
        cv2.waitKey(1)

0 个答案:

没有答案