test_hubserving.py 658 字节
Newer Older
D
dyning 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#!usr/bin/python
# -*- coding: utf-8 -*-

import requests
import json
import cv2
import base64
import time

def cv2_to_base64(image):
    return base64.b64encode(image).decode('utf8')

start = time.time()
# 发送HTTP请求
data = {'images':[cv2_to_base64(open("./doc/imgs/11.jpg", 'rb').read())]}
headers = {"Content-type": "application/json"}
# url = "http://127.0.0.1:8866/predict/ocr_det"
# url = "http://127.0.0.1:8866/predict/ocr_rec"
url = "http://127.0.0.1:8866/predict/ocr_system"
r = requests.post(url=url, headers=headers, data=json.dumps(data))
end = time.time()

# 打印预测结果
print(r.json()["results"])
print("time cost: ", end - start)