Skip to content

Commit

Permalink
fix: filter polygon objects according to their complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
Gorkem-Encord committed Aug 3, 2023
1 parent 2d6731e commit 3252a73
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/encord_active/lib/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from loguru import logger
from PIL import Image
from shapely.errors import ShapelyDeprecationWarning
from shapely.geometry import Polygon
from shapely.geometry import MultiPolygon, Polygon
from tqdm.auto import tqdm

from encord_active.lib.labels.object import BoxShapes, ObjectShape, SimpleShapes
Expand Down Expand Up @@ -160,8 +160,17 @@ def get_geometry_from_encord_object(obj: dict, w: int, h: int) -> Optional[np.nd
polygon = get_polygon(obj, force_simple_polygons=False)

if polygon:
polygon_buffered = polygon.buffer(0)
if isinstance(polygon_buffered, MultiPolygon):
if abs(polygon_buffered.area - polygon.area) < 1e-6:
final_polygon = polygon
else:
return None
else:
final_polygon = polygon_buffered

img_size = np.array([[w, h]])
return (np.array(polygon.exterior.xy).T * img_size).astype(int)
return (np.array(final_polygon.exterior.xy).T * img_size).astype(int)
else:
return None

Expand Down

0 comments on commit 3252a73

Please sign in to comment.