dump coco format json and write KITTI format file ( nightowls person night )
# cat nightowlsapi/python/load_validation_data_demo.py
import random
import os
from os import path
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import matplotlib.patches as patches
from coco import COCO
# Ground truth
annFile = '../../nightowls_validation.json'
#image_directory = '/nightowls/images'
target_label_path = "./labels"
cocoGt = COCO(annFile)
print(cocoGt)
imgIds = sorted(cocoGt.getImgIds())
print('There are %d images in the validation set' % len(imgIds))
#annotations is a list which contain all the AnnIds
annotations = cocoGt.getAnnIds()
print('There are %d annotations in the validation set' % len(annotations))
# Select random annotation
for i in range(len(annotations)):
anno_id = annotations[i]
anno = cocoGt.loadAnns(ids=anno_id)[0]
print('Annotation (id=%d): %s' % (anno_id, anno))
cat = cocoGt.loadCats(ids=anno['category_id'])[0]
category_name = cat['name']
print('Object type %s' % category_name)
if (category_name == "pedestrian"):
class_name = "person"
else:
continue
# Show the annotation in its image
#print(cocoGt.loadImgs(ids=anno['image_id']))
image = cocoGt.loadImgs(ids=anno['image_id'])[0]
file_name = image['file_name']
#file_path = path.join(image_directory, image['file_name'])
#print("file_name is {}".format(file_name))
bbox = anno['bbox']
x1 = bbox[0]
y1 = bbox[1]
x2 = bbox[0] + bbox[2]
y2 = bbox[1] + bbox[3]
label_file = file_name.replace(".png",".txt")
if not os.path.exists(target_label_path):
os.makedirs(target_label_path)
label_file = os.path.join(target_label_path, label_file)
print("label_file is {}".format(label_file))
with open(label_file, "a") as f:
f.write("{} 0.0 0 0.0 {:.2f} {:.2f} {:.2f} {:.2f} 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n".format(class_name, x1, y1, x2, y2))
https://github.com/ivclab/Day_Night_dataset_list
https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=6224623
https://www.nightowls-dataset.org/about/
https://www.nightowls-dataset.org/examples/
https://www.nightowls-dataset.org/download/
https://gitlab.com/vgg/nightowlsapi/-/tree/master
Check basic info for the dataset
# cat load_validation_data_demo_just_show_info.py
import random
from os import path
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import matplotlib.patches as patches
from coco import COCO
# Ground truth
annFile = '../../nightowls_validation.json'
#annFile = '../../nightowls_training.json'
#image_directory = '/nightowls/images'
cocoGt = COCO(annFile)
print(cocoGt)
imgIds = sorted(cocoGt.getImgIds())
print('There are %d images in the validation set' % len(imgIds))
annotations = cocoGt.getAnnIds()
print('There are %d annotations in the validation set' % len(annotations))
# Select random annotation
anno_id = annotations[random.randint(0, len(annotations))]
anno = cocoGt.loadAnns(ids=anno_id)[0]
print('Annotation (id=%d): %s' % (anno_id, anno))
cat = cocoGt.loadCats(ids=anno['category_id'])[0]
category_name = cat['name']
print('Object type %s' % category_name)
# Show the annotation in its image
print(cocoGt.loadImgs(ids=anno['image_id']))
image = cocoGt.loadImgs(ids=anno['image_id'])[0]
file_name = image['file_name']
#file_path = path.join(image_directory, image['file_name'])
print("file_name is {}".format(file_name))
'''
fig,ax = plt.subplots(1)
img=mpimg.imread(file_path)
ax.imshow(img)
'''
bbox = anno['bbox']
print(bbox)
'''
rect = patches.Rectangle((bbox[0],bbox[1]),bbox[2],bbox[3],linewidth=2,edgecolor='g',facecolor='none')
ax.add_patch(rect)
plt.show()
'''
浙公网安备 33010602011771号