我正在尝试使用matplotlib进行基本操作,但我发现只要我尝试使用matplotlib显示图像,就会在图像中添加蓝色阴影.
例如,
码:
# import the necessary packages
import numpy as np
import cv2
import matplotlib.pyplot as plt
image = cv2.imread("./data/images/cat_and_dog.jpg")
cv2.imshow('image',image) # Display the picture
plt.imshow(image)
plt.show()
cv2.waitKey(0) # wait for closing
cv2.destroyAllWindows() # Ok,destroy the window
opencv gui和matplotlib显示的图像是不同的.
甚至直方图也会失真,而不仅仅是显示
如何避免图像上出现此蓝色阴影
最佳答案
见:http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_image_display/py_image_display.html#using-matplotlib
原文链接:https://www.f2er.com/python/439398.htmlWarning: 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.
您可以使用以下行替换plt.imshow(image)行:
im2 = image.copy()
im2[:,:,0] = image[:,2]
im2[:,2] = image[:,0]
plt.imshow(im2)