From 87ce916a2b8463dda351d9040dbf635caf758de5 Mon Sep 17 00:00:00 2001 From: tink2123 Date: Tue, 30 Jun 2020 13:08:33 +0800 Subject: [PATCH 1/4] fix resize shape --- ppocr/data/rec/img_tools.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ppocr/data/rec/img_tools.py b/ppocr/data/rec/img_tools.py index e8ac462..3ca20f3 100755 --- a/ppocr/data/rec/img_tools.py +++ b/ppocr/data/rec/img_tools.py @@ -97,7 +97,7 @@ def process_image(img, max_text_length=None, tps=None, infer_mode=False): - if not infer_mode or char_ops.character_type == "en" or tps != None: + if not infer_mode and (char_ops.character_type == "en" or tps != None): norm_img = resize_norm_img(img, image_shape) else: norm_img = resize_norm_img_chinese(img, image_shape) @@ -109,7 +109,8 @@ def process_image(img, logger.info( "Warning in ppocr/data/rec/img_tools.py:line106: Wrong data type." "Excepted string with length between 1 and {}, but " - "got '{}'. Label is '{}'".format(max_text_length, len(text),label)) + "got '{}'. Label is '{}'".format(max_text_length, + len(text), label)) return None else: if loss_type == "ctc": From 1c8cddf46f85d4359881a16a8014121f3aeec9de Mon Sep 17 00:00:00 2001 From: tink2123 Date: Tue, 30 Jun 2020 13:59:59 +0800 Subject: [PATCH 2/4] fix resize norm for ch --- ppocr/data/rec/img_tools.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ppocr/data/rec/img_tools.py b/ppocr/data/rec/img_tools.py index 3ca20f3..ef4e4e5 100755 --- a/ppocr/data/rec/img_tools.py +++ b/ppocr/data/rec/img_tools.py @@ -53,6 +53,7 @@ def resize_norm_img(img, image_shape): def resize_norm_img_chinese(img, image_shape): imgC, imgH, imgW = image_shape # todo: change to 0 and modified image shape + imgC = 3 max_wh_ratio = 0 h, w = img.shape[0], img.shape[1] ratio = w * 1.0 / h @@ -97,10 +98,11 @@ def process_image(img, max_text_length=None, tps=None, infer_mode=False): - if not infer_mode and (char_ops.character_type == "en" or tps != None): - norm_img = resize_norm_img(img, image_shape) - else: + if infer_mode and char_ops.character_type == "ch" and not tps: norm_img = resize_norm_img_chinese(img, image_shape) + else: + norm_img = resize_norm_img(img, image_shape) + norm_img = norm_img[np.newaxis, :] if label is not None: # char_num = char_ops.get_char_num() From 2cc1d00b049f2cb0edeb5ce5f899351e8f7c615e Mon Sep 17 00:00:00 2001 From: tink2123 Date: Tue, 30 Jun 2020 14:47:24 +0800 Subject: [PATCH 3/4] revert modified for predict_rec --- tools/infer/predict_rec.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/infer/predict_rec.py b/tools/infer/predict_rec.py index 41e556b..cc580a6 100755 --- a/tools/infer/predict_rec.py +++ b/tools/infer/predict_rec.py @@ -53,7 +53,7 @@ class TextRecognizer(object): imgC, imgH, imgW = self.rec_image_shape assert imgC == img.shape[2] if self.character_type == "ch": - imgW = int(math.ceil(32 * max_wh_ratio)) + imgW = int((32 * max_wh_ratio)) h, w = img.shape[:2] ratio = w / float(h) if math.ceil(imgH * ratio) > imgW: From 5fae5ffd5ec9670659f4750b8147e8fc3692ffad Mon Sep 17 00:00:00 2001 From: tink2123 Date: Tue, 30 Jun 2020 15:03:37 +0800 Subject: [PATCH 4/4] update img_tools --- ppocr/data/rec/img_tools.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ppocr/data/rec/img_tools.py b/ppocr/data/rec/img_tools.py index ef4e4e5..9c4bfa4 100755 --- a/ppocr/data/rec/img_tools.py +++ b/ppocr/data/rec/img_tools.py @@ -53,7 +53,6 @@ def resize_norm_img(img, image_shape): def resize_norm_img_chinese(img, image_shape): imgC, imgH, imgW = image_shape # todo: change to 0 and modified image shape - imgC = 3 max_wh_ratio = 0 h, w = img.shape[0], img.shape[1] ratio = w * 1.0 / h