Skip to content

Instantly share code, notes, and snippets.

@ericxyan
Last active March 28, 2016 18:30
Show Gist options
  • Save ericxyan/136bba6b573fd17312bb to your computer and use it in GitHub Desktop.
Save ericxyan/136bba6b573fd17312bb to your computer and use it in GitHub Desktop.
Opencv read image as BGR, a
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)
@ericxyan
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment