# matplotlib interprets images in RGB format, but OpenCV uses BGR format
# so to convert the image so that it's properly loaded, convert it before loading
img = cv2.imread('filename.ext') # this is read in BGR format
rgb_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # this converts it into RGB
plt.imshow(rgb_img)
plt.show()
cv2.imshow() is disabled in Colab, because it causes Jupyter sessions for google colab
最新推荐文章于 2022-11-23 20:11:54 发布
本文介绍了在图像处理中OpenCV和Matplotlib对于颜色格式的不同处理方式。OpenCV默认使用BGR格式读取图片,而Matplotlib则使用RGB。为确保正确显示,需要在加载图片后进行颜色转换。示例代码展示了如何使用cv2.cvtColor将BGR图像转换为RGB格式,以便用plt.imshow正确显示。
1234

被折叠的 条评论
为什么被折叠?



