Mercurial Hosting > traffic-intelligence
comparison scripts/merge-features.py @ 998:933670761a57
updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Sun, 27 May 2018 23:22:48 -0400 |
parents | 668a85c963c3 |
children | cc5cb04b04b0 |
comparison
equal
deleted
inserted
replaced
997:4f3387a242a1 | 998:933670761a57 |
---|---|
1 #! /usr/bin/env python | 1 #! /usr/bin/env python3 |
2 | 2 |
3 import sys, argparse, os.path, sqlite3 | 3 import sys, argparse, os.path, sqlite3 |
4 import cvutils, utils, moving, storage | 4 import cvutils, utils, moving, storage |
5 from metadata import connectDatabase, Site, VideoSequence, CameraView, getSite | 5 from metadata import connectDatabase, Site, VideoSequence, CameraView, getSite |
6 from datetime import datetime, timedelta | 6 from datetime import datetime, timedelta |
38 timeIntervals = {} | 38 timeIntervals = {} |
39 for cv in videoSequences: | 39 for cv in videoSequences: |
40 timeIntervals[cv] = moving.TimeInterval.unionIntervals([v.getTimeInterval() for v in videoSequences[cv]]) | 40 timeIntervals[cv] = moving.TimeInterval.unionIntervals([v.getTimeInterval() for v in videoSequences[cv]]) |
41 | 41 |
42 # intersection of the time interval (union) for each camera view | 42 # intersection of the time interval (union) for each camera view |
43 commonTimeInterval = timeIntervals.values()[0] | 43 commonTimeInterval = list(timeIntervals.values())[0] |
44 for inter in timeIntervals.values()[1:]: | 44 for inter in timeIntervals.values()[1:]: |
45 commonTimeInterval = moving.TimeInterval.intersection(commonTimeInterval, inter) | 45 commonTimeInterval = moving.TimeInterval.intersection(commonTimeInterval, inter) |
46 commonTimeInterval = moving.TimeInterval.intersection(commonTimeInterval, processInterval) | 46 commonTimeInterval = moving.TimeInterval.intersection(commonTimeInterval, processInterval) |
47 | 47 |
48 if commonTimeInterval.empty(): | 48 if commonTimeInterval.empty(): |
69 if len(dirname) == 0: | 69 if len(dirname) == 0: |
70 dirname = '.' | 70 dirname = '.' |
71 | 71 |
72 newTrajectoryId = -1 | 72 newTrajectoryId = -1 |
73 # first frame num is commonTimeInterval | 73 # first frame num is commonTimeInterval |
74 for cv, vs in videoSequences.iteritems(): | 74 for cv, vs in videoSequences.items(): |
75 print cv.idx, cv.description | 75 print(cv.idx, cv.description) |
76 for videoSequence in vs: | 76 for videoSequence in vs: |
77 try: | 77 try: |
78 vsConnection = sqlite3.connect(dirname+os.path.sep+videoSequence.getDatabaseFilename()) | 78 vsConnection = sqlite3.connect(dirname+os.path.sep+videoSequence.getDatabaseFilename()) |
79 vsCursor = vsConnection.cursor() | 79 vsCursor = vsConnection.cursor() |
80 firstFrameNum = utils.deltaFrames(videoSequence.startTime, commonTimeInterval.first, frameRate) | 80 firstFrameNum = utils.deltaFrames(videoSequence.startTime, commonTimeInterval.first, frameRate) |
91 outCursor.execute(storage.insertTrajectoryQuery('positions'), (newTrajectoryId, row[1]-firstFrameNum, row[2], row[3])) | 91 outCursor.execute(storage.insertTrajectoryQuery('positions'), (newTrajectoryId, row[1]-firstFrameNum, row[2], row[3])) |
92 # velocities table | 92 # velocities table |
93 for row in vsCursor: | 93 for row in vsCursor: |
94 outCursor.execute(storage.insertTrajectoryQuery('velocities'), (featureIdCorrespondences[row[0]], row[1]-firstFrameNum, row[2], row[3])) | 94 outCursor.execute(storage.insertTrajectoryQuery('velocities'), (featureIdCorrespondences[row[0]], row[1]-firstFrameNum, row[2], row[3])) |
95 # saving the id correspondences | 95 # saving the id correspondences |
96 for oldId, newId in featureIdCorrespondences.iteritems(): | 96 for oldId, newId in featureIdCorrespondences.items(): |
97 outCursor.execute("INSERT INTO feature_correspondences (trajectory_id, source_dbname, db_trajectory_id) VALUES ({},\"{}\",{})".format(newId, videoSequence.name, oldId)) | 97 outCursor.execute("INSERT INTO feature_correspondences (trajectory_id, source_dbname, db_trajectory_id) VALUES ({},\"{}\",{})".format(newId, videoSequence.name, oldId)) |
98 outConnection.commit() | 98 outConnection.commit() |
99 except sqlite3.OperationalError as error: | 99 except sqlite3.OperationalError as error: |
100 storage.printDBError(error) | 100 storage.printDBError(error) |
101 | 101 |