You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
910 B
Python

import requests
import base64
import uuid
# 函数用于读取图片并将其转换为 Base64 编码
def image_to_base64(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode('utf-8')
# FastAPI 服务的 URL
url = "http://192.168.10.137:8866/ocr"
# url = "http://127.0.0.1:8000/ocr"
# 准备测试数据
pictures = [
{
"pic_id": uuid.uuid4().int, # 生成整数类型的 pic_id
"pic": image_to_base64(r"E:\Project\PaddleOCR\doc\imgs\10.08\Image_00032.jpg")
},
{
"pic_id": uuid.uuid4().int, # 生成另一个唯一的整数类型 pic_id
"pic": image_to_base64(r"E:\Project\PaddleOCR\doc\imgs\10.08\Image_00032.jpg")
}
]
# 发送 POST 请求
response = requests.post(url, json=pictures)
# 打印响应结果
print("Status Code:", response.status_code)
print("Response JSON:", response.json())