|
|
|
@ -48,6 +48,32 @@ def resize_norm_img(img, image_shape):
|
|
|
|
|
return padding_im
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def resize_norm_img_chinese(img, image_shape):
|
|
|
|
|
imgC, imgH, imgW = image_shape
|
|
|
|
|
# todo: change to 0 and modified image shape
|
|
|
|
|
max_wh_ratio = 10
|
|
|
|
|
h, w = img.shape[0], img.shape[1]
|
|
|
|
|
ratio = w * 1.0 / h
|
|
|
|
|
max_wh_ratio = max(max_wh_ratio, ratio)
|
|
|
|
|
imgW = int(32 * max_wh_ratio)
|
|
|
|
|
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')
|
|
|
|
|
if image_shape[0] == 1:
|
|
|
|
|
resized_image = resized_image / 255
|
|
|
|
|
resized_image = resized_image[np.newaxis, :]
|
|
|
|
|
else:
|
|
|
|
|
resized_image = resized_image.transpose((2, 0, 1)) / 255
|
|
|
|
|
resized_image -= 0.5
|
|
|
|
|
resized_image /= 0.5
|
|
|
|
|
padding_im = np.zeros((imgC, imgH, imgW), dtype=np.float32)
|
|
|
|
|
padding_im[:, :, 0:resized_w] = resized_image
|
|
|
|
|
return padding_im
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_img_data(value):
|
|
|
|
|
"""get_img_data"""
|
|
|
|
|
if not value:
|
|
|
|
@ -67,7 +93,10 @@ def process_image(img,
|
|
|
|
|
char_ops=None,
|
|
|
|
|
loss_type=None,
|
|
|
|
|
max_text_length=None):
|
|
|
|
|
norm_img = resize_norm_img(img, image_shape)
|
|
|
|
|
if char_ops.character_type == "en":
|
|
|
|
|
norm_img = resize_norm_img(img, image_shape)
|
|
|
|
|
else:
|
|
|
|
|
norm_img = resize_norm_img_chinese(img, image_shape)
|
|
|
|
|
norm_img = norm_img[np.newaxis, :]
|
|
|
|
|
if label is not None:
|
|
|
|
|
char_num = char_ops.get_char_num()
|
|
|
|
|