Merge pull request #600 from LDOUBLEV/fixocr

fix bug in randomcropdata func
This commit is contained in:
Double_V 2020-09-10 10:35:11 +08:00 committed by GitHub
commit d31effaf97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 8 deletions

View File

@ -121,24 +121,22 @@ def RandomCropData(data, size):
all_care_polys = [ all_care_polys = [
text_polys[i] for i, tag in enumerate(ignore_tags) if not tag text_polys[i] for i, tag in enumerate(ignore_tags) if not tag
] ]
# 计算crop区域
crop_x, crop_y, crop_w, crop_h = crop_area(im, all_care_polys, crop_x, crop_y, crop_w, crop_h = crop_area(im, all_care_polys,
min_crop_side_ratio, max_tries) min_crop_side_ratio, max_tries)
# crop 图片 保持比例填充 dh, dw = size
scale_w = size[0] / crop_w scale_w = dw / crop_w
scale_h = size[1] / crop_h scale_h = dh / crop_h
scale = min(scale_w, scale_h) scale = min(scale_w, scale_h)
h = int(crop_h * scale) h = int(crop_h * scale)
w = int(crop_w * scale) w = int(crop_w * scale)
if keep_ratio: if keep_ratio:
padimg = np.zeros((size[1], size[0], im.shape[2]), im.dtype) padimg = np.zeros((dh, dw, im.shape[2]), im.dtype)
padimg[:h, :w] = cv2.resize( padimg[:h, :w] = cv2.resize(
im[crop_y:crop_y + crop_h, crop_x:crop_x + crop_w], (w, h)) im[crop_y:crop_y + crop_h, crop_x:crop_x + crop_w], (w, h))
img = padimg img = padimg
else: else:
img = cv2.resize(im[crop_y:crop_y + crop_h, crop_x:crop_x + crop_w], img = cv2.resize(im[crop_y:crop_y + crop_h, crop_x:crop_x + crop_w],
tuple(size)) (dw, dh))
# crop 文本框
text_polys_crop = [] text_polys_crop = []
ignore_tags_crop = [] ignore_tags_crop = []
texts_crop = [] texts_crop = []