changeset 836:7058a40a4bbc

updated metadata and code to merge features from different cameras
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 06 Jul 2016 10:18:35 -0400
parents f3ae72d86762
children e01cabca4c55
files python/metadata.py scripts/display-synced-trajectories.py scripts/merge-features.py
diffstat 3 files changed, 19 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/python/metadata.py	Tue Jul 05 13:56:13 2016 -0400
+++ b/python/metadata.py	Wed Jul 06 10:18:35 2016 -0400
@@ -164,17 +164,19 @@
     cameraTypeIdx = Column(Integer, ForeignKey('camera_types.idx'))
     trackingConfigurationFilename = Column(String) # path to configuration .cfg file, relative to site name
     maskFilename = Column(String) # path to mask file, relative to site name
+    virtual = Column(Boolean) # indicates it is not a real camera view, eg merged
     
     site = relationship("Site", backref=backref('sites', order_by = idx))
     cameraType = relationship('CameraType', backref=backref('camera_views', order_by = idx))
 
-    def __init__(self, description, homographyFilename, site, cameraType, trackingConfigurationFilename, maskFilename):
+    def __init__(self, description, homographyFilename, site, cameraType, trackingConfigurationFilename, maskFilename, virtual = False):
         self.description = description
         self.homographyFilename = homographyFilename
         self.site = site
         self.cameraType = cameraType
         self.trackingConfigurationFilename = trackingConfigurationFilename
         self.maskFilename = maskFilename
+        self.virtual = virtual
 
     def getHomographyFilename(self, relativeToSiteFilename = True):
         if relativeToSiteFilename:
@@ -232,11 +234,12 @@
     startTime = Column(DateTime)
     duration = Column(Interval) # video sequence duration
     databaseFilename = Column(String) # path relative to the the site name
+    virtual = Column(Boolean) # indicates it is not a real video sequence (no video file), eg merged
     cameraViewIdx = Column(Integer, ForeignKey('camera_views.idx'))
 
     cameraView = relationship("CameraView", backref=backref('video_sequences', order_by = idx))
 
-    def __init__(self, name, startTime, duration, cameraView, databaseFilename = None):
+    def __init__(self, name, startTime, duration, cameraView, databaseFilename = None, virtual = False):
         '''startTime is passed as string in utils.datetimeFormat, eg 2011-06-22 10:00:39
         duration is a timedelta object'''
         self.name = name
@@ -248,6 +251,7 @@
         self.cameraView = cameraView
         if databaseFilename is None and len(self.name) > 0:
             self.databaseFilename = removeExtension(self.name)+'.sqlite'
+        self.virtual = virtual
 
     def getVideoSequenceFilename(self, relativeToSiteFilename = True):
         if relativeToSiteFilename:
--- a/scripts/display-synced-trajectories.py	Tue Jul 05 13:56:13 2016 -0400
+++ b/scripts/display-synced-trajectories.py	Wed Jul 06 10:18:35 2016 -0400
@@ -28,13 +28,13 @@
 dirname = os.path.split(args.metadataFilename)[0]
 
 startTime = datetime.strptime(args.startTime, utils.datetimeFormat)
-# TODO issue with framerate
 if startTime > mergedSequence.startTime:
-    mergedFirstFrameNum = (startTime-mergedSequence.startTime).seconds*
+    mergedFirstFrameNum = (startTime-mergedSequence.startTime).seconds*mergedSequence.cameraView.cameraType.frameRate
 
-videoSequences = session.query(VideoSequence).filter(VideoSequence.site == mergedSequence.site).filter(VideoSequence.startTime <= startTime).all()
-videoSequences.remove(mergedSequence)
-videoSequences = [v for v in videoSequences if v.containsInstant(startTime)]
+cameraViews = session.query(CameraView).filter(CameraView.site == mergedSequence.site).filter(CameraView.virtual == False)
+videoSequences = session.query(VideoSequence).filter(VideoSequence.virtual == False).filter(VideoSequence.startTime <= startTime).all()
+#videoSequences.remove(mergedSequence)
+videoSequences = [v for v in videoSequences if v.cameraView in cameraViews and v.containsInstant(startTime)]
 filenames = [dirname+os.path.sep+v.getVideoSequenceFilename() for v in videoSequences]
 firstFrameNums = [v.getFrameNum(startTime) for v in videoSequences]
 windowNames = [v.cameraView.description for v in videoSequences]
--- a/scripts/merge-features.py	Tue Jul 05 13:56:13 2016 -0400
+++ b/scripts/merge-features.py	Wed Jul 06 10:18:35 2016 -0400
@@ -26,8 +26,8 @@
 startTime = datetime.strptime(args.startTime, utils.datetimeFormat)
 endTime = datetime.strptime(args.endTime, utils.datetimeFormat)
 processInterval = moving.TimeInterval(startTime, endTime)
-cameraViews = session.query(CameraView).filter(CameraView.site == site)
-videoSequences = session.query(VideoSequence).order_by(VideoSequence.startTime.asc()).all() #.order_by(VideoSequence.cameraViewIdx) .filter(VideoSequence.startTime <= startTime)
+cameraViews = session.query(CameraView).filter(CameraView.site == site).filter(CameraView.virtual == False)
+videoSequences = session.query(VideoSequence).filter(VideoSequence.virtual == False).order_by(VideoSequence.startTime.asc()).all() #.order_by(VideoSequence.cameraViewIdx) .filter(VideoSequence.startTime <= startTime)
 videoSequences = [vs for vs in videoSequences if vs.cameraView in cameraViews]
 #timeIntervals = [v.intersection(startTime, endTime) for v in videoSequences]
 #cameraViews = set([v.cameraView for v in videoSequences])
@@ -70,9 +70,8 @@
 newTrajectoryId = -1
 # first frame num is commonTimeInterval
 for cv, vs in videoSequences.iteritems():
-    #return cursor.fetchone()[0] == 1
+    print cv.idx, cv.description
     for videoSequence in vs:
-        print videoSequence.name
         try:
             vsConnection = sqlite3.connect(dirname+os.path.sep+videoSequence.getDatabaseFilename())
             vsCursor = vsConnection.cursor()
@@ -92,7 +91,6 @@
                     featureIdCorrespondences[currentTrajectoryId] = newTrajectoryId
                 outCursor.execute(storage.insertTrajectoryQuery('positions'), (newTrajectoryId, row[1]-firstFrameNum, row[2], row[3]))
             # velocities table
-            vsCursor.execute('SELECT * FROM velocities WHERE frame_number BETWEEN {} AND {} ORDER BY trajectory_id'.format(firstFrameNum, lastFrameNum))
             for row in vsCursor:
                 outCursor.execute(storage.insertTrajectoryQuery('velocities'), (featureIdCorrespondences[row[0]], row[1]-firstFrameNum, row[2], row[3]))
             # saving the id correspondences
@@ -101,9 +99,9 @@
             outConnection.commit()
         except sqlite3.OperationalError as error:
             storage.printDBError(error)
-
-# TODO save the information of the new "sequence" in the metadata
-mergedCameraView = CameraView('merged', None, site, cv.cameraType, None, None)
+            
+# save the information of the new virtual sequence and camera view in the metadata
+mergedCameraView = CameraView('merged', None, site, cv.cameraType, None, None, virtual = True)
+session.add(mergedCameraView)
+session.add(VideoSequence('merged', commonTimeInterval.first, commonTimeInterval.last-commonTimeInterval.first, mergedCameraView, virtual = True))
 session.commit()
-session.add(VideoSequence('merged', commonTimeInterval.first, commonTimeInterval.last-commonTimeInterval.first, mergedCameraView))
-session.commit()