annotate scripts/polytracktopdtv.py @ 998:933670761a57

updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Sun, 27 May 2018 23:22:48 -0400
parents 3058e00887bc
children cc5cb04b04b0
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
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
3 from pdtv import TsaiCamera, ZipVideo, SyncedVideos, TrackSet, Track, State
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
4 import sys, os, datetime, argparse
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
5 import shutil
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
6 import sqlite3
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 import zipfile
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 import utils
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
9 import cvutils
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 import cv2
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
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
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 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
14 '''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
15 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
16 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
17 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
18 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
19 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
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
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
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 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
25 '''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
26 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
27 "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
28 "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
29 "3" -> "motorcycle"
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 "4" -> "bicycle"
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 "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
32 "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
33 ... 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
34 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
35 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
36 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
37
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
38 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
39 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
40 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
41 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
42 typeDict["3"] = "motorcycle"
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["4"] = "bicycle"
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 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
45 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
46
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 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
48 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
49 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
50 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
51
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
52 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
53
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
54 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
55 '''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
56 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
57 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
58 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
59
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
60 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
61
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
62 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
63 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
64 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
65 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
66
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
67 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
68 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
69
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 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
71 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
72 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
73 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
74 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
75
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
76 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
77 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
78 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
79 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
80 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
81 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
82 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
83 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
84
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
85
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
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
87 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
88 '''
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 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
90 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
91 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
92 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
93 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
94 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
95 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
96 '''
403
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
97 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
98 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
99 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
100 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
101 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
102 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
103
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 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
105 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
106 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
107 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
108 # 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
109 # 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
110 # 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
111
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 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
113 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
114
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
115 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
116 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
117 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
118 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
119 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
120 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
121 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
122 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
123 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
124 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
125 error = True
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
126
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
127
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 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
129 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
130 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
131 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
132 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
133 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
134 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
135 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
136 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
137 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
138 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
139 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
140 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
141 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
142
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 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
144 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
145 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
146 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
147 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
148 #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
149 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
150 calibrationFile = cameraCalibrationFilename
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
151 else:
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
152 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
153 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
154 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
155 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
156
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 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
158 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
159 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
160 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
161 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
162 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
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('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
165
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 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
167 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
168 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
169
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
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 #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
172 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
173
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
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 #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
176 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
177
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 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
179 #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
180 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
181 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
182 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
183 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
184 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
185 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
186 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
187 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
188 #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
189 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
190 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
191 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
192 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
193 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
194 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
195 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
196 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
197 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
198 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
199 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
200 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
201 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
202
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 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
204 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
205 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
206 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
207 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
208 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
209 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
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
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
213
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
214 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
215 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
216 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
217 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
218 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
219 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
220 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
221 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
222 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
223 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
224 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
225 #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
226 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
227 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
228 #convertDatabase(args)
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
229
f3938bb6da7f added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 402
diff changeset
230 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 )