Python 读取图片 转 base64 并生成 JSON
import json
import base64
img_path = r'D:\OpenSource\PaddlePaddle\PaddleOCR\images\005.jpeg';
with open(img_path, 'rb') as file:
image_data1 = file.read()
image = base64.b64encode(image_data1).decode('utf8')
data = {"key": ["image"], "value": [image]}
# 转成 json 字符串
json_str = json.dumps(data)
print(json_str)