Skip to content

Commit d174bca

Browse files
fix ocr pipe (#3618)
1 parent 3c23a9a commit d174bca

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

paddlex/inference/models/text_recognition/processors.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,25 @@ class OCRReisizeNormImg:
3535
def __init__(self, rec_image_shape=[3, 48, 320]):
3636
super().__init__()
3737
self.rec_image_shape = rec_image_shape
38+
self.max_imgW = 3200
3839

3940
def resize_norm_img(self, img, max_wh_ratio):
4041
"""resize and normalize the img"""
4142
imgC, imgH, imgW = self.rec_image_shape
4243
assert imgC == img.shape[2]
4344
imgW = int((imgH * max_wh_ratio))
44-
45-
h, w = img.shape[:2]
46-
ratio = w / float(h)
47-
if math.ceil(imgH * ratio) > imgW:
48-
resized_w = imgW
45+
if imgW > self.max_imgW:
46+
resized_image = cv2.resize(img, (self.max_imgW, imgH))
47+
resized_w = self.max_imgW
48+
imgW = self.max_imgW
4949
else:
50-
resized_w = int(math.ceil(imgH * ratio))
51-
resized_image = cv2.resize(img, (resized_w, imgH))
50+
h, w = img.shape[:2]
51+
ratio = w / float(h)
52+
if math.ceil(imgH * ratio) > imgW:
53+
resized_w = imgW
54+
else:
55+
resized_w = int(math.ceil(imgH * ratio))
56+
resized_image = cv2.resize(img, (resized_w, imgH))
5257
resized_image = resized_image.astype("float32")
5358
resized_image = resized_image.transpose((2, 0, 1)) / 255
5459
resized_image -= 0.5

0 commit comments

Comments
 (0)