Last active
March 28, 2016 18:30
-
-
Save ericxyan/136bba6b573fd17312bb to your computer and use it in GitHub Desktop.
Opencv read image as BGR, a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
import matplotlib.pyplot as plt | |
# show diff | |
# Approach 0 | |
img = cv2.imread('messi4.jpg') | |
b,g,r = cv2.split(img) | |
img2 = cv2.merge([r,g,b]) | |
plt.subplot(121);plt.imshow(img) # expects distorted color | |
plt.subplot(122);plt.imshow(img2) # expect true color | |
plt.show() | |
cv2.imshow('bgr image',img) # expects true color | |
cv2.imshow('rgb image',img2) # expects distorted color | |
cv2.waitKey(0) | |
cv2.destroyAllWindows() | |
# Approach 1 | |
img2 = img[:,:,::-1] | |
# Approach 2 | |
img2 = img[..., ::-1] | |
# Approach 3 | |
cv2.cvtColor(img, cv2.BGR2RGB) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Stackoverflow