728x90
  • OpenCV is BGR, Pillow is RGB
im_bgr = cv2.imread('data/src/lena.jpg')

im_rgb = im_bgr[:, :, [2, 1, 0]]
Image.fromarray(im_rgb).save('data/dst/lena_swap.jpg')

im_rgb = im_bgr[:, :, ::-1] 
Image.fromarray(im_rgb).save('data/dst/lena_swap_2.jpg')

 

note.nkmk.me/en/python-opencv-bgr-rgb-cvtcolor/

 

Convert BGR and RGB with Python, OpenCV (cvtColor) | note.nkmk.me

When the image file is read with the OpenCV function imread(), the order of colors is BGR (blue, green, red). On the other hand, in Pillow, the order of colors is assumed to be RGB (red, green, blue).Therefore, if you want to use both the Pillow function a

note.nkmk.me

 

728x90

+ Recent posts