matplotlib.pyplot与cv2、Image.open 读取图片显示的差异

来源:互联网 发布:l36h刷机软件 编辑:程序博客网 时间:2024/05/22 13:21

简介

In the Python bindings of OpenCV, images are represented as NumPy arrays in BGR order. This works fine when using the cv2.imshow function. However, if you intend on using Matplotlib, the plt.imshow function assumes the image is in RGB order. A simple call to cv2.cvtColor will resolve this problem, or you can use the opencv2matplotlib convenience function.

cv2.imshow读取图片的NumPy arrays数组是以 BGR order形式保存的,而Matplotlib中的plt.imshow 是以RGB顺序保存的。若要以plt显示需要用imutils.opencv2matplotlib函数,或者要将Image.open 读取的图片正常显示需要cv2.cvtColor来调用。

图片Gaussian pyramid(一)Image.open 读取
http://blog.csdn.net/u011463646/article/details/77415047

代码

import matplotlib.pyplot  as pltimport cv2import imutilscactus = cv2.imread('')  # INCORRECT: show the image without converting color spacesplt.figure("Incorrect")plt.imshow(cactus)# CORRECT: convert color spaces before using plt.imshowplt.figure("Correct")plt.imshow(imutils.opencv2matplotlib(cactus))plt.show()

效果

这里写图片描述

参考

【1】图片Gaussian pyramid(一)Image.open 读取
http://blog.csdn.net/u011463646/article/details/77415047
【2】https://github.com/jrosebr1/imutils

阅读全文
0 0
原创粉丝点击