Skip to content

Commit a40454c

Browse files
authored
fix: fixed issue #544 (#545)
1 parent 386c415 commit a40454c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

python/rapidocr/ch_ppocr_cls/main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def __init__(self, cfg: Dict[str, Any]):
3434
self.session = get_engine(cfg.engine_type)(cfg)
3535

3636
def __call__(self, img_list: Union[np.ndarray, List[np.ndarray]]) -> TextClsOutput:
37+
start_time = time.perf_counter()
38+
3739
if isinstance(img_list, np.ndarray):
3840
img_list = [img_list]
3941

@@ -59,17 +61,17 @@ def __call__(self, img_list: Union[np.ndarray, List[np.ndarray]]) -> TextClsOutp
5961
norm_img_batch.append(norm_img)
6062
norm_img_batch = np.concatenate(norm_img_batch).astype(np.float32)
6163

62-
starttime = time.time()
6364
prob_out = self.session(norm_img_batch)
6465
cls_result = self.postprocess_op(prob_out)
65-
elapse += time.time() - starttime
6666

6767
for rno, (label, score) in enumerate(cls_result):
6868
cls_res[indices[beg_img_no + rno]] = (label, score)
6969
if "180" in label and score > self.cls_thresh:
7070
img_list[indices[beg_img_no + rno]] = cv2.rotate(
7171
img_list[indices[beg_img_no + rno]], 1
7272
)
73+
74+
elapse = time.perf_counter() - start_time
7375
return TextClsOutput(img_list=img_list, cls_res=cls_res, elapse=elapse)
7476

7577
def resize_norm_img(self, img: np.ndarray) -> np.ndarray:

python/rapidocr/ch_ppocr_rec/main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def get_character_dict(self, cfg):
8484
return character, dict_path
8585

8686
def __call__(self, args: TextRecInput) -> TextRecOutput:
87+
start_time = time.perf_counter()
88+
8789
img_list = [args.img] if isinstance(args.img, np.ndarray) else args.img
8890
return_word_box = args.return_word_box
8991

@@ -116,7 +118,6 @@ def __call__(self, args: TextRecInput) -> TextRecOutput:
116118
norm_img_batch.append(norm_img[np.newaxis, :])
117119
norm_img_batch = np.concatenate(norm_img_batch).astype(np.float32)
118120

119-
start_time = time.perf_counter()
120121
preds = self.session(norm_img_batch)
121122
line_results, word_results = self.postprocess_op(
122123
preds,
@@ -131,10 +132,11 @@ def __call__(self, args: TextRecInput) -> TextRecOutput:
131132
continue
132133

133134
rec_res[indices[beg_img_no + rno]] = (one_res, None)
134-
elapse += time.perf_counter() - start_time
135135

136136
all_line_results, all_word_results = list(zip(*rec_res))
137137
txts, scores = list(zip(*all_line_results))
138+
139+
elapse = time.perf_counter() - start_time
138140
return TextRecOutput(
139141
img_list,
140142
txts,

0 commit comments

Comments
 (0)