In [1]:
import cv2
import numpy as np
from PIL import Image

In [2]:
im_cv = cv2.imread('data/src/lena.jpg')

In [3]:
cv2.imwrite('data/dst/lena_bgr_cv.jpg', im_cv)


Out[3]:
True

In [4]:
pil_img = Image.fromarray(im_cv)
pil_img.save('data/dst/lena_bgr_pillow.jpg')

In [5]:
im_rgb = cv2.cvtColor(im_cv, cv2.COLOR_BGR2RGB)

In [6]:
Image.fromarray(im_rgb).save('data/dst/lena_rgb_pillow.jpg')

In [7]:
cv2.imwrite('data/dst/lena_rgb_cv.jpg', im_rgb)


Out[7]:
True

In [8]:
im_pillow = np.array(Image.open('data/src/lena.jpg'))

In [9]:
im_bgr = cv2.cvtColor(im_pillow, cv2.COLOR_RGB2BGR)

In [10]:
cv2.imwrite('data/dst/lena_bgr_cv_2.jpg', im_bgr)


Out[10]:
True

In [11]:
im_bgr = cv2.imread('data/src/lena.jpg')

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

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