图像处理笔记(6)---- OpenCV waitKey函数

函数格式:waitKey(x);
参数x :

  • 等待x秒,如果在x秒期间,按下任意键,则立刻结束并返回按下键的ASCll码,否则返回-1
  • 若 x=0,那么会无限等待下去,直到有按键按下。
import cv2
from matplotlib import pyplot as plt
img = cv2.imread("C:\\Users\\SPC20-012\\Pictures\\girl.png", 0)
cv2.imshow("Image", img)
k = cv2.waitKey(0)&0xFF
#按下ESC时关闭图片窗口
if k == 27:
    cv2.destroyAllWindows()
#按下s键时保存并关闭图片窗口
elif k == ord('s'):
    cv2.imwrite("C:\\Users\\SPC20-012\\Pictures\\girl1.png", img)
    cv2.destroyAllWindows()

猜你喜欢

转载自blog.csdn.net/qq_24546137/article/details/108661263