From 0f889935fdf07e2c8429b373872815effacece96 Mon Sep 17 00:00:00 2001 From: Shubham Kanitkar Date: Mon, 21 Aug 2023 16:38:30 -0700 Subject: [PATCH] filtering out invalid point key --- supervision/detection/utils.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/supervision/detection/utils.py b/supervision/detection/utils.py index a3229650..7e8a4ee9 100644 --- a/supervision/detection/utils.py +++ b/supervision/detection/utils.py @@ -21,9 +21,7 @@ def polygon_to_mask(polygon: np.ndarray, resolution_wh: Tuple[int, int]) -> np.n width, height = resolution_wh mask = np.zeros((height, width)) - # Empty numpy array check - if np.any(polygon): - cv2.fillPoly(mask, [polygon], color=1) + cv2.fillPoly(mask, [polygon], color=1) return mask @@ -364,12 +362,13 @@ def process_roboflow_result( if "points" not in prediction: continue - polygon = np.array( - [[point["x"], point["y"]] for point in prediction["points"]], dtype=int - ) + if len(prediction["points"]) >= 3: + polygon = np.array( + [[point["x"], point["y"]] for point in prediction["points"]], dtype=int + ) - mask = polygon_to_mask(polygon, resolution_wh=(image_width, image_height)) - masks.append(mask) + mask = polygon_to_mask(polygon, resolution_wh=(image_width, image_height)) + masks.append(mask) xyxy = np.array(xyxy) confidence = np.array(confidence)