changeset 587:cf578ba866da

added code to load bounding box corners as trajectories
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 04 Dec 2014 17:46:32 -0500
parents ff4f0ce46ca6
children c5406edbcf12
files python/moving.py python/storage.py
diffstat 2 files changed, 47 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/python/moving.py	Thu Dec 04 17:21:45 2014 -0500
+++ b/python/moving.py	Thu Dec 04 17:46:32 2014 -0500
@@ -1276,6 +1276,25 @@
         return Point.cosine(movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant), #deltap
                             movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant)) #deltav
 
+
+##################
+# Bounding Boxes
+##################
+
+# class BoundingBoxes(STObject):
+#     '''Class for : a spatio-temporal object 
+#     with a trajectory and a geometry (constant volume over time) and a usertype (e.g. road user) coded as a number (see 
+#     '''
+
+#     def __init__(self, num = None, timeInterval = None, positions = None, velocities = None, geometry = None, userType = userType2Num['unknown']):
+#         super(MovingObject, self).__init__(num, timeInterval)
+#         self.positions = positions
+#         self.velocities = velocities
+#         self.geometry = geometry
+#         self.userType = userType
+#         self.features = []
+#         # compute bounding polygon from trajectory
+
 def plotRoadUsers(objects, colors):
     '''Colors is a PlottingPropertyValues instance'''
     from matplotlib.pyplot import figure, axis
--- a/python/storage.py	Thu Dec 04 17:21:45 2014 -0500
+++ b/python/storage.py	Thu Dec 04 17:46:32 2014 -0500
@@ -249,7 +249,9 @@
     if trajectoryType == 'feature':
         statementBeginning = 'where trajectory_id '
     elif trajectoryType == 'object':
-        statementBeginning =  'and OF.object_id '
+        statementBeginning = 'and OF.object_id '
+    elif trajectoryType == 'bbtop' or 'bbbottom':
+        statementBeginning = 'where object_id '
     else:
         print('no trajectory type was chosen')
 
@@ -269,14 +271,21 @@
     cursor = connection.cursor()
 
     try:
+        trajectoryIdQuery = getTrajectoryIdQuery(objectNumbers, trajectoryType)
         if trajectoryType == 'feature':
-            trajectoryIdQuery = getTrajectoryIdQuery(objectNumbers, trajectoryType)
-            queryStatement = 'SELECT * from '+tableName+' '+trajectoryIdQuery+'order by trajectory_id, frame_number'
+            queryStatement = 'SELECT * from '+tableName+' '+trajectoryIdQuery+'ORDER BY trajectory_id, frame_number'
             cursor.execute(queryStatement)
             logging.debug(queryStatement)
         elif trajectoryType == 'object':
-            objectIdQuery = getTrajectoryIdQuery(objectNumbers, trajectoryType)
-            queryStatement = 'SELECT OF.object_id, P.frame_number, avg(P.x_coordinate), avg(P.y_coordinate) from '+tableName+' P, objects_features OF where P.trajectory_id = OF.trajectory_id '+objectIdQuery+'group by OF.object_id, P.frame_number order by OF.object_id, P.frame_number'
+            queryStatement = 'SELECT OF.object_id, P.frame_number, avg(P.x_coordinate), avg(P.y_coordinate) from '+tableName+' P, objects_features OF where P.trajectory_id = OF.trajectory_id '+objectIdQuery+'group by OF.object_id, P.frame_number ORDER BY OF.object_id, P.frame_number'
+            cursor.execute(queryStatement)
+            logging.debug(queryStatement)
+        elif trajectoryType == 'bbtop' or trajectoryType == 'bbbottom':
+            if trajectoryType == 'bbtop':
+                corner = 'top_left'
+            elif trajectoryType == 'bbbottom':
+                corner = 'bottom_right'
+            queryStatement = 'SELECT object_id, frame_number, x_'+corner+', y_'+corner+' FROM '+tableName+' '+trajectoryIdQuery+'ORDER BY object_id, frame_number'
             cursor.execute(queryStatement)
             logging.debug(queryStatement)
         else:
@@ -291,7 +300,7 @@
     for row in cursor:
         if row[0] != objId:
             objId = row[0]
-            if obj:
+            if obj != None:
                 objects.append(obj)
             obj = moving.MovingObject(row[0], timeInterval = moving.TimeInterval(row[1], row[1]), positions = moving.Trajectory([[row[2]],[row[3]]]))
         else:
@@ -497,6 +506,19 @@
     connection.close()
     return boundingBoxes
 
+def loadBoundingBoxTable(filename):
+    connection = sqlite3.connect(filename)
+    cursor = connection.cursor()
+    boundingBoxes = []
+    
+    try:
+        pass
+    except sqlite3.OperationalError as error:
+        printDBError(error)
+        return boundingBoxes
+    connection.close()
+    return boundingBoxes
+
 
 #########################
 # txt files