SWHL commited on
Commit
d80ba6a
1 Parent(s): 042dccb

Update files

Browse files
Files changed (6) hide show
  1. .gitattributes +3 -0
  2. .gitignore +2 -0
  3. README.md +2 -2
  4. app.py +180 -116
  5. requirements.txt +0 -1
  6. utils.py +31 -38
.gitattributes CHANGED
@@ -34,3 +34,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
34
  *.TTF filter=lfs diff=lfs merge=lfs -text
35
  images/car_plate.jpeg filter=lfs diff=lfs merge=lfs -text
36
  *.ttc filter=lfs diff=lfs merge=lfs -text
 
 
 
 
34
  *.TTF filter=lfs diff=lfs merge=lfs -text
35
  images/car_plate.jpeg filter=lfs diff=lfs merge=lfs -text
36
  *.ttc filter=lfs diff=lfs merge=lfs -text
37
+ fonts/simfang.ttf filter=lfs diff=lfs merge=lfs -text
38
+ models/text_det/ch_PP-OCRv4_det_infer.onnx filter=lfs diff=lfs merge=lfs -text
39
+ models/text_rec/ch_PP-OCRv4_rec_infer.onnx filter=lfs diff=lfs merge=lfs -text
.gitignore CHANGED
@@ -1,3 +1,5 @@
1
  *.pyc
2
 
3
  __pycache__/
 
 
 
1
  *.pyc
2
 
3
  __pycache__/
4
+ .vscode
5
+ .DS_Store
README.md CHANGED
@@ -3,8 +3,8 @@ title: RapidOCR
3
  emoji: ⚡
4
  colorFrom: blue
5
  colorTo: blue
6
- sdk: gradio
7
- sdk_version: 3.6
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
 
3
  emoji: ⚡
4
  colorFrom: blue
5
  colorTo: blue
6
+ sdk: streamlit
7
+ sdk_version: 1.25.0
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
app.py CHANGED
@@ -1,138 +1,202 @@
1
  # -*- encoding: utf-8 -*-
2
- import json
 
3
  import time
4
  from pathlib import Path
5
 
6
  import cv2
7
- import gradio as gr
 
 
 
8
  from rapidocr_onnxruntime import RapidOCR
 
9
 
10
  from utils import visualize
11
 
12
  font_dict = {
13
- 'ch': 'FZYTK.TTF',
14
- 'japan': 'japan.ttc',
15
- 'korean': 'korean.ttf',
16
- 'en': 'FZYTK.TTF',
17
  }
18
 
19
 
20
- def inference(img_path, box_thresh=0.5, unclip_ratio=1.6, text_score=0.5,
21
- text_det=None, text_rec=None):
22
- out_log_list = []
23
-
24
- det_model_path = str(Path('models') / 'text_det' / text_det)
25
- rec_model_path = str(Path('models') / 'text_rec' / text_rec)
26
- if 'v2' in rec_model_path:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  rec_image_shape = [3, 32, 320]
28
  else:
29
  rec_image_shape = [3, 48, 320]
30
 
31
- out_log_list.append('Init Model')
32
- s = time.time()
33
- rapid_ocr = RapidOCR(det_model_path=det_model_path,
34
- rec_model_path=rec_model_path,
35
- rec_img_shape=rec_image_shape)
36
- elapse = time.time() - s
37
-
38
- if 'ch' in rec_model_path or 'en' in rec_model_path:
39
- lan_name = 'ch'
40
- elif 'japan' in rec_model_path:
41
- lan_name = 'japan'
42
- elif 'korean' in rec_model_path:
43
- lan_name = 'korean'
44
  else:
45
- lan_name = 'ch'
46
 
47
- out_log_list.append(f'Init Model cost: {elapse:.5f}')
48
- out_log_list.extend([f'det_model: {det_model_path}',
49
- f'rec_model: {rec_model_path}',
50
- f'rec_image_shape: {rec_image_shape}'])
 
51
 
52
- img = cv2.imread(img_path)
53
- ocr_result, infer_elapse = rapid_ocr(img, box_thresh=box_thresh,
54
- unclip_ratio=unclip_ratio,
55
- text_score=text_score)
56
  det_cost, cls_cost, rec_cost = infer_elapse
