python读取图片的两种办法

1.opencv

img_bgr=cv2.imread('test/im1904.jpg',cv2.IMREAD_UNCHANGED)
cv2.imshow('img',img_bgr)
cv2.waitKey(0)
cv2.destroyAllWindows()
2.matplotlib

     

img=matplotlib.image.imread('test/im1904.jpg')
plt.imshow(img)
plt.show()
3.混合

因为opencv读取是按bgr通道读取,如果要用plt的方式显示,则需要先转换成rgb

img_bgr=cv2.imread('test/im1904.jpg',cv2.IMREAD_UNCHANGED)
img_rgb = np.zeros(img_bgr.shape, img_bgr.dtype)
img_rgb[:,:,0] = img_bgr[:,:,2]
img_rgb[:,:,1] = img_bgr[:,:,1]
img_rgb[:,:,2] = img_bgr[:,:,0]
plt.imshow(img_rgb)


猜你喜欢

转载自blog.csdn.net/shuijiaobuzhundahulu/article/details/79086019