@@ -80,13 +80,13 @@ def create_mask(image=None, annotations=None, label_map=None, include_img = Fals
8080 269
8181 ],
8282 "area": 56759,
83- "segmentation": [
83+ "segmentation": [[
8484 470,
8585 387,
8686 541,
8787 394,
8888 599,
89- 370
89+ 370]
9090 ],
9191 "iscrowd": 0
9292 }
@@ -98,11 +98,15 @@ def create_mask(image=None, annotations=None, label_map=None, include_img = Fals
9898 for annotation in annotations :
9999 if mask_type == 'polygon' :
100100 segmentation = annotation ['segmentation' ]
101- segmentation = np .array (segmentation ).reshape (- 1 , 2 )
102- segmentation = segmentation .astype (np .int32 )
103- cv2 .fillPoly (mask , [segmentation ], color = random_colors_palette [annotation ['category_id' ]].tolist ())
101+ for polygon in segmentation :
102+ polygon = np .array (polygon ).reshape (- 1 , 2 )
103+ polygon = polygon .astype (np .int32 )
104+ cv2 .fillPoly (mask , [polygon ], color = random_colors_palette [annotation ['category_id' ]].tolist ())
104105 label = label_map [annotation ['category_id' ]]
105- cv2 .putText (mask , label , (segmentation [0 ][0 ], segmentation [0 ][1 ]), cv2 .FONT_HERSHEY_SIMPLEX , 1 , (255 , 255 , 255 ), 2 )
106+ bbox = annotation ['bbox' ]
107+ x , y , w , h = bbox
108+ cv2 .rectangle (mask , (x , y ), (x + w , y + h ), random_colors_palette [annotation ['category_id' ]].tolist (), 2 )
109+ cv2 .putText (mask , label , (x , y ), cv2 .FONT_HERSHEY_SIMPLEX , 1 , (255 , 255 , 255 ), 2 )
106110 elif mask_type == 'bbox' :
107111 bbox = annotation ['bbox' ]
108112 x , y , w , h = bbox
0 commit comments