57
- out_log_list.extend([f'det cost: {det_cost:.5f}',
58
- f'cls cost: {cls_cost:.5f}',
59
- f'rec cost: {rec_cost:.5f}'])
60
- out_log = '\n'.join([str(v) for v in out_log_list])
61
- if not ocr_result:
62
- return img_path, '未识别到有效文本', out_log
63
-
64
  dt_boxes, rec_res, scores = list(zip(*ocr_result))
65
- font_path = Path('fonts') / font_dict.get(lan_name)
66
- img_save_path = visualize(img_path, dt_boxes, rec_res, scores,
67
- font_path=str(font_path))
68
- out_dict = {str(i): {'rec_txt': rec, 'score': score}
69
- for i, (rec, score) in enumerate(zip(rec_res, scores))}
70
- return img_save_path, out_dict, out_log
71
-
72
-
73
- if __name__ == '__main__':
74
- examples = [['images/1.jpg'],
75
- ['images/ch_en_num.jpg'],
76
- ['images/air_ticket.jpg'],
77
- ['images/car_plate.jpeg'],
78
- ['images/idcard.jpg'],
79
- ['images/train_ticket.jpeg'],
80
- ['images/japan_2.jpg'],
81
- ['images/korean_1.jpg']]
82
-
83
- with gr.Blocks(title='RapidOCR') as demo:
84
- gr.Markdown("""
85
- <h1><center><a href="https://github.com/RapidAI/RapidOCR" target="_blank">Rapid⚡OCR</a></center></h1>
86
-
87
- ### Docs: [Docs](https://rapidocr.rtfd.io/)
88
- ### 运行环境:
89
- Python: 3.8 | onnxruntime: 1.14.1 | rapidocr_onnxruntime: 1.2.5""")
90
- gr.Markdown(
91
- '''**[超参数调节](https://github.com/RapidAI/RapidOCR/tree/main/python#configyaml%E4%B8%AD%E5%B8%B8%E7%94%A8%E5%8F%82%E6%95%B0%E4%BB%8B%E7%BB%8D)**
92
- - **box_thresh**: 检测到的框是文本的概率,值越大,框中是文本的概率就越大。存在漏检时,调低该值。取值范围:[0, 1.0]
93
- - **unclip_ratio**: 控制文本检测框的大小,值越大,检测框整体越大。在出现框截断文字的情况,调大该值。取值范围:[1.5, 2.0]
94
- - **text_score**: 文本识别结果是正确的置信度,值越大,显示出的识别结果更准确。存在漏检时,调低该值。取值范围:[0, 1.0]
95
- ''')
96
- with gr.Row():
97
- box_thresh = gr.Slider(minimum=0, maximum=1.0, value=0.5,
98
- label='box_thresh', step=0.1,
99
- interactive=True,
100
- info='[0, 1.0]')
101
- unclip_ratio = gr.Slider(minimum=1.5, maximum=2.0, value=1.6,
102
- label='unclip_ratio', step=0.1,
103
- interactive=True,
104
- info='[1.5, 2.0]')
105
- text_score = gr.Slider(minimum=0, maximum=1.0, value=0.5,
106
- label='text_score', step=0.1,
107
- interactive=True,
108
- info='[0, 1.0]')
109
-
110
- gr.Markdown('**[模型选择](https://github.com/RapidAI/RapidOCR/blob/main/docs/models.md)** (模型转换→[PaddleOCRModelConverter](https://github.com/RapidAI/PaddleOCRModelConverter))')
111
- with gr.Row():
112
- text_det = gr.Dropdown(['ch_PP-OCRv3_det_infer.onnx',
113
- 'ch_PP-OCRv2_det_infer.onnx',
114
- 'ch_ppocr_server_v2.0_det_infer.onnx'],
115
- label='选择文本检测模型',
116
- value='ch_PP-OCRv3_det_infer.onnx',
117
- interactive=True)
118
- rec_model_list = [v.name for v in Path('models/text_rec').iterdir()]
119
- text_rec = gr.Dropdown(rec_model_list,
120
- label='选择文本识别模型(包括中英文和多语言,欢迎提交更多模型)',
121
- value='ch_PP-OCRv3_rec_infer.onnx',
122
- interactive=True)
123
-
124
- with gr.Row():
125
- input_img = gr.Image(type='filepath', label='Input')
126
- out_img = gr.Image(type='filepath', label='Output')
127
- out_json = gr.JSON(label='Rec Res')
128
- out_log = gr.outputs.Textbox(type='text', label='Run Log')
129
- button = gr.Button('Submit')
130
- button.click(fn=inference,
131
- inputs=[input_img, box_thresh, unclip_ratio, text_score,
132
- text_det, text_rec],
133
- outputs=[out_img, out_json, out_log])
134
- gr.Examples(examples=examples,
135
- inputs=[input_img, box_thresh, unclip_ratio, text_score,
136
- text_det, text_rec],
137
- outputs=[out_img, out_json, out_log], fn=inference)
138
- demo.launch(debug=True, enable_queue=True)
 
 
 
 
 
 
 
 
1
  # -*- encoding: utf-8 -*-
