import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt#读取图像
#cv2.IMREAD_COLOR: 读取彩色图像,忽略alpha通道,也可以直接写1
#cv2.IMREAD_GRAYSCALE: 读取灰度图,也可以直接写0
#cv2.IMREAD_UNCHANGED: 读取原始图像数据,包括alpha通道,也可以直接写-1
img = cv.imread("pomeranian.png", cv.IMREAD_COLOR)#显示图像信息
print(img.shape)#opencv原始窗口显示图像
cv.imshow("pomeranian", img)
cv.waitKey(0)
cv.destroyAllWindows()#matplotlib显示图像
plt.imshow(img[:,:,::-1])
plt.show()#matplotlib显示灰度图,https://blog.csdn.net/qq_30967115/article/details/85053415
img = cv.imread("pomeranian.png", cv.IMREAD_GRAYSCALE)
plt.imshow(img, cmap="gray")
plt.show()#写入图像
#imwrite详细参考:https://blog.csdn.net/m0_55320151/article/details/127012570
cv.imwrite("dog.png", img)