@@ -34,7 +34,7 @@ def range_limited_float_type_0_to_1(arg):
34
34
35
35
# Available classes for YOEO
36
36
CLASSES = {
37
- 'bb_classes' : ['ball' , 'goalpost' , 'robot' ] if args .robots_with_team_colors else ['ball' , 'goalpost' , 'robot_blue' , 'robot_red' , 'robot_unknown' ],
37
+ 'bb_classes' : ['ball' , 'goalpost' , 'robot' ] if not args .robots_with_team_colors else ['ball' , 'goalpost' , 'robot_blue' , 'robot_red' , 'robot_unknown' ],
38
38
'segmentation_classes' : ['background' , 'lines' , 'field' ],
39
39
'skip_classes' : ['obstacle' , 'L-Intersection' , 'X-Intersection' , 'T-Intersection' ],
40
40
}
@@ -122,8 +122,12 @@ def range_limited_float_type_0_to_1(arg):
122
122
annotations = []
123
123
124
124
for annotation in image_data ['annotations' ]:
125
- class_name = annotation ['type' ]
125
+ # Skip annotations that are not in the image
126
+ if not annotation ['in_image' ]:
127
+ continue
126
128
129
+ # Derive the class name of the current annotation
130
+ class_name = annotation ['type' ]
127
131
if args .robots_with_team_colors and class_name == 'robot' :
128
132
class_name += f"_{ annotation ['color' ]} "
129
133
@@ -134,25 +138,24 @@ def range_limited_float_type_0_to_1(arg):
134
138
(args .skip_concealed and annotation .get ('concealed' , False ))):
135
139
continue
136
140
elif class_name in CLASSES ['bb_classes' ]: # Handle bounding boxes
137
- if annotation ['in_image' ]: # If annotation is not in image, do nothing
138
- min_x = min (map (lambda x : x [0 ], annotation ['vector' ]))
139
- max_x = max (map (lambda x : x [0 ], annotation ['vector' ]))
140
- min_y = min (map (lambda x : x [1 ], annotation ['vector' ]))
141
- max_y = max (map (lambda x : x [1 ], annotation ['vector' ]))
142
-
143
- annotation_width = max_x - min_x
144
- annotation_height = max_y - min_y
145
- relative_annotation_width = annotation_width / img_width
146
- relative_annotation_height = annotation_height / img_height
147
-
148
- center_x = min_x + (annotation_width / 2 )
149
- center_y = min_y + (annotation_height / 2 )
150
- relative_center_x = center_x / img_width
151
- relative_center_y = center_y / img_height
152
-
153
- # Derive classID from index in predefined classes
154
- classID = CLASSES ['bb_classes' ].index (class_name )
155
- annotations .append (f"{ classID } { relative_center_x } { relative_center_y } { relative_annotation_width } { relative_annotation_height } " )
141
+ min_x = min (map (lambda x : x [0 ], annotation ['vector' ]))
142
+ max_x = max (map (lambda x : x [0 ], annotation ['vector' ]))
143
+ min_y = min (map (lambda x : x [1 ], annotation ['vector' ]))
144
+ max_y = max (map (lambda x : x [1 ], annotation ['vector' ]))
145
+
146
+ annotation_width = max_x - min_x
147
+ annotation_height = max_y - min_y
148
+ relative_annotation_width = annotation_width / img_width
149
+ relative_annotation_height = annotation_height / img_height
150
+
151
+ center_x = min_x + (annotation_width / 2 )
152
+ center_y = min_y + (annotation_height / 2 )
153
+ relative_center_x = center_x / img_width
154
+ relative_center_y = center_y / img_height
155
+
156
+ # Derive classID from index in predefined classes
157
+ classID = CLASSES ['bb_classes' ].index (class_name )
158
+ annotations .append (f"{ classID } { relative_center_x } { relative_center_y } { relative_annotation_width } { relative_annotation_height } " )
156
159
else :
157
160
print (f"The annotation type '{ class_name } ' is not supported. Image: '{ img_name_with_extension } '" )
158
161
0 commit comments