OpenCV 版本:3.4.3
編程語(yǔ)言:Python
原文:https://docs.opencv.org/3.4.3/dc/d2e/tutorial_py_image_display.html
用 Matplotlib 展示圖像
Matplotlib 是 Python 的繪圖庫(kù),提供了各種繪圖方法。
import cv2 as cv
from matplotlib import pyplot as plt
img = cv.imread('/Users/scott/Documents/opencv-test-01.bmp', cv.IMREAD_UNCHANGED)
plt.imshow(img, cmap = 'gray', interpolation = 'bicubic')
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.show()
注意:
OpenCV 以BGR模式加載彩色圖像,Matplotlib 以RGB模式顯示。因此,如果使用 OpenCV 讀取圖像,則 Matplotlib 中的彩色圖像將無(wú)法正確顯示。