|
|
@@ -37,20 +37,25 @@ class OCRReisizeNormImg:
|
|
|
def __init__(self, rec_image_shape=[3, 48, 320]):
|
|
|
super().__init__()
|
|
|
self.rec_image_shape = rec_image_shape
|
|
|
+ self.max_imgW = 3200
|
|
|
|
|
|
def resize_norm_img(self, img, max_wh_ratio):
|
|
|
"""resize and normalize the img"""
|
|
|
imgC, imgH, imgW = self.rec_image_shape
|
|
|
assert imgC == img.shape[2]
|
|
|
imgW = int((imgH * max_wh_ratio))
|
|
|
-
|
|
|
- h, w = img.shape[:2]
|
|
|
- ratio = w / float(h)
|
|
|
- if math.ceil(imgH * ratio) > imgW:
|
|
|
- resized_w = imgW
|
|
|
+ if imgW > self.max_imgW:
|
|
|
+ resized_image = cv2.resize(img, (self.max_imgW, imgH))
|
|
|
+ resized_w = self.max_imgW
|
|
|
+ imgW = self.max_imgW
|
|
|
else:
|
|
|
- resized_w = int(math.ceil(imgH * ratio))
|
|
|
- resized_image = cv2.resize(img, (resized_w, imgH))
|
|
|
+ h, w = img.shape[:2]
|
|
|
+ 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))
|
|
|
resized_image = resized_image.astype("float32")
|
|
|
resized_image = resized_image.transpose((2, 0, 1)) / 255
|
|
|
resized_image -= 0.5
|