为什么这个 python 程序在处理图像时将蓝色转换为黄色?

Why does this python program convert blue color to yellow when working on the image?

问题是,我有这段代码:

import numpy as np
import cv2
from matplotlib import pyplot
img = cv2.imread('C:\Users\Niranjan\Desktop\FINAL YEAR PROJECT\Python Codes\obj.jpg')
rows,cols,ch = img.shape
pts1 = np.float32([[170,220],[466,221],[110,540],[528,541]])
pts2 = np.float32([[0,0],[530,0],[0,542],[530,542]])
M = cv2.getPerspectiveTransform(pts1,pts2)
dst = cv2.warpPerspective(img,M,(530,542))
pyplot.subplot(121),pyplot.imshow(img),pyplot.title('Input')
pyplot.subplot(122),pyplot.imshow(dst),pyplot.title('Output')
pyplot.show()

所以蓝色正在转换为黄色...这是否暗示 RGB 已转换为 CMYK?

我应该怎么做才能使我的颜色与原始颜色保持一致?

*注意:这不是广告

For historical reasons,OpenCV使用BGR颜色表示。您可以在显示图像之前转换图像:

image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

使用 img = img[:,:,::-1] 将颜色通道从 BGR 打乱为 RGB。

pyplot.subplot(121),pyplot.imshow(img[:,:,::-1] ),pyplot.title('Input')
pyplot.subplot(122),pyplot.imshow(dst[:,:,::-1] ),pyplot.title('Output')
pyplot.show()

这里是 matplotlib 输入和输出图像。