opencv官方文档上写的,
Color image loaded by OpenCV is in BGR mode. But Matplotlib displays in RGB mode. So color images will not be displayed correctly in Matplotlib if image is read with OpenCV. Please see the exercises for more details.
import cv2import numpy as npimport matplotlib.pyplot as pltimg = cv2.imread('messi4.jpg')b,g,r = cv2.split(img)img2 = cv2.merge([r,g,b])#img2 = img[:,:,::-1]plt.subplot(121);plt.imshow(img) # expects distorted colorplt.subplot(122);plt.imshow(img2) # expect true colorplt.show()cv2.imshow('bgr image',img) # expects true colorcv2.imshow('rgb image',img2) # expects distorted colorcv2.waitKey(0)cv2.destroyAllWindows()