Skip to content

Instantly share code, notes, and snippets.

@Ripley6811
Created September 17, 2012 05:50
Show Gist options
  • Save Ripley6811/3735758 to your computer and use it in GitHub Desktop.
Save Ripley6811/3735758 to your computer and use it in GitHub Desktop.
PIL image to CV2 image
# PIL RGB 'im' to CV2 BGR 'imcv'
imcv = np.asarray(im)[:,:,::-1].copy()
# Or
imcv = cv2.cvtColor(np.asarray(im), cv2.COLOR_RGB2BGR)
# To gray image
imcv = np.asarray(im.convert('L'))
# Or
imcv = cv2.cvtColor(np.asarray(im), cv2.COLOR_RGB2GRAY)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment