diff trafficintelligence/storage.py @ 1296:d073524de272

work on bounding boxes
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 21 Feb 2025 17:09:19 -0500
parents 51893de43293
children
line wrap: on
line diff
--- a/trafficintelligence/storage.py	Fri Feb 14 15:01:40 2025 -0500
+++ b/trafficintelligence/storage.py	Fri Feb 21 17:09:19 2025 -0500
@@ -247,6 +247,7 @@
     return objects
 
 def loadObjectAttributesFromTable(cursor, objectNumbers, loadNObjects = False):
+    '''Loads the object user_type and n_objects fields'''
     objectCriteria = getObjectCriteria(objectNumbers)
     queryStatement = 'SELECT object_id, road_user_type'
     if loadNObjects:
@@ -469,25 +470,30 @@
             cursor.execute('update objects set road_user_type = {} WHERE object_id = {}'.format(obj.getUserType(), obj.getNum()))
         connection.commit()
 
-def loadBBMovingObjectsFromSqlite(filename, objectType = 'bb', objectNumbers = None, timeStep = None):
+# todo addBBTrajectories -> remove class and just add, comme curvilinear
+def addBoundingBoxTrajectoriesFromSqlite(filename, objects):
+    '''Adds curvilinear positions (s_coordinate, y_coordinate, lane)
+    from a database to an existing MovingObject dict (indexed by each objects's num) or list'''
+    pass
+
+def loadBBMovingObjectsFromSqlite(filename, objectNumbers = None, timeStep = None):
     '''Loads bounding box moving object from an SQLite
     (format of SQLite output by the ground truth annotation tool
     or Urban Tracker'''
     objects = []
     if Path(filename).is_file():
         with sqlite3.connect(filename) as connection:
-            if objectType == 'bb':
-                topCorners = loadTrajectoriesFromTable(connection, 'bounding_boxes', 'bbtop', objectNumbers, timeStep)
-                bottomCorners = loadTrajectoriesFromTable(connection, 'bounding_boxes', 'bbbottom', objectNumbers, timeStep)
-                userTypes = loadObjectAttributesFromTable(connection.cursor(), objectNumbers) # string format is same as object
+            topCorners = loadTrajectoriesFromTable(connection, 'bounding_boxes', 'bbtop', objectNumbers, timeStep)
+            bottomCorners = loadTrajectoriesFromTable(connection, 'bounding_boxes', 'bbbottom', objectNumbers, timeStep)
+            userTypes = loadObjectAttributesFromTable(connection.cursor(), objectNumbers) # string format is same as object
 
-                for t, b in zip(topCorners, bottomCorners):
-                    num = t.getNum()
-                    if t.getNum() == b.getNum():
-                        annotation = moving.BBMovingObject(num, t, b, t.getTimeInterval(), userTypes[num])
-                        objects.append(annotation)
-            else:
-                print ('Unknown type of bounding box {}'.format(objectType))
+            for i in range(len(topCorners)):#t, b in zip(topCorners, bottomCorners):
+                num = topCorners[i].getNum()
+                if num == bottomCorners[i].getNum():
+                    annotation = moving.BBMovingObject(topCorners[i], bottomCorners[i], num, topCorners[i].getTimeInterval(), userTypes[num])
+                    objects.append(annotation)
+                else:
+                    print('Mismatch id for top left and bottom right corners (resp. {} {})'.format(num, bottomCorners[i].getNum()))
     return objects
 
 def saveBBMovingObjectsToSqlite(outputFilename, objects):