1import cv2
2import numpy as np
3from PIL import Image
4
5img = cv2.imread("path/to/img.png")
6
7# You may need to convert the color.
8img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
9im_pil = Image.fromarray(img)
10
11# For reversing the operation:
12im_np = np.asarray(im_pil)