def numpy_to_base64(image_np):
data = cv2.imencode('.jpg', image_np)[1]
image_bytes = data.tobytes()
image_base4 = base64.b64encode(image_bytes).decode('utf8')
return image_base4
def base64_to_numpy(img_bs64):
img_bs64 = base64.b64decode(img_bs64)
img_array = np.frombuffer(img_bs64, np.uint8)
cv2_img = cv2.imdecode(img_array, cv2.IMREAD_COLOR)
return cv2_img
【python】 np转base64, base64转np
于 2022-04-18 20:54:33 首次发布
本文介绍了如何使用NumPy库进行图像数据的Base64编码转换,包括将图像转为字节并编码,以及从Base64字符串还原成图像的过程。这对于数据传输和存储有着实际应用价值。
1万+

被折叠的 条评论
为什么被折叠?



