主要是为了记录下一些简单的命令。
import cv2
image = cv2.imread('图片路径')
image = cv2.imread('xx.jpg') #读取jpg格式图片
image = cv2.imread('xx.png',cv2.IMREAD_UNCHANGED) #读取png格式图片
image = cv2.imread('xx.png',-1) #读取png格式图片
image = cv2.imread('xx.jpg',0) #读取灰度图
cv2.imshow('',img) #显示图片
cv2.waitKey(0) #按键等待事件
cv2.destroyAllWindows() #摧毁窗口
cv2.imwrite('图片保存路径',image)
import cv2
img = cv2.imread('xxx')
cutted = img[y0:y1,x0:x1]
import cv2
import numpy as np
img1 = cv2.imread('xxx')
img2 = cv2.imread('xxx')
np.concatenate((img,img1), axis=1)
import cv2
img = cv2.imread('xxx')
img = cv2.resize(img,(长,宽))
4、图像添加文字
cv2.putText(blank, 'Hello World', (0, 225),cv2.FONT_HERSHEY_TRIPLEX, 1.0, (255, 0, 0), 2)
import cv2
import numpy as np
blank = np.zeros((255,255,3),dtype='uint8') #创建一个全黑的图片
cv2.putText(blank, 'Hello World', (0, 225),cv2.FONT_HERSHEY_TRIPLEX, 1.0, (255, 0, 0), 2)
cv2.imshow('', blank)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.rectangle(img, (x1, y1), (x2, y2), (100, 210, 20), 2)