2
+ # @Author: SWHL
3
+ # @Contact: liekkaskono@163.com
4
  import time
5
  from pathlib import Path
6
 
7
  import cv2
8
+ import numpy as np
9
+ import pandas as pd
10
+ import streamlit as st
11
+ from PIL import Image
12
  from rapidocr_onnxruntime import RapidOCR
13
+ from streamlit_image_select import image_select
14
 
15
  from utils import visualize
16
 
17
  font_dict = {
18
+ "ch": "chinese_cht.ttf",
19
+ "japan": "japan.ttc",
20
+ "korean": "korean.ttf",
21
+ "en": "chinese_cht.ttf",
22
  }
23
 
24
 
25
+ def init_sidebar():
26
+ st.session_state["params"] = {}
27
+
28
+ st.sidebar.markdown(
29
+ "### [🛠️ Parameter Settings](https://github.com/RapidAI/RapidOCR/wiki/config_parameter)"
30
+ )
31
+ box_thresh = st.sidebar.slider(
32
+ "box_thresh",
33
+ min_value=0.0,
34
+ max_value=1.0,
35
+ value=0.5,
36
+ step=0.1,
37
+ help="检测到的框是文本的概率,值越大,框中是文本的概率就越大。存在漏检时,调低该值。取值范围:[0, 1.0],默认值为0.5",
38
+ )
39
+ st.session_state["params"]["box_thresh"] = box_thresh
40
+
41
+ unclip_ratio = st.sidebar.slider(
42
+ "unclip_ratio",
43
+ min_value=1.5,
44
+ max_value=2.0,
45
+ value=1.6,
46
+ step=0.1,
47
+ help="控制文本检测框的大小,值越大,检测框整体越大。在出现框截断文字的情况,调大该值。取值范围:[1.5, 2.0],默认值为1.6",
48
+ )
49
+ st.session_state["params"]["unclip_ratio"] = unclip_ratio
50
+
51
+ text_score = st.sidebar.slider(
52
+ "text_score",
53
+ min_value=0.0,
54
+ max_value=1.0,
55
+ value=0.5,
56
+ step=0.1,
57
+ help="文本识别结果是正确的置信度,值越大,显示出的识别结果更准确。存在漏检时,调低该值。取值范围:[0, 1.0],默认值为0.5",
58
+ )
59
+ st.session_state["params"]["text_score"] = text_score
60
+
61
+ img_file_buffer = st.sidebar.file_uploader(
62
+ "Upload an image",
63
+ accept_multiple_files=False,
64
+ label_visibility="visible",
65
+ type=["png", "jpg", "jpeg", "bmp"],
66
+ )
67
+ if img_file_buffer:
68
+ image = Image.open(img_file_buffer)
69
+ img = np.array(image)
70
+
71
+ with st.sidebar.container():
72
+ img_path = image_select(
73
+ label="Examples(click to select):",
74
+ images=examples,
75
+ key="equation_default",
76
+ use_container_width=True,
77
+ )
78
+ img = cv2.imread(img_path)
79
+ st.session_state["img"] = img
80
+
81
+
82
+ def inference(
83
+ text_det=None,
84
+ text_rec=None,
85
+ ):
86
+ img = st.session_state.get("img")
87
+ box_thresh = st.session_state["params"].get("box_thresh")
88
+ unclip_ratio = st.session_state["params"].get("unclip_ratio")
89
+ text_score = st.session_state["params"].get("text_score")
90
+
91
+ det_model_path = str(Path("models") / "text_det" / text_det)
92
+ rec_model_path = str(Path("models") / "text_rec" / text_rec)
93
+ if "v2" in rec_model_path:
94
  rec_image_shape = [3, 32, 320]
