import requests
import base64
import json,cv2
import numpy as np
# opencv读取出来的图片相当于numpy数组
def cv2_to_base64(image):
image1 = cv2.imencode('.jpg', image)[1]
image_code = str(base64.b64encode(image1))[2:-1]
return image_code
def base64_to_cv2(image_code):
#解码
img_data=base64.b64decode(image_code)
#转为numpy
img_array=np.fromstring(img_data,np.uint8)
#转成opencv可用格式
img=cv2.imdecode(img_array,cv2.COLOR_RGB2BGR)
return img