-
Notifications
You must be signed in to change notification settings - Fork 3
/
demo_kitti2csv.py
47 lines (32 loc) · 1.51 KB
/
demo_kitti2csv.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
42
43
44
45
46
47
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: Mads Dyrmann
"""
import kitti
import CSV
import os
CROPBBOXTOIMAGE = True
kittidir = '/mnt/AU_BrugerDrev/Database/GetThumbnailsFromServerForDetection_242_326_336_249_250_279_2018-05-22/LocalizationAnnotationsOnedir/KittiAnnotations'
exportdir = '/mnt/AU_BrugerDrev/Database/GetThumbnailsFromServerForDetection_242_326_336_249_250_279_2018-05-22/LocalizationAnnotationsOnedir/csvAnnotations'
annotationFiles = []
for root, dirnames, filenames in os.walk(kittidir):
for filename in filenames:
if filename.lower().endswith(('.txt')):
annotationFiles.append(os.path.join(root, filename))
def createIfNotExist(directory):
if not os.path.exists(directory):
os.makedirs(directory)
createIfNotExist(exportdir)
for annotationFile in annotationFiles:
kittianno=kitti.readAnnotationFile(annotationFile)
imagepathparts = annotationFile.split(os.path.sep)
imagepathparts[-2]='JPEGImages' #set image folder
imagepathparts[-1]=os.path.splitext(imagepathparts[-1])[-2] #remove extension
imagepathWithoutext=os.path.sep.join(imagepathparts) #construct imagepath without extension
imagesInDirectory = os.listdir(os.path.sep.join(imagepathparts[:-1]))
imagepathWithExtension =[x for x in imagesInDirectory if os.path.splitext(x)[0]==imagepathWithoutext]
AUanno = kitti.kitti2AU(kittianno,filename=annotationFile)
csvanno = CSV.AU2csv(AUanno)
CSV.csvlist2file(csvAnnotationList=csvanno,outputpath=exportdir)
pass