python

超轻量级php框架startmvc

Python 实现OpenCV格式和PIL.Image格式互转

更新时间:2020-08-19 11:24:01 作者:startmvc
OpenCV转换成PIL.Image格式:importcv2fromPILimportImageimportnumpyimg=cv2.imread("plane.jpg")cv2.imshow("OpenCV",im

OpenCV转换成PIL.Image格式:


import cv2 
from PIL import Image 
import numpy 
 
img = cv2.imread("plane.jpg") 
cv2.imshow("OpenCV",img) 
image = Image.fromarray(cv2.cvtColor(img,cv2.COLOR_BGR2RGB)) 
image.show() 
cv2.waitKey() 

PIL.Image转换成OpenCV格式:


import cv2 
from PIL import Image 
import numpy 
 
image = Image.open("plane.jpg") 
image.show() 
img = cv2.cvtColor(numpy.asarray(image),cv2.COLOR_RGB2BGR) 
cv2.imshow("OpenCV",img) 
cv2.waitKey() 

以上这篇Python 实现OpenCV格式和PIL.Image格式互转就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

Python OpenCV PIL.Image