Python 读取图片 转 base64 并生成 JSON
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)
本文来自博客园,作者:VipSoft 转载请注明原文链接:https://www.cnblogs.com/vipsoft/p/17442991.html
 
                    
                     
                    
                 
                    
                 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号