from PIL import Image, ImageFont, ImageDraw
im = Image.open("BC03.jpg")
print(im.format, im.size, im.mode)
im.show()
#result
JPEG (580, 1088) RGB
OpenCV 加载的彩色图像是 BGR 模式,
但 Matplotib 是 RGB模式。
所以彩色图像如果已经被 OpenCV 读入,
那它将不会被 Matplotib 正确显示。
matplotlib操作图像,需要解决彩色图像由BGR模式转RGB模式的问题。
import cv2
from matplotlib import pyplot as plt
img = cv2.imread(r'BC03.jpg')
img3 = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# 调用matplotlib显示
plt.subplot(221); plt.imshow(img)
#颜色错
plt.subplot(224); plt.imshow(img3)
#正确
plt.show()