From 917606b4087b1122c0e39555edd7a0bc19ce8dd8 Mon Sep 17 00:00:00 2001 From: zhiminzhang0830 <452516515@qq.com> Date: Sun, 27 Feb 2022 11:31:33 +0800 Subject: [PATCH] modify poly_intersection --- ppocr/data/imaug/fce_aug.py | 2 +- ppocr/utils/poly_nms.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ppocr/data/imaug/fce_aug.py b/ppocr/data/imaug/fce_aug.py index 7ef00de3..66bafef1 100644 --- a/ppocr/data/imaug/fce_aug.py +++ b/ppocr/data/imaug/fce_aug.py @@ -133,7 +133,7 @@ class RandomCropFlip: fail_flag = False for polygon, ignore_tag in zip(polygons, ignore_tags): ppi = Polygon(polygon.reshape(-1, 2)) - ppiou, _ = poly_intersection(ppi, pp) + ppiou, _ = poly_intersection(ppi, pp, buffer=0) if np.abs(ppiou - float(ppi.area)) > self.epsilon and \ np.abs(ppiou) > self.epsilon: fail_flag = True diff --git a/ppocr/utils/poly_nms.py b/ppocr/utils/poly_nms.py index 31eb6642..9dcb3d2c 100644 --- a/ppocr/utils/poly_nms.py +++ b/ppocr/utils/poly_nms.py @@ -36,7 +36,7 @@ def points2polygon(points): return Polygon(point_mat) -def poly_intersection(poly_det, poly_gt): +def poly_intersection(poly_det, poly_gt, buffer=0.0001): """Calculate the intersection area between two polygon. Args: @@ -49,7 +49,10 @@ def poly_intersection(poly_det, poly_gt): assert isinstance(poly_det, Polygon) assert isinstance(poly_gt, Polygon) - poly_inter = poly_det.buffer(0.001) & poly_gt.buffer(0.001) + if buffer == 0: + poly_inter = poly_det & poly_gt + else: + poly_inter = poly_det.buffer(buffer) & poly_gt.buffer(buffer) return poly_inter.area, poly_inter -- GitLab