1、得接口为:http://xxx.xxx.xxx.xx:xxxx/det/predict
# 测试AutoOD接口
import requests
import base64
# 读取图片文件,your_image_file.jpg为你图片路径,即传入的参数
with open('your_image_file.jpg', 'rb') as f:
image_data = f.read()
# 这里是需要注意的部分,图片处理的格式不同
encoded_string = base64.b64encode(image_data).decode()
# print('encoded_string:', encoded_string)
# 构建请求的数据
# "conf_thres": 0.4,"debug": 0,是本程序的请求格式,请按照你自己的格式进行填写,无则写第一行即可
data = {
'image': encoded_string,
"conf_thres": 0.4,
"debug": 0
}
# 发送POST请求,http://xxx.xxx.xxx.xx:xxxx/det/predict为请求的接口
response = requests.post("http://xxx.xxx.xxx.xx:xxxx/det/predict", json=data)
# 打印返回的结果
print(response.text)