CV2读取图片,图片颜色发生改变解决方案

原因:cv2读取彩色图片通道顺序为B、G、R,PIL显示图片是R、G、B顺序,因此读出来图片颜色会改变,需要对图像通道进行调序。

调序:

b,g,r = cv2.split(image_1)
image_1 = cv2.merge([r,g,b])

应用实例:

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

image_path = 'E:/ImageStudy/python/Siamese-tf2-master/Siamese-tf2-master/img/copy.png'
image_1 = cv2.imread(image_path)

# cv2读出来是bgr,plt是rgb顺序,这是在调序
b,g,r = cv2.split(image_1)
image_1 = cv2.merge([r,g,b])

plt.subplot(1, 2, 1)
plt.imshow(np.array(image_1))
# 矩形框的左上角起点和右下角终点
first_point = (100, 100)
last_point = (300, 300)
cv2.rectangle(image_1, first_point, last_point, (0, 255, 0), 2)
plt.subplot(1, 2, 2)
plt.imshow(np.array(image_1))
plt.show()

你可能感兴趣的:(计算机视觉,opencv,人工智能)