Skip to content

Commit 02346e9

Browse files
committed
chore: add test files
1 parent 3523939 commit 02346e9

File tree

3 files changed

+39
-38
lines changed

3 files changed

+39
-38
lines changed

demo.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import requests
88

99
url = "http://localhost:9003/ocr"
10-
img_path = "../python/tests/test_files/ch_en_num.jpg"
10+
img_path = "tests/test_files/ch_en_num.jpg"
1111

1212
# 方式一:使用base64编码传
1313
stime = time.time()
@@ -23,28 +23,28 @@
2323

2424
print("-" * 40)
2525

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.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)

rapidocr_api/main.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@
1313
import uvicorn
1414
from fastapi import FastAPI, Form, UploadFile
1515
from PIL import Image
16-
from rapidocr import RapidOCR
17-
18-
# if importlib.util.find_spec("rapidocr_onnxruntime"):
19-
# from rapidocr_onnxruntime import RapidOCR
20-
# elif importlib.util.find_spec("rapidocr_paddle"):
21-
# from rapidocr_paddle import RapidOCR
22-
# elif importlib.util.find_spec("rapidocr_openvino"):
23-
# from rapidocr_openvino import RapidOCR
24-
# else:
25-
# raise ImportError(
26-
# "Please install one of [rapidocr_onnxruntime,rapidocr-paddle,rapidocr-openvino]"
27-
# )
16+
17+
# from rapidocr import RapidOCR
18+
19+
if importlib.util.find_spec("rapidocr_onnxruntime"):
20+
from rapidocr_onnxruntime import RapidOCR
21+
elif importlib.util.find_spec("rapidocr_paddle"):
22+
from rapidocr_paddle import RapidOCR
23+
elif importlib.util.find_spec("rapidocr_openvino"):
24+
from rapidocr_openvino import RapidOCR
25+
else:
26+
raise ImportError(
27+
"Please install one of [rapidocr_onnxruntime,rapidocr-paddle,rapidocr-openvino]"
28+
)
2829

2930
sys.path.append(str(Path(__file__).resolve().parent.parent))
3031

tests/test_files/ch_en_num.jpg

69 KB
Loading

0 commit comments

Comments
 (0)