From 9e9a9a45daaf41ccff6fc6066b7a4ba22a73336c Mon Sep 17 00:00:00 2001 From: zhangxin Date: Wed, 24 Jun 2020 19:50:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=86=E5=88=ABinfer=E6=97=B6=E6=94=B9?= =?UTF-8?q?=E5=9B=9E=E4=B8=8D=E5=90=8C=E5=AD=97=E7=AC=A6=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E9=87=87=E7=94=A8=E4=B8=8D=E5=90=8C=E5=BD=92=E4=B8=80=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/infer/predict_rec.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/infer/predict_rec.py b/tools/infer/predict_rec.py index 5ec3cc60..f7540494 100755 --- a/tools/infer/predict_rec.py +++ b/tools/infer/predict_rec.py @@ -50,9 +50,14 @@ class TextRecognizer(object): def resize_norm_img(self, img, max_wh_ratio): imgC, imgH, imgW = self.rec_image_shape assert imgC == img.shape[2] - imgW = int(math.ceil(32 * max_wh_ratio)) + if self.character_type == "ch": + imgW = int(math.ceil(32 * max_wh_ratio)) h, w = img.shape[:2] - resized_w = int(math.ceil(imgH * w / float(h))) + ratio = w / float(h) + if math.ceil(imgH * ratio) > imgW: + resized_w = imgW + else: + resized_w = int(math.ceil(imgH * ratio)) resized_image = cv2.resize(img, (resized_w, imgH), interpolation=cv2.INTER_CUBIC) resized_image = resized_image.astype('float32') resized_image = resized_image.transpose((2, 0, 1)) / 255 -- GitLab