Mercurial Hosting > traffic-intelligence
annotate scripts/polytracktopdtv.py @ 981:c3e690c5536e
corrected bug in display trajectories
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 27 Feb 2018 15:24:57 -0500 |
parents | 3058e00887bc |
children | 933670761a57 |
rev | line source |
---|---|
404 | 1 #! /usr/bin/env python |
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 |
f29204e68aab
function to 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 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
|
73 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
|
74 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
|
75 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
|
76 |
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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
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 |
f29204e68aab
function to 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 |
403
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
88 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
|
89 ''' |
f29204e68aab
function to 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 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 ''' |
403
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 |
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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 # 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
|
110 # 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
|
111 # 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
|
112 |
f29204e68aab
function to 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 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
|
114 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
|
115 |
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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 error = True |
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
127 |
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
|
128 |
f29204e68aab
function to 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 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 |
f29204e68aab
function to 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 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 #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
|
150 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
|
151 calibrationFile = cameraCalibrationFilename |
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
152 else: |
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
153 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
|
154 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
|
155 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
|
156 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
|
157 |
f29204e68aab
function to 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 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 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
|
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('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
|
166 |
f29204e68aab
function to 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 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
|
168 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
|
169 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
|
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 |
f29204e68aab
function to 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 #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
|
173 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
|
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 |
f29204e68aab
function to 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 #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
|
177 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
|
178 |
f29204e68aab
function to 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 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
|
180 #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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 #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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 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
|
202 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
|
203 |
f29204e68aab
function to 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 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
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 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
|
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 |
f29204e68aab
function to generate homography from PDTV Tsai format and script to generate trajectories from sqlite bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 #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
|
227 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
|
228 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
|
229 #convertDatabase(args) |
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
230 |
f3938bb6da7f
added commande line options to script to convert polytrack annotation data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
402
diff
changeset
|
231 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 ) |