一、opencv读取图片
1、 相关代码
img = cv2.imread('path')
# 显示图片
cv2.imshow("name", img)
cv2.waitKey()
cv2.destroyAllWindows()
2、读取结果类型和通道顺序
type: numpy.ndarray
older: (height, weight, channel) 或者 (x, y, z)
3、通道特别注意!!!
channel = 3 : 通道顺序是 **BGR**
channel = 1 : 图像是灰度图
二、PIL 读取图片
1、 相关代码
img = Image.open(data_path)
# 显示图片需要用到 matplotlib.pyplot
import matplotlib.pyplot as plt
plt.imshow(img)
plt.show()
2、读取结果类型和通道顺序
# PIL 读取的 img 需要转化为 np.array 进行操作
type: <class 'PIL.JpegImagePlugin.JpegImageFile'>
older: (height, weight, channel) 或者 (x, y, z)
3、通道特别注意!!!
channel = 3 : 通道顺序是 **RGB**
channel = 1 : 图像是灰度图
注释:坐标顺序与opencv相同
三、 总结
opencv与PIL读取图像的最主要区别是,通道顺序不同, opencv为:BGR, PIL为:RGB