95
  else:
96
  rec_image_shape = [3, 48, 320]
97
 
98
+ rapid_ocr = RapidOCR(
99
+ det_model_path=det_model_path,
100
+ rec_model_path=rec_model_path,
101
+ rec_img_shape=rec_image_shape,
102
+ )
103
+
104
+ if "ch" in rec_model_path or "en" in rec_model_path:
105
+ lan_name = "ch"
106
+ elif "japan" in rec_model_path:
107
+ lan_name = "japan"
108
+ elif "korean" in rec_model_path:
109
+ lan_name = "korean"
 
110
  else:
111
+ lan_name = "ch"
112
 
113
+ ocr_result, infer_elapse = rapid_ocr(
114
+ img, box_thresh=box_thresh, unclip_ratio=unclip_ratio, text_score=text_score
115
+ )
116
+ if not ocr_result or not infer_elapse:
117
+ return None, None, None, None
118
 
 
 
 
 
119
  det_cost, cls_cost, rec_cost = infer_elapse
120
+ elapse = f"- `det cost`: {det_cost:.5f}\n - `cls cost`: {cls_cost:.5f}\n - `rec cost`: {rec_cost:.5f}"
 
 
 
 
 
 
121
  dt_boxes, rec_res, scores = list(zip(*ocr_result))
122
+ font_path = Path("fonts") / font_dict.get(lan_name)
123
+ vis_img = visualize(
124
+ Image.fromarray(img), dt_boxes, rec_res, scores, font_path=str(font_path)
125
+ )
126
+ out_df = pd.DataFrame(
127
+ [[rec, score] for rec, score in zip(rec_res, scores)],
128
+ columns=("Rec", "Score"),
129
+ )
130
+ return vis_img, out_df, elapse, rec_res
131
+
132
+
133
+ def tips(txt: str, wait_time: int = 2, icon: str = "🎉"):
134
+ st.toast(txt, icon=icon)
135
+ time.sleep(wait_time)
136
+
137
+
138
+ if __name__ == "__main__":
139
+ st.markdown(
140
+ "<h1 style='text-align: center;'><a href='https://github.com/RapidAI/RapidOCR' style='text-decoration: none'>Rapid⚡OCR</a></h1>",
141
+ unsafe_allow_html=True,
142
+ )
143
+ st.markdown(
144
+ """
145
+ <p align="left">
146
+ <a href=""><img src="https://img.shields.io/badge/Python->=3.6,<3.12-aff.svg"></a>
147
+ <a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg"></a>
148
+ <a href="https://pepy.tech/project/rapidocr_onnxruntime"><img src="https://static.pepy.tech/personalized-badge/rapidocr_onnxruntime?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=Downloads%20Ort"></a>
149
+ <a href="https://pypi.org/project/rapidocr-onnxruntime/"><img alt="PyPI" src="https://img.shields.io/pypi/v/rapidocr-onnxruntime"></a>
150
+ <a href='https://rapidocr.readthedocs.io/en/latest/?badge=latest'>
151
+ <img src='https://readthedocs.org/projects/rapidocr/badge/?version=latest' alt='Documentation Status' />
152
+ </p>
153
+ """,
154
+ unsafe_allow_html=True,
155
+ )
156
+
157
+ examples = [
158
+ "images/1.jpg",
159
+ "images/ch_en_num.jpg",
160
+ "images/air_ticket.jpg",
161
+ "images/car_plate.jpeg",
162
+ "images/train_ticket.jpeg",
163
+ "images/japan_2.jpg",
164
+ "images/korean_1.jpg",
165
+ ]
166
+
167
+ init_sidebar()
168
+
169
+ menu_det, menu_rec = st.columns([1, 1])
170
+ det_models = [
171
+ "ch_PP-OCRv4_det_infer.onnx",
172
+ "ch_PP-OCRv3_det_infer.onnx",
173
+ "ch_PP-OCRv2_det_infer.onnx",
174
+ "ch_ppocr_server_v2.0_det_infer.onnx",
175
+ ]
176
+ select_det = menu_det.selectbox("Det model:", det_models)
177
+
178
+ rec_models = [
179
+ "ch_PP-OCRv4_rec_infer.onnx",
180
+ "ch_PP-OCRv3_rec_infer.onnx",
181
+ "ch_PP-OCRv2_rec_infer.onnx",
182
+ "ch_ppocr_server_v2.0_rec_infer.onnx",
183
+ "en_PP-OCRv3_rec_infer.onnx",
184
+ "en_number_mobile_v2.0_rec_infer.onnx",
185
+ "korean_mobile_v2.0_rec_infer.onnx",
186
+ "japan_rec_crnn_v2.onnx",
187
+ ]
188
+ select_rec = menu_rec.selectbox("Rec model:", rec_models)
189
+
190
+ out_img, out_json, elapse, only_txts = inference(select_det, select_rec)
191
+ if all(v is not None for v in [out_img, out_json, elapse]):
192
+ st.markdown("#### Visualize:")
193
+ st.image(out_img)
194
+
195
+ st.markdown("### Rec Result:")
196
+ st.markdown(elapse)
197
+ st.dataframe(out_json, use_container_width=True)
198
+
199
+ st.markdown("### Only Txts")
200
+ st.code(only_txts)
201
+ else:
202
+ tips("识别结果为空", wait_time=5, icon="⚠️")
requirements.txt CHANGED
@@ -1,4 +1,3 @@
1
- Gradio
2
  Pillow
3
  onnxruntime==1.14.1
4
  rapidocr_onnxruntime==1.2.5
 
 
1
  Pillow
2
  onnxruntime==1.14.1
3
  rapidocr_onnxruntime==1.2.5
utils.py CHANGED
@@ -3,19 +3,16 @@
3
  # @Contact: liekkaskono@163.com
4
  import math
5
  import random
6
- import time
7
  from pathlib import Path
8
 
9
- import cv2
10
  import numpy as np
11
  from PIL import Image, ImageDraw, ImageFont
12
 
13
 
14
- def draw_ocr_box_txt(image, boxes, txts, font_path,
15
- scores=None, text_score=0.5):
16
  h, w = image.height, image.width
17
  img_left = image.copy()
18
- img_right = Image.new('RGB', (w, h), (255, 255, 255))
19
 
20
  random.seed(0)
21
  draw_left = ImageDraw.Draw(img_left)
@@ -24,62 +21,58 @@ def draw_ocr_box_txt(image, boxes, txts, font_path,
24
  if scores is not None and float(scores[idx]) < text_score:
25
  continue
26
 
27
- color = (random.randint(0, 255),
28
- random.randint(0, 255),
29
- random.randint(0, 255))
30
 
31
  box = [tuple(v) for v in box]
32
  draw_left.polygon(box, fill=color)
33
- draw_right.polygon([box[0][0], box[0][1],
34
- box[1][0], box[1][1],
35
- box[2][0], box[2][1],
36
- box[3][0], box[3][1]],
37
- outline=color)
38
 
39
- box_height = math.sqrt((box[0][0] - box[3][0])**2
40
- + (box[0][1] - box[3][1])**2)
 
 
 
 
 
 
 
 
 
 
 
41
 
42
- box_width = math.sqrt((box[0][0] - box[1][0])**2
43
- + (box[0][1] - box[1][1])**2)
 
 
 
 
 
44
 
45
  if box_height > 2 * box_width:
46
  font_size = max(int(box_width * 0.9), 10)
47
- font = ImageFont.truetype(font_path, font_size,
48
- encoding="utf-8")
49
  cur_y = box[0][1]
50
  for c in txt:
51
  char_size = font.getsize(c)
52
- draw_right.text((box[0][0] + 3, cur_y), c,
53
- fill=(0, 0, 0), font=font)
54
  cur_y += char_size[1]
55
  else:
56
  font_size = max(int(box_height * 0.8), 10)
57
  font = ImageFont.truetype(font_path, font_size, encoding="utf-8")
58
- draw_right.text([box[0][0], box[0][1]], txt,
59
- fill=(0, 0, 0), font=font)
60
 
61
  img_left = Image.blend(image, img_left, 0.5)
62
- img_show = Image.new('RGB', (w * 2, h), (255, 255, 255))
63
  img_show.paste(img_left, (0, 0, w, h))
64
  img_show.paste(img_right, (w, 0, w * 2, h))
65
  return np.array(img_show)
66
 
67
 
68
- def visualize(image_path, boxes, txts, scores,
69
- font_path="./fonts/FZYTK.TTF"):
70
- image = Image.open(image_path)
71
-
72
- draw_img = draw_ocr_box_txt(image, boxes,
73
- txts, font_path,
74
- scores,
75
- text_score=0.5)
76
 
77
  draw_img_save = Path("./inference_results/")
78
  if not draw_img_save.exists():
79
  draw_img_save.mkdir(parents=True, exist_ok=True)
80
-
81
- time_stamp = time.strftime(
82
- '%Y-%m-%d-%H-%M-%S', time.localtime(time.time()))
83
- image_save = str(draw_img_save / f'{time_stamp}_{Path(image_path).name}')
84
- cv2.imwrite(image_save, draw_img[:, :, ::-1])
85
- return image_save
 
3
  # @Contact: liekkaskono@163.com
4
  import math
5
  import random
 
6
  from pathlib import Path
7
 
 
8
  import numpy as np
9
  from PIL import Image, ImageDraw, ImageFont
10
 
11
 
12
+ def draw_ocr_box_txt(image, boxes, txts, font_path, scores=None, text_score=0.5):
 
13
  h, w = image.height, image.width
14
  img_left = image.copy()
15
+ img_right = Image.new("RGB", (w, h), (255, 255, 255))
16
 
17
  random.seed(0)
18
  draw_left = ImageDraw.Draw(img_left)
 
21
  if scores is not None and float(scores[idx]) < text_score:
22
  continue
23
 
24
+ color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
 
 
25
 
26
  box = [tuple(v) for v in box]
27
  draw_left.polygon(box, fill=color)
28
+ draw_right.text([box[3][0], box[3][1]], str(idx), fill=color)
 
 
 
 
29
 
30
+ draw_right.polygon(
31
+ [
32
+ box[0][0],
33
+ box[0][1],
34
+ box[1][0],
35
+ box[1][1],
36
+ box[2][0],
37
+ box[2][1],
38
+ box[3][0],
39
+ box[3][1],
40
+ ],
41
+ outline=color,
42
+ )
43
 
44
+ box_height = math.sqrt(
45
+ (box[0][0] - box[3][0]) ** 2 + (box[0][1] - box[3][1]) ** 2
46
+ )
47
+
48
+ box_width = math.sqrt(
49
+ (box[0][0] - box[1][0]) ** 2 + (box[0][1] - box[1][1]) ** 2
50
+ )
51
 
52
  if box_height > 2 * box_width:
53
  font_size = max(int(box_width * 0.9), 10)
54
+ font = ImageFont.truetype(font_path, font_size, encoding="utf-8")
 
55
  cur_y = box[0][1]
56
  for c in txt:
57
  char_size = font.getsize(c)
58
+ draw_right.text((box[0][0] + 3, cur_y), c, fill=(0, 0, 0), font=font)
 
59
  cur_y += char_size[1]
60
  else:
61
  font_size = max(int(box_height * 0.8), 10)
62
  font = ImageFont.truetype(font_path, font_size, encoding="utf-8")
63
+ draw_right.text([box[0][0], box[0][1]], txt, fill=(0, 0, 0), font=font)
 
64
 
65
  img_left = Image.blend(image, img_left, 0.5)
66
+ img_show = Image.new("RGB", (w * 2, h), (255, 255, 255))
67
  img_show.paste(img_left, (0, 0, w, h))
68
  img_show.paste(img_right, (w, 0, w * 2, h))
69
  return np.array(img_show)
70
 
71
 
72
+ def visualize(image, boxes, txts, scores, font_path="./fonts/FZYTK.TTF"):
73
+ draw_img = draw_ocr_box_txt(image, boxes, txts, font_path, scores, text_score=0.5)
 
 
 
 
 
 
74
 
75
  draw_img_save = Path("./inference_results/")
76
  if not draw_img_save.exists():
77
  draw_img_save.mkdir(parents=True, exist_ok=True)
78
+ return draw_img[:, :, ::-1]