标签:
最近看MATLAB有点看不下去。。。就忍不住回到python的怀抱。研究下OpenCV,就当放松啦,对视觉还是很感兴趣的。
这里和之后代码大部分是来自这里的文档。
首先是对图片的处理。
‘‘‘ import numpy as np import cv2 import time # Load an color image in grayscale # cv2.IMREAD_COLOR,cv2.IMREAD_GRAYSCALE,cv2.IMREAD_UNCHANGED img = cv2.imread(‘cute.jpg‘,0) # 2sd=1 --> color # print(img) # 即使路径有误,找不到图片,也不会报错,返回None # Display an image cv2.namedWindow(‘image‘,cv2.WINDOW_NORMAL) cv2.imshow(‘image‘,img) # window name and image data cv2.waitKey(0) # 窗口停留时间,毫秒1s=1000ms cv2.destroyAllWindows() # 关闭所有窗口,也可指定特定窗口 # Write an image cv2.imwrite(‘my_cute.png‘,img) ‘‘‘ # Sum it up import numpy as np import cv2 img = cv2.imread(‘cute.jpg‘,0) # 0,为gray;1为original cv2.imshow(‘image‘,img) k = cv2.waitKey(0) if k == 27: # waut for ESC key to exit cv2.destroyAllWindows() elif k == ord(‘s‘): # wait for ‘s‘ key to save and exit cv2.imwrite(‘my_cute.jpg‘,img) cv2.destroyAllWindows()
这里的cute.jpg是这幅(好萌。。):
代码输出:
标签:
原文地址:http://www.cnblogs.com/buzhizhitong/p/5918462.html