Skip to content

Commit 083e035

Browse files
committed
chore: update files
1 parent 2b08a56 commit 083e035

3 files changed

Lines changed: 36 additions & 53 deletions

File tree

demo.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,41 @@
1010
img_path = "tests/test_files/ch_en_num.jpg"
1111

1212
# 方式一:使用base64编码传
13-
stime = time.time()
13+
stime = time.perf_counter()
1414
with open(img_path, "rb") as fa:
1515
img_str = base64.b64encode(fa.read())
1616

1717
payload = {"image_data": img_str}
18-
response = requests.post(url, data=payload) # , timeout=60
18+
response = requests.post(url, data=payload, timeout=180)
1919

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}秒")
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.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)

rapidocr_api/main.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,14 @@ def __call__(
4343
img, use_det=use_det, use_cls=use_cls, use_rec=use_rec, **kwargs
4444
)
4545

46-
if not ocr_res:
46+
if ocr_res.boxes is None or ocr_res.txts is None or ocr_res.scores is None:
4747
return {}
4848

49-
import pdb
50-
51-
pdb.set_trace()
52-
5349
out_dict = {}
54-
for i, dats in enumerate(ocr_res):
55-
values = {}
56-
for dat in dats:
57-
if isinstance(dat, str):
58-
values["rec_txt"] = dat
59-
60-
if isinstance(dat, np.float32):
61-
values["score"] = f"{dat:.4f}"
62-
63-
if isinstance(dat, list):
64-
values["dt_boxes"] = dat
65-
out_dict[str(i)] = values
66-
50+
for i, (boxes, txt, score) in enumerate(
51+
zip(ocr_res.boxes, ocr_res.txts, ocr_res.scores)
52+
):
53+
out_dict[i] = {"rec_txt": txt, "dt_boxes": boxes.tolist(), "score": score}
6754
return out_dict
6855

6956

@@ -95,6 +82,7 @@ def ocr(
9582
"When sending a post request, data or files must have a value."
9683
)
9784
ocr_res = processor(img, use_det=use_det, use_cls=use_cls, use_rec=use_rec)
85+
9886
return ocr_res
9987

10088

setup.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,4 @@ def get_readme():
7777
f"{MODULE_NAME}={MODULE_NAME}.main:main",
7878
],
7979
},
80-
extras_require={
81-
"onnx": ["rapidocr-onnxruntime"],
82-
"paddle": ["rapidocr-paddle"],
83-
"openvino": ["rapidocr-openvino"],
84-
},
8580
)

0 commit comments

Comments
 (0)