forked from bosch-ros-pkg/bstld
-
Notifications
You must be signed in to change notification settings - Fork 7
/
read_label_file.py
41 lines (33 loc) · 1.24 KB
/
read_label_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
"""
Sample script to receive traffic light labels and images
of the Bosch Small Traffic Lights Dataset.
Example usage:
python read_label_file.py input_yaml
"""
import os
import sys
import yaml
def get_all_labels(input_yaml, riib=False):
""" Gets all labels within label file
Note that RGB images are 1280x720 and RIIB images are 1280x736.
:param input_yaml: Path to yaml file
:param riib: If True, change path to labeled pictures
:return: images: Labels for traffic lights
"""
images = yaml.load(open(input_yaml, 'rb').read())
for i in range(len(images)):
images[i]['path'] = os.path.abspath(os.path.join(os.path.dirname(input_yaml), images[i]['path']))
if riib:
images[i]['path'] = images[i]['path'].replace('.png', '.pgm')
images[i]['path'] = images[i]['path'].replace('rgb/train', 'riib/train')
images[i]['path'] = images[i]['path'].replace('rgb/test', 'riib/test')
for box in images[i]['boxes']:
box['y_max'] = box['y_max'] + 8
box['y_min'] = box['y_min'] + 8
return images
if __name__ == '__main__':
if len(sys.argv) < 2:
print(__doc__)
sys.exit(-1)
get_all_labels(sys.argv[1])