opencv 转 PIL(PILLOW) 和PIL转opencv

import cv2
import numpy as np
from PIL import Image

#注意opencv通道顺序为BGR,pillow通道顺序为RGB,所以转的时候需要通道调整

#图片路径
img_path="pic.jpg"

#opencv 转Pillow
img_cv = cv2.imread(img_path)
img_pil = Image.fromarray(cv2.cvtColor(img_cv,cv2.COLOR_BGR2RGB))


#pillow转opencv
img_pil=Image.open(img_path)
img_cv= cv2.cvtColor(np.asarray(img_pil),cv2.COLOR_RGB2BGR)

你可能感兴趣的:(opencv,opencv,pillow,计算机视觉,python)