~/dataset/flir_dataset/FLIR_ADAS_1_3/train$ cat 1028.py
import json
js_file = './thermal_annotations.json'
CLASS_NAME_MAP = { 1:'person', 2:'bicycle', 3: 'car', 4:'motorcycle', 5:'airplane' ,
17: 'dog'}
with open(js_file,'r') as f:
js = json.load(f)
#print(label)
label_info = js['info']
print(label_info)
for annotation in js["annotations"]:
print(annotation)
image_id = annotation['image_id']
print("image_id is {:0>5d}".format(image_id))
class_name = CLASS_NAME_MAP[annotation['category_id']]
#print("map_id is {}".format(CLASS_NAME_MAP[1]))
print("class_name is {}".format(class_name))
kitti_file = './label/' + str(image_id + 1).zfill(5) + '.txt'
with open(kitti_file, 'a') as kf:
kf.write(class_name)
kf.write(" ")
kf.write("0.00 0 0.00 ")
#class_id = annotation['category_id']
#print("class_id is {}".format(class_id))
seg = annotation['segmentation']
#print(seg[0])
bbox = "-".join( repr(e) for e in seg[0])
print(bbox)
xmin = bbox.split('-')[0]
ymin = bbox.split('-')[1]
xmax = bbox.split('-')[4]
ymax = bbox.split('-')[5]
with open(kitti_file, 'a') as kf:
kf.write(xmin + ' ')
kf.write(ymin + ' ')
kf.write(xmax + ' ')
kf.write(ymax + ' ')
kf.write("0.00 0.00 0.00 0.00 0.00 0.00 0.00\n")
if (image_id > 3):
break