Skip to content

Commit 759f4f0

Browse files
committed
fix problem with annotation not in image
1 parent 0dbd5af commit 759f4f0

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

yoeo/scripts/createYOEOLabelsFromTORSO-21.py

+24-21
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def range_limited_float_type_0_to_1(arg):
3434

3535
# Available classes for YOEO
3636
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'],
3838
'segmentation_classes': ['background', 'lines', 'field'],
3939
'skip_classes': ['obstacle', 'L-Intersection', 'X-Intersection', 'T-Intersection'],
4040
}
@@ -122,8 +122,12 @@ def range_limited_float_type_0_to_1(arg):
122122
annotations = []
123123

124124
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
126128

129+
# Derive the class name of the current annotation
130+
class_name = annotation['type']
127131
if args.robots_with_team_colors and class_name == 'robot':
128132
class_name += f"_{annotation['color']}"
129133

@@ -134,25 +138,24 @@ def range_limited_float_type_0_to_1(arg):
134138
(args.skip_concealed and annotation.get('concealed', False))):
135139
continue
136140
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}")
156159
else:
157160
print(f"The annotation type '{class_name}' is not supported. Image: '{img_name_with_extension}'")
158161

0 commit comments

Comments
 (0)