import requests
import json
import base64
class OCRClientTool:
def __init__(self, url):
self.url = url
def get_ocr_result(self, file_path):
# 读取文件内容并编码为base64字符串
with open(file_path, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
# 准备请求数据
data = {
"base64": encoded_string,
"options": {
"data.format": "text",
}
}
# 发送POST请求
try:
response = requests.post(self.url, json=data)
response.raise_for_status() # 检查请求是否成功
res_dict = json.loads(response.text)
return res_dict['data'
标签:base64,url,data,self,py,json,file,ocr,umi
From: https://blog.csdn.net/qq_45662588/article/details/145428630