From d8e615921d8e020f5f422a84be7fd8d3db53d8e0 Mon Sep 17 00:00:00 2001 From: Tong Gao Date: Wed, 8 Feb 2023 10:36:11 +0800 Subject: [PATCH] [Fix] Detect intersection before using shapley.intersection to eliminate spurious warnings (#1710) * [Fix] Detect intersection before using shapley.intersection to eliminate spurious warnings * Update polygon_utils.py --- mmocr/utils/polygon_utils.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mmocr/utils/polygon_utils.py b/mmocr/utils/polygon_utils.py index 0ae4ed65..4a103ca4 100644 --- a/mmocr/utils/polygon_utils.py +++ b/mmocr/utils/polygon_utils.py @@ -212,9 +212,8 @@ def poly_intersection(poly_a: Polygon, float or tuple(float, Polygon): Returns the intersection area or a tuple ``(area, Optional[poly_obj])``, where the `area` is the intersection area between two polygons and `poly_obj` is The Polygon - object of the intersection area. Set as `None` if the input is invalid. - Set as `None` if the input is invalid. `poly_obj` will be returned - only if `return_poly` is `True`. + object of the intersection area, which will be `None` if the input is + invalid. `poly_obj` will be returned only if `return_poly` is `True`. """ assert isinstance(poly_a, Polygon) assert isinstance(poly_b, Polygon) @@ -227,8 +226,12 @@ def poly_intersection(poly_a: Polygon, poly_obj = None area = invalid_ret if poly_a.is_valid and poly_b.is_valid: - poly_obj = poly_a.intersection(poly_b) - area = poly_obj.area + if poly_a.intersects(poly_b): + poly_obj = poly_a.intersection(poly_b) + area = poly_obj.area + else: + poly_obj = Polygon() + area = 0.0 return (area, poly_obj) if return_poly else area