今天继续研究OpenCV,还是从网上找个例程,读入一副图像,按’s’键保存后退出,其它任意键则直接退出不保存
- #!/usr/bin/env python
- #-*- coding:utf-8 -*-
- import numpy as np
- import cv2
- img = cv2.imread('img/nxp.png',cv2.IMREAD_UNCHANGED)
- cv2.imshow('image',img)
- k = cv2.waitKey(0)
- if k == ord('s'): # wait for 's' key to save and exit
- cv2.imwrite('1.png',img)
- cv2.destroyAllWindows()
- else:
- cv2.destroyAllWindows()
注意:#!/usr/bin/env python
#-*- coding:utf-8 -*-一定要加,不然会报错,ModuleNotFoundError: No module named 'numpy'保存,运行,按s键,保存,出现了1.png
要是按其他任意键,不会出现1.png
此内容由EEWORLD论坛网友star_66666原创,如需转载或用于商业用途需征得作者同意并注明出处