Mercurial Hosting > traffic-intelligence
annotate scripts/polytracktopdtv.py @ 403:f3938bb6da7f
added commande line options to script to convert polytrack annotation data
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 30 Jul 2013 19:45:03 -0400 |
parents | f29204e68aab |
children | 4dd68b0765b1 |
rev | line source |
---|---|
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
|
1 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
|
2 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
|
3 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
|
4 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
|
5 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
|
6 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
|
7 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
|
8 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
|
9 |
f29204e68aab
function to 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" |
f29204e68aab
function to 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 "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
|
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 |
f29204e68aab
function to 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 if(data == None): |
f29204e68aab
function to 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" |
f29204e68aab
function to 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["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
|
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 |
403
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
60 if lastFrameNum != None: |
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 |
f29204e68aab
function to 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 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
|
71 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
|
72 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
|
73 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
|
74 |
403
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
75 if lastFrameNum != None: |
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 print('Extracting frame ' + str(currentIdx)) |
f29204e68aab
function to 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 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
|
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 |
f29204e68aab
function to 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 |
403
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
86 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
|
87 ''' |
f29204e68aab
function to 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 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 ''' |
403
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
96 error = False |
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
97 if sceneFilename != None: |
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
98 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
|
99 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
|
100 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
|
101 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
|
102 |
f29204e68aab
function to 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 if databaseFilename != None: |
f29204e68aab
function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
104 inputDb = os.path.join(workDirname, databaseFilename) |
403
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
105 if videoFilename != None: |
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
106 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
|
107 # 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
|
108 # 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
|
109 # 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
|
110 |
f29204e68aab
function to 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 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
|
112 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
|
113 |
403
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
114 if videoFile != None: |
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
115 fps = cvutils.getFPS(videoFile) |
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
116 print('Video should run at ' + str(fps) + ' fps') |
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 error = True |
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
125 |
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
|
126 |
f29204e68aab
function to 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 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 |
f29204e68aab
function to 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 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 #We generate the structure for ZipVideo |
403
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
148 if cameraCalibrationFilename != None: |
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
149 calibrationFile = cameraCalibrationFilename |
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
150 else: |
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
151 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
|
152 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
|
153 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
|
154 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
|
155 |
f29204e68aab
function to 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 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 |
f29204e68aab
function to 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 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
|
164 |
f29204e68aab
function to 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 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
|
166 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
|
167 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
|
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 |
f29204e68aab
function to 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 #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
|
171 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
|
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 |
f29204e68aab
function to 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 #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
|
175 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
|
176 |
f29204e68aab
function to 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 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
|
178 #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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 #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
|
188 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
|
189 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
|
190 if data == None: |
f29204e68aab
function to 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 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 |
f29204e68aab
function to 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 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 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
|
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 |
f29204e68aab
function to 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 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 #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
|
225 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
|
226 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
|
227 #convertDatabase(args) |
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
228 |
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
229 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 ) |