opencv imshow plt imshow

Posted jianyingzhou

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了opencv imshow plt imshow相关的知识,希望对你有一定的参考价值。

 

opencv官方文档上写的,https://docs.opencv.org/master/dc/d2e/tutorial_py_image_display.html

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.

https://stackoverflow.com/questions/15072736/extracting-a-region-from-an-image-using-slicing-in-python-opencv/15074748#15074748

import cv2
import numpy as np
import matplotlib.pyplot as plt

img = 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 color
plt.subplot(122);plt.imshow(img2) # expect true color
plt.show()

cv2.imshow(‘bgr image‘,img) # expects true color
cv2.imshow(‘rgb image‘,img2) # expects distorted color
cv2.waitKey(0)
cv2.destroyAllWindows()

  

以上是关于opencv imshow plt imshow的主要内容,如果未能解决你的问题,请参考以下文章

plt.imshow与cv2.imshow显示颜色问题

plt.imshow() 和 plt.show() 没有图像弹出或显示

没有图像弹出或显示plt.imshow()和plt.show()

plt格式打开字的颜色不统一怎么办

将 cv2.imshow() 与 matplotlib plt.show() 实时结合

OpenCV 例程300篇03. 图像的显示(cv2.imshow)