|
10 | 10 | img_path = "tests/test_files/ch_en_num.jpg" |
11 | 11 |
|
12 | 12 | # 方式一:使用base64编码传 |
13 | | -stime = time.time() |
| 13 | +stime = time.perf_counter() |
14 | 14 | with open(img_path, "rb") as fa: |
15 | 15 | img_str = base64.b64encode(fa.read()) |
16 | 16 |
|
17 | 17 | payload = {"image_data": img_str} |
18 | | -response = requests.post(url, data=payload) # , timeout=60 |
| 18 | +response = requests.post(url, data=payload, timeout=180) |
19 | 19 |
|
20 | | -print(response) |
21 | | -etime = time.time() - stime |
22 | | -print(f"用时:{etime:.3f}秒") |
| 20 | +print(response.json()) |
| 21 | +elapse = time.perf_counter() - stime |
| 22 | +print(f"用时:{elapse:.3f}秒") |
23 | 23 |
|
24 | 24 | print("-" * 40) |
25 | 25 |
|
26 | | -# # 方式二:使用文件上传方式 |
27 | | -# stime = time.time() |
28 | | -# with open(img_path, "rb") as f: |
29 | | -# file_dict = {"image_file": (img_path, f, "image/png")} |
30 | | -# response = requests.post(url, files=file_dict) # , timeout=60 |
31 | | -# print(response.json()) |
32 | | - |
33 | | -# etime = time.time() - stime |
34 | | -# print(f"用时:{etime:.3f}秒") |
35 | | -# print("-" * 40) |
36 | | - |
37 | | -# # 方式三:控制是否使用检测、方向分类和识别这三部分的模型; 不使用检测模型:use_det=False |
38 | | -# stime = time.time() |
39 | | -# img_path = "../python/tests/test_files/test_without_det.jpg" |
40 | | - |
41 | | -# with open(img_path, "rb") as f: |
42 | | -# file_dict = {"image_file": (img_path, f, "image/png")} |
43 | | -# # 添加控制参数 |
44 | | -# data = {"use_det": False, "use_cls": True, "use_rec": True} |
45 | | -# response = requests.post(url, files=file_dict, data=data) # , timeout=60 |
46 | | -# print(response.json()) |
47 | | - |
48 | | -# etime = time.time() - stime |
49 | | -# print(f"用时:{etime:.3f}秒") |
50 | | -# print("-" * 40) |
| 26 | +# 方式二:使用文件上传方式 |
| 27 | +stime = time.perf_counter() |
| 28 | +with open(img_path, "rb") as f: |
| 29 | + file_dict = {"image_file": (img_path, f, "image/png")} |
| 30 | + response = requests.post(url, files=file_dict, timeout=180) |
| 31 | + print(response.json()) |
| 32 | + |
| 33 | +elapse = time.perf_counter() - stime |
| 34 | +print(f"用时:{elapse:.3f}秒") |
| 35 | +print("-" * 40) |
| 36 | + |
| 37 | +# 方式三:控制是否使用检测、方向分类和识别这三部分的模型; 不使用检测模型:use_det=False |
| 38 | +stime = time.perf_counter() |
| 39 | +img_path = "tests/test_files/ch_en_num.jpg" |
| 40 | + |
| 41 | +with open(img_path, "rb") as f: |
| 42 | + file_dict = {"image_file": (img_path, f, "image/png")} |
| 43 | + # 添加控制参数 |
| 44 | + data = {"use_det": False, "use_cls": True, "use_rec": True} |
| 45 | + response = requests.post(url, files=file_dict, data=data, timeout=180) |
| 46 | + print(response.json()) |
| 47 | + |
| 48 | +elapse = time.perf_counter() - stime |
| 49 | +print(f"用时:{elapse:.3f}秒") |
| 50 | +print("-" * 40) |
0 commit comments