服务器访问yolov5接口

import time

import requests, base64, cv2


# url = 'http://127.0.0.1:5555/yolov5'
url = 'http://43.139.184.232:5555/yolov5'


def image_to_base64(image_path):
    import base64
    with open(image_path, "rb") as image_file:
        image_data = image_file.read()
        base64_encoded = base64.b64encode(image_data).decode("utf-8")
        return base64_encoded


image_path = r"E:\Code\Python\yolotest0823\datasets\coco128\images\train2017\000000000009.jpg"
base64_image = image_to_base64(image_path)
# print(base64_image)

dic = {
    "image_data": base64_image
}

t1 = time.time()
res = requests.post(url=url, json=dic)
t2 = time.time()
print(res.status_code)
print(res.json())
print(f'时间{t2-t1}')
posted @ 2023-08-28 16:10  __username  阅读(45)  评论(0编辑  收藏  举报

本文作者:DIVMonster

本文链接:https://www.cnblogs.com/guangzan/p/12886111.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。