diff --git a/ppocr/data/imaug/make_shrink_map.py b/ppocr/data/imaug/make_shrink_map.py index a66706f2bff25680a3597ef67ce5fa809747cf05..e8e4d43f10fe5e673f9038194c5c83c396faec73 100644 --- a/ppocr/data/imaug/make_shrink_map.py +++ b/ppocr/data/imaug/make_shrink_map.py @@ -44,20 +44,33 @@ class MakeShrinkMap(object): ignore_tags[i] = True else: polygon_shape = Polygon(polygon) - distance = polygon_shape.area * ( - 1 - np.power(self.shrink_ratio, 2)) / polygon_shape.length - subject = [tuple(l) for l in text_polys[i]] + subject = [tuple(l) for l in polygon] padding = pyclipper.PyclipperOffset() padding.AddPath(subject, pyclipper.JT_ROUND, pyclipper.ET_CLOSEDPOLYGON) - shrinked = padding.Execute(-distance) + shrinked = [] + + # Increase the shrink ratio every time we get multiple polygon returned back + possible_ratios = np.arange(self.shrink_ratio, 1, self.shrink_ratio) + np.append(possible_ratios, 1) + # print(possible_ratios) + for ratio in possible_ratios: + # print(f"Change shrink ratio to {ratio}") + distance = polygon_shape.area * ( + 1 - np.power(ratio, 2)) / polygon_shape.length + shrinked = padding.Execute(-distance) + if len(shrinked) == 1: + break + if shrinked == []: cv2.fillPoly(mask, polygon.astype(np.int32)[np.newaxis, :, :], 0) ignore_tags[i] = True continue - shrinked = np.array(shrinked[0]).reshape(-1, 2) - cv2.fillPoly(gt, [shrinked.astype(np.int32)], 1) + + for each_shirnk in shrinked: + shirnk = np.array(each_shirnk).reshape(-1, 2) + cv2.fillPoly(gt, [shirnk.astype(np.int32)], 1) # cv2.fillPoly(gt[0], [shrinked.astype(np.int32)], 1) data['shrink_map'] = gt @@ -91,4 +104,4 @@ class MakeShrinkMap(object): edge += (polygon[next_index, 0] - polygon[i, 0]) * ( polygon[next_index, 1] - polygon[i, 1]) - return edge / 2. + return edge / 2. \ No newline at end of file