diff 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
line wrap: on
line diff
--- a/scripts/merge-features.py	Fri May 25 18:15:18 2018 -0400
+++ b/scripts/merge-features.py	Sun May 27 23:22:48 2018 -0400
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
 
 import sys, argparse, os.path, sqlite3
 import cvutils, utils, moving, storage
@@ -40,7 +40,7 @@
     timeIntervals[cv] = moving.TimeInterval.unionIntervals([v.getTimeInterval() for v in videoSequences[cv]])
 
 # intersection of the time interval (union) for each camera view
-commonTimeInterval = timeIntervals.values()[0]
+commonTimeInterval = list(timeIntervals.values())[0]
 for inter in timeIntervals.values()[1:]:
     commonTimeInterval = moving.TimeInterval.intersection(commonTimeInterval, inter)
 commonTimeInterval = moving.TimeInterval.intersection(commonTimeInterval, processInterval)
@@ -71,8 +71,8 @@
 
 newTrajectoryId = -1
 # first frame num is commonTimeInterval
-for cv, vs in videoSequences.iteritems():
-    print cv.idx, cv.description
+for cv, vs in videoSequences.items():
+    print(cv.idx, cv.description)
     for videoSequence in vs:
         try:
             vsConnection = sqlite3.connect(dirname+os.path.sep+videoSequence.getDatabaseFilename())
@@ -93,7 +93,7 @@
             for row in vsCursor:
                 outCursor.execute(storage.insertTrajectoryQuery('velocities'), (featureIdCorrespondences[row[0]], row[1]-firstFrameNum, row[2], row[3]))
             # saving the id correspondences
-            for oldId, newId in featureIdCorrespondences.iteritems():
+            for oldId, newId in featureIdCorrespondences.items():
                 outCursor.execute("INSERT INTO feature_correspondences (trajectory_id, source_dbname, db_trajectory_id) VALUES ({},\"{}\",{})".format(newId, videoSequence.name, oldId))
             outConnection.commit()
         except sqlite3.OperationalError as error: