diff --git a/tools/infer/predict_rec.py b/tools/infer/predict_rec.py index 7c94225506bb2d3291503e033fd9139fc2b752a4..77dc82aad25bec5023367d051ec195001c4fd8e7 100755 --- a/tools/infer/predict_rec.py +++ b/tools/infer/predict_rec.py @@ -60,12 +60,12 @@ class TextRecognizer(object): self.loss_type = 'srn' self.char_ops = CharacterOps(char_ops_params) - def resize_norm_img(self, img, wh_ratio): + def resize_norm_img(self, img, max_wh_ratio): imgC, imgH, imgW = self.rec_image_shape assert imgC == img.shape[2] - max_wh_ration = max(wh_ratio, imgW * 1.0 / imgH) + wh_ratio = max(max_wh_ratio, imgW * 1.0 / imgH) if self.character_type == "ch": - imgW = int((32 * max_wh_ratio)) + imgW = int((32 * wh_ratio)) h, w = img.shape[:2] ratio = w / float(h) if math.ceil(imgH * ratio) > imgW: @@ -174,14 +174,16 @@ class TextRecognizer(object): for beg_img_no in range(0, img_num, batch_num): end_img_no = min(img_num, beg_img_no + batch_num) norm_img_batch = [] + max_wh_ratio = 0 for ino in range(beg_img_no, end_img_no): # h, w = img_list[ino].shape[0:2] h, w = img_list[indices[ino]].shape[0:2] wh_ratio = w * 1.0 / h + max_wh_ratio = max(max_wh_ratio, wh_ratio) for ino in range(beg_img_no, end_img_no): if self.loss_type != "srn": norm_img = self.resize_norm_img(img_list[indices[ino]], - wh_ratio) + max_wh_ratio) norm_img = norm_img[np.newaxis, :] norm_img_batch.append(norm_img) else: