Python OpenCV - waitKey(0) does not respond?

后端 未结 12 902
忘掉有多难
忘掉有多难 2020-12-29 02:58

I\'m using opencv 2.4.7 on ubuntu 12.04. I\'m programming with python and I have a problem when i run this script:

import cv2

img = cv2.imread(\'34762092361         


        
12条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 03:08

    This will work even if you close the window using the cross button on the window.

    import numpy as np
    import cv2
    
    img = cv2.imread('arvid.jpg', 0)
    cv2.namedWindow('image', cv2.WINDOW_NORMAL)
    cv2.imshow('image', img)
    
    while True:
        k = cv2.waitKey(30) & 0xFF
        if k == 27:         # wait for ESC key to exit
            cv2.destroyAllWindows()
        elif k == ord('s'):  # wait for 's' key to save and exit
            cv2.imwrite('arvid2.jpg', img)
            cv2.destroyAllWindows()
        if cv2.getWindowProperty("image", 0) == -1:
            break
    

提交回复
热议问题