base64转换成np、opencv、PIL

 

# coding: utf-8
import base64
import numpy as np
import cv2
from PIL import Image
import io
import PIL
 
img_file = open('4.png','rb')   # 二进制打开图片文件
img_b64encode = base64.b64encode(img_file.read())  # base64编码
img_file.close()  # 文件关闭
img_b64decode = base64.b64decode(img_b64encode) # base64解码 img_array = np.frombuffer(img_b64decode,np.uint8) # 转换np序列 img=cv2.imdecode(img_array,cv2.COLOR_BGR2RGB) # 转换Opencv格式 image = io.BytesIO(img_b64decode) good_image = Image.open(image)#PIL
posted @ 2020-01-07 09:27  悦悦的小屋  阅读(725)  评论(0编辑  收藏  举报