diff --git a/ppocr/data/imaug/rec_img_aug.py b/ppocr/data/imaug/rec_img_aug.py index ed3026a5f4547481bb2abd75b871bdf68072414a..725b4b0617c2f0808c7bf99077e2f62caa3afbf0 100644 --- a/ppocr/data/imaug/rec_img_aug.py +++ b/ppocr/data/imaug/rec_img_aug.py @@ -219,21 +219,18 @@ class VLRecResizeImg(object): def __call__(self, data): img = data['image'] - if self.infer_mode and self.character_dict_path is not None: - norm_img, valid_ratio = resize_norm_img_chinese(img, - self.image_shape) + + imgC, imgH, imgW = self.image_shape + resized_image = cv2.resize( + img, (imgW, imgH), interpolation=cv2.INTER_LINEAR) + resized_w = imgW + resized_image = resized_image.astype('float32') + if self.image_shape[0] == 1: + resized_image = resized_image / 255 + norm_img = resized_image[np.newaxis, :] else: - imgC, imgH, imgW = self.image_shape - resized_image = cv2.resize( - img, (imgW, imgH), interpolation=cv2.INTER_LINEAR) - resized_w = imgW - resized_image = resized_image.astype('float32') - if self.image_shape[0] == 1: - resized_image = resized_image / 255 - norm_img = resized_image[np.newaxis, :] - else: - norm_img = resized_image.transpose((2, 0, 1)) / 255 - valid_ratio = min(1.0, float(resized_w / imgW)) + norm_img = resized_image.transpose((2, 0, 1)) / 255 + valid_ratio = min(1.0, float(resized_w / imgW)) data['image'] = norm_img data['valid_ratio'] = valid_ratio diff --git a/tools/infer/predict_rec.py b/tools/infer/predict_rec.py index 911f75112da712d3493dd932d69850944ae95fab..e1d0d596ea82deeca3665a9eafd2fa78d6863a19 100755 --- a/tools/infer/predict_rec.py +++ b/tools/infer/predict_rec.py @@ -166,6 +166,7 @@ class TextRecognizer(object): def resize_norm_img_vl(self, img, image_shape): imgC, imgH, imgW = image_shape + img = img[:, :, ::-1] # bgr2rgb resized_image = cv2.resize( img, (imgW, imgH), interpolation=cv2.INTER_LINEAR) resized_image = resized_image.astype('float32') diff --git a/tools/infer_rec.py b/tools/infer_rec.py index a08fa25b467482da4a2996912ad2cc8cc7c398da..182694e6cda12ead0e263bb94a7d6483a6f7f212 100755 --- a/tools/infer_rec.py +++ b/tools/infer_rec.py @@ -131,7 +131,6 @@ def main(): if config['Architecture']['algorithm'] == "SAR": valid_ratio = np.expand_dims(batch[-1], axis=0) img_metas = [paddle.to_tensor(valid_ratio)] - images = np.expand_dims(batch[0], axis=0) images = paddle.to_tensor(images) if config['Architecture']['algorithm'] == "SRN":