opencv python版-lesson 01

此为读取显示保存的方法,cv2.imread('opencv.jpg',0)读取灰度图

import cv2
# show and save the picture 
img = cv2.imread('opencv.jpg',0)
cv2.imshow('image',img)
cv2.namedWindow('image',cv2.WINDOW_NORMAL)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite('{}'.format('opencv.png'),img)

选择分支

import cv2
# show and save the picture 
img = cv2.imread('opencv.jpg',0)
cv2.imshow('image',img)
cv2.namedWindow('image',cv2.WINDOW_NORMAL)
k=cv2.waitKey(0)
if k==27:
    cv2.destroyAllWindows()
elif k==ord('s'):
    cv2.imwrite('{}'.format('opencv.png'),img)
    cv2.destroyAllWindows()

你可能感兴趣的:(opencv python版-lesson 01)