Reputation: 115
The thing is, I have this code:
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()
So blue is getting converted to yellow... is this a hint that RGB is converted to CMYK?
what should i do to keep my colors same as original?
*note: This is not an ad
Upvotes: 2
Views: 4168
Reputation: 8636
Use img = img[:,:,::-1]
to shuffle the color channels form BGR to RGB.
pyplot.subplot(121),pyplot.imshow(img[:,:,::-1] ),pyplot.title('Input')
pyplot.subplot(122),pyplot.imshow(dst[:,:,::-1] ),pyplot.title('Output')
pyplot.show()
Here is the matplotlib
input and output images.
Upvotes: 3
Reputation: 3028
For historical reasons, OpenCV uses a BGR color representation. You can convert your images before displaying them using:
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
Upvotes: 3