annotate scripts/polytracktopdtv.py @ 1226:d478d3122804

change of bicycle to cyclist
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 12 Jul 2023 12:12:37 -0400
parents cc5cb04b04b0
children 5654c9173548
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
998
933670761a57 updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
1 #! /usr/bin/env python3
404
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 403
diff changeset
2
1028
cc5cb04b04b0 major update using the trafficintelligence package name and install through pip
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 998
diff changeset
3 import sys, os, datetime, argparse
cc5cb04b04b0 major update using the trafficintelligence package name and install through pip
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 998
diff changeset
4 import shutil, sqlite3, zipfile
cc5cb04b04b0 major update using the trafficintelligence package name and install through pip
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 998
diff changeset
5
cc5cb04b04b0 major update using the trafficintelligence package name and install through pip
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 998
diff changeset
6 import cv2
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
7 from pdtv import TsaiCamera, ZipVideo, SyncedVideos, TrackSet, Track, State
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
8
1028
cc5cb04b04b0 major update using the trafficintelligence package name and install through pip
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 998
diff changeset
9 from trafficintelligence import utils, cvutils
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
10
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
11 def zipFolder(inputFolder, outputFile):
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
12 '''Method to compress the content of the inputFolder in the outputFile'''
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
13 zip = zipfile.ZipFile(outputFile, 'w')
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
14 for root, dirs, files in os.walk(inputFolder):
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
15 for file in files:
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
16 zip.write(root+file, file)
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
17 zip.close()
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
18
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
19
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
20
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
21
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
22 def getTypeDict(cursor):
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
23 '''Return a dictionnary with integer key and associated type string
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
24 i.e.: "0" -> "unknown"
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
25 "1" -> "car"
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
26 "2" -> "pedestrians"
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
27 "3" -> "motorcycle"
1226
d478d3122804 change of bicycle to cyclist
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 1028
diff changeset
28 "4" -> "cyclist"
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
29 "5" -> "bus"
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
30 "6" -> "truck"
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
31 ... and other type if the objects_type table is defined in SQLite'''
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
32 typeDict = dict()
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
33 cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='objects_type'")
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
34 data = cursor.fetchone()
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
35
636
3058e00887bc removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 404
diff changeset
36 if(data is None):
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
37 typeDict["0"] = "unknown"
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
38 typeDict["1"] = "car"
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
39 typeDict["2"] = "pedestrians"
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
40 typeDict["3"] = "motorcycle"
1226
d478d3122804 change of bicycle to cyclist
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 1028
diff changeset
41 typeDict["4"] = "cyclist"
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
42 typeDict["5"] = "bus"
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
43 typeDict["6"] = "truck"
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
44
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
45 else:
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
46 cursor.execute("SELECT road_user_type, type_string FROM objects_type")
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
47 for row in cursor:
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
48 typeDict[row[0]]= row[1]
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
49
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
50 return typeDict
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
51
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
52 def extractFrames(videoFile, framePath, fps, time, firstFrameNum = 0, lastFrameNum = None):
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
53 '''Method to extract all the frames of the video'''
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
54 print('Extracting frame')
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
55 deltaTimestamp = 1000.0/float(fps);
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
56 time+=datetime.timedelta(microseconds=firstFrameNum*deltaTimestamp*1000)
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
57
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
58 inc = 1000 #How many frame we fetch in the video at a time
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
59
636
3058e00887bc removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 404
diff changeset
60 if lastFrameNum is not None:
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
61 delta = lastFrameNum-firstFrameNum
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
62 if delta < inc:
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
63 inc = delta
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
64
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
65 currentIdx = firstFrameNum
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
66 frameList = cvutils.getImagesFromVideo(videoFile, firstFrameNum = currentIdx, nFrames = inc)
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
67
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
68 while len(frameList) == inc and inc > 0:
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
69 for f in frameList:
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
70 cv2.imwrite(os.path.join(framePath,time.strftime("%Y%m%d-%H%M%S.%f")[:-3]+'.jpg'), f)
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
71 time += datetime.timedelta(microseconds=deltaTimestamp*1000)
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
72 currentIdx = currentIdx + inc
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
73
636
3058e00887bc removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 404
diff changeset
74 if lastFrameNum is not None:
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
75 delta = lastFrameNum-currentIdx
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
76 if delta < inc:
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
77 inc = delta
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
78 if inc:
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
79 frameList = cvutils.getImagesFromVideo(videoFile, firstFrameNum = currentIdx, nFrames = inc)
998
933670761a57 updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
80 print('Extracting frame {}'.format(currentIdx))
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
81 return len(frameList) > 0
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
82
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
83
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
84
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
85 def convertDatabase(workDirname, sectionName, sceneFilename = None, databaseFilename = None, videoFilename = None, videoFolderExist = False, firstFrameNum = 0, lastFrameNum = None, cameraCalibrationFilename = None, outputFileName = 'roaduser.json'):
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
86 '''
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
87 Method to convert database from polytrack to PDTV:
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
88 workDirname is the current working directory
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
89 sceneFilename is the path to the .cfg file
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
90 sectionName is the name of the section we want to process in this file
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
91 videoFolderExist specifiy if we want to reextract the video frame or if they already exist at workdir/videoframes/
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
92 firstFrameNum is the first frame we want to extract
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
93 lastFrameNum is the last frame we want to extract (or None if we want to extract everything)
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
94 '''
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
95 error = False
636
3058e00887bc removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 404
diff changeset
96 if sceneFilename is not None:
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
97 scene = utils.SceneParameters.loadConfigFile(os.path.join(workDirname, sceneFilename))
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
98 time = scene[sectionName].date
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
99 inputDb = os.path.join(workDirname, scene[sectionName].databaseFilename)
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
100 videoFile = os.path.join(workDirname, scene[sectionName].videoFilename)
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
101
636
3058e00887bc removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 404
diff changeset
102 if databaseFilename is not None:
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
103 inputDb = os.path.join(workDirname, databaseFilename)
636
3058e00887bc removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 404
diff changeset
104 if videoFilename is not None:
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
105 videoFile = os.path.join(workDirname, videoFilename)
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
106 # elif videoFolderExist == False:
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
107 # print('No video path specified')
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
108 # error = True
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
109
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
110 videoFolderPath = os.path.join(workDirname, "videoframes/")
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
111 fileName = sectionName
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
112
636
3058e00887bc removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 404
diff changeset
113 if videoFile is not None:
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
114 fps = cvutils.getFPS(videoFile)
998
933670761a57 updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
115 print('Video should run at {} fps'.format(fps))
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
116 deltaTimestamp = 1000.0/float(fps);
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
117 if videoFolderExist == False:
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
118 if os.path.exists(videoFolderPath):
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
119 shutil.rmtree(videoFolderPath)
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
120 utils.mkdir(videoFolderPath)
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
121 if extractFrames(videoFile, videoFolderPath, fps, time, firstFrameNum, lastFrameNum) == 0:
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
122 print("Error. Frame were not extracted")
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
123 error = True
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
124
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
125
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
126 if not error:
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
127 masterTimestamp = 0.0
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
128 masterTimestampList = list()
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
129 video_timestringsList = list()
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
130 frameNumberToMasterTimestamp = dict()
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
131 for r,d,f in os.walk(videoFolderPath):
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
132 i = firstFrameNum
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
133 for files in f:
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
134 name, ext = os.path.splitext(files)
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
135 video_timestringsList.append(name)
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
136 masterTimestampList.append(masterTimestamp)
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
137 frameNumberToMasterTimestamp[i] = masterTimestamp
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
138 i = i +1
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
139 masterTimestamp = masterTimestamp+deltaTimestamp
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
140
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
141 inputZipVideoName = fileName+".zip"
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
142 print('Zipping files...')
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
143 if not os.path.exists(inputZipVideoName) or not videoFolderExist:
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
144 zipFolder(videoFolderPath, inputZipVideoName)
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
145 print('Zipping files...Done.')
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
146 #We generate the structure for ZipVideo
636
3058e00887bc removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 404
diff changeset
147 if cameraCalibrationFilename is not None:
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
148 calibrationFile = cameraCalibrationFilename
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
149 else:
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
150 calibrationFile = 'calib.json'
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
151 zipVideo = ZipVideo(video_zip_file=inputZipVideoName,
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
152 time_offset=0.0, time_scale=1.0, master_timestamps=masterTimestampList, calibration_file=calibrationFile)
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
153 zipVideo.save(os.path.join(workDirname, 'video.json'))
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
154
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
155 print('ZipVideo saved')
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
156 obj = SyncedVideos(master_timestamps = [masterTimestamp],
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
157 video_timestrings = [video_timestringsList],
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
158 video_files = ['video.json'],
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
159 fps=fps)
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
160 obj.save(os.path.join(workDirname, 'syncedvideo.json'))
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
161
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
162 print('SyncedVideos saved')
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
163
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
164 print('Opening db')
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
165 connection = sqlite3.connect(inputDb)
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
166 cursor = connection.cursor()
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
167
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
168
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
169 #Tracket database
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
170 trackset = TrackSet(synced_file = ['syncedvideo.json'])
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
171
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
172
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
173 #1) We build the type index dictionnary
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
174 typeDict = getTypeDict(cursor)
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
175
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
176 idToTrackDict = dict()
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
177 #2) We read the object database
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
178 cursor.execute("SELECT object_id, road_user_type FROM objects")
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
179 for row in cursor:
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
180 objectId = row[0]
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
181 objectType = row[1]
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
182 t = Track(type=typeDict.get(objectType, "unknown"))
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
183 idToTrackDict[objectId] = t;
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
184 trackset.append(t)
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
185 print('Reading boundingbox table')
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
186 #3) We read the bounding box table
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
187 cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='bounding_boxes'")
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
188 data = cursor.fetchone()
636
3058e00887bc removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 404
diff changeset
189 if data is None:
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
190 print('No bounding box table. Maybe it was not generated ?')
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
191 else:
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
192 cursor.execute("SELECT object_id, frame_number, x_top_left, y_top_left, x_bottom_right, y_bottom_right FROM bounding_boxes")
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
193 for row in cursor:
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
194 objectId = row[0]
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
195 frameNumber = row[1]
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
196 x_top_left = row[2]
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
197 y_top_left = row[3]
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
198 x_bottom_right = row[4]
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
199 y_bottom_right = row[5]
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
200
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
201 idToTrackDict[objectId].append(State(frame=int(frameNumber), world_position = [0.,0.],
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
202 master_timestamp=frameNumberToMasterTimestamp[int(frameNumber)],
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
203 bounding_boxes=[[(x_top_left, x_bottom_right), (y_top_left, y_bottom_right)]]))
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
204 print('Saving db in json')
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
205 trackset.save(os.path.join(workDirname, outputFileName))
402
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
206 connection.close()
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
207 print('Done.')
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
208
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
209
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
210
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
211
f29204e68aab function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
212 if __name__ == "__main__":
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
213 parser = argparse.ArgumentParser(description='The program convert polytrack.sqlite database to pdtv bounding boxes', epilog = 'Either the configuration filename or the other parameters (at least video and database filenames) need to be provided.')
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
214 parser.add_argument('-w', dest = 'workDirname', help = 'use a different work directory', default = "./",type = str)
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
215 parser.add_argument('--scene', dest = 'sceneFilename', help = 'name of the configuration file', type = str, default = None)
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
216 parser.add_argument('--section', dest = 'sectionName', help = 'name of the section', type = str, default = None)
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
217 parser.add_argument('-d', dest = 'databaseFilename', help = 'name of the Sqlite database file', type = str, default = None)
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
218 parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file', type = str, default = None)
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
219 parser.add_argument('-c', dest = 'cameraCalibrationFilename', help = 'name of the camera json file', type = str, default = None)
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
220 parser.add_argument('-o', dest = 'outputFilename', help = 'name of the output json file', type = str, default = 'roaduser.json')
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
221 parser.add_argument('-s', dest = 'firstFrameNum', help = 'forced start frame', type = int, default = 0)
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
222 parser.add_argument('-e', dest = 'lastFrameNum', help = 'forced end frame', type = int, default = None)
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
223 #parser.add_argument('-t', dest = 'useDatabaseTimestamp', help = 'use the timestamp of the database', default= False, type = bool)
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
224 parser.add_argument('-u', dest = 'useCurrentVideoFile', help = 'use the previously generated video file', action = 'store_true')
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
225 args = parser.parse_args()
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
226 #convertDatabase(args)
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
227
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
228 convertDatabase(args.workDirname, args.sectionName, args.sceneFilename, videoFilename = args.videoFilename, databaseFilename = args.databaseFilename, videoFolderExist = args.useCurrentVideoFile, firstFrameNum = args.firstFrameNum, lastFrameNum = args.lastFrameNum, cameraCalibrationFilename = args.cameraCalibrationFilename, outputFileName=args.outputFilename )