避免关闭OpenCv窗口

时间:2020-11-10 14:06:13

标签: python opencv video cv2 opencv-python

是否可以通过任何方式禁用或隐藏cv2.window中的X按钮,或者至少更改其行为,以便在单击窗口时没有任何反应?

PS:我正在使用Windows 10,Python 3.6和OpenCV 4.3.0

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以添加一个循环以显示您使用的窗口,并将键的条件添加到您批准关闭窗口的waitKey中(例如esc)

while video.isOpened(): #Starting a loop to play the video continuously
    ret, frame = video.read()

    if not ret:
        break

    cv2.imshow('Video Player',frame) # Display the video

    k = cv2.waitKey(0) & 0xFF

    if k == 27:    # Use Esc key to exit the program
        break