python下使用opencv+numpy实现Mat和Base64互转

import cv2
import numpy as np
import base64


mat = cv2.imread("/home/lab/2.png")
# Mat to Base64
string = base64.b64encode(cv2.imencode('.png', mat)[1]).decode()

print(string)

# Base64 to Mat
img_original = base64.b64decode(string)
img_np = np.frombuffer(img_original, dtype=np.uint8)
img = cv2.imdecode(img_np, cv2.IMREAD_UNCHANGED)

cv2.imwrite('/home/lab/1.png',img)

 

posted @ 2020-04-23 15:54  来兮子宁  阅读(607)  评论(0编辑  收藏