From 0cbad076518b67b9a6df58b712e81a2433f243e2 Mon Sep 17 00:00:00 2001 From: healthonrails Date: Tue, 12 Mar 2024 08:35:46 -0400 Subject: [PATCH] Check and only convert valid polygon with at least 3 points to mask --- annolid/segmentation/SAM/edge_sam_bg.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/annolid/segmentation/SAM/edge_sam_bg.py b/annolid/segmentation/SAM/edge_sam_bg.py index 1f8830a..703bdfa 100644 --- a/annolid/segmentation/SAM/edge_sam_bg.py +++ b/annolid/segmentation/SAM/edge_sam_bg.py @@ -209,6 +209,9 @@ def process_video_with_cutite(self, frames_to_propagate=100, frame_number = int( Path(self.most_recent_file).stem.split('_')[-1]) shapes = self.load_shapes(self.most_recent_file) + shapes = [shape for shape in shapes if len(shape["points"]) >= 3] + if len(shapes) < 1: + return f"No valid polygon found in this frame; requires a minimum of 3 points #{frame_number} " for shape in sorted(shapes, key=lambda x: x["label"]): label_name = shape["label"] if label_name in label_name_to_value: