@@ -33,15 +33,13 @@ def vector_to_coco_segment_info(canvas: np.ndarray,
33
33
bbox = [xmin , ymin , xmax - xmin , ymax - ymin ])
34
34
35
35
36
- def mask_to_coco_segment_info (canvas : np .ndarray , annotation , category_id ):
37
- # Expects a unique color for each class....
38
- # Also there is a possible conflict with vector classes being draw. TODO: Use ID instead
39
- mask = annotation .value .draw ()
36
+ def mask_to_coco_segment_info (canvas : np .ndarray , annotation , annotation_idx : int , category_id ):
37
+ color = id_to_rgb (annotation_idx )
38
+ mask = annotation .value .draw (color = color )
40
39
shapely = annotation .value .shapely
41
40
xmin , ymin , xmax , ymax = shapely .bounds
42
41
canvas = np .where (canvas == (0 , 0 , 0 ), mask , canvas )
43
- id = rgb_to_id (* annotation .value .color )
44
- return SegmentInfo (id = id ,
42
+ return SegmentInfo (id = annotation_idx ,
45
43
category_id = category_id ,
46
44
area = shapely .area ,
47
45
bbox = [xmin , ymin , xmax - xmin , ymax - ymin ]), canvas
@@ -66,7 +64,7 @@ def process_label(label: Label, idx: Union[int, str], image_root, mask_root, all
66
64
categories [annotation .name ] = hash_category_name (annotation .name )
67
65
if isinstance (annotation .value , Mask ):
68
66
segment , canvas = (mask_to_coco_segment_info (
69
- canvas , annotation , categories [annotation .name ]))
67
+ canvas , annotation , class_idx , categories [annotation .name ]))
70
68
segments .append (segment )
71
69
is_thing [annotation .name ] = 0
72
70
@@ -79,7 +77,6 @@ def process_label(label: Label, idx: Union[int, str], image_root, mask_root, all
79
77
image = image ,
80
78
category_id = categories [annotation .name ]))
81
79
is_thing [annotation .name ] = 1 - int (all_stuff )
82
- # TODO: Report on unconverted annotations.
83
80
84
81
mask_file = image .file_name .replace ('.jpg' , '.png' )
85
82
mask_file = os .path .join (mask_root , mask_file )
0 commit comments