在python_opencv中使用matplotlib进行绘图
读取当前文件夹下的图片并显示出来
彩色图像使用 OpenCV 加载时是 BGR 模式。但是 Matplotib 是 RGB
模式。所以彩色图像如果已经被 OpenCV 读取,那它将不会被 Matplotib 正
确显示。具体细节请看练习
**#-*- coding utf-8 -*-
import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread('tu.jpg')
b,g,r = cv2.split(img)
img2 = cv2.merge([r,g,b])
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.imwrite('memory.png',img2)
cv2.imshow('rgb image',img2) # expects distorted color
cv2.waitKey(0)
cv2.destroyAllWindows()**
2859

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



