changeset 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 c15b9fcdbcb1
files scripts/display-trajectories.py scripts/dltrack.py trafficintelligence/storage.py
diffstat 3 files changed, 20 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/display-trajectories.py	Fri Feb 14 15:01:40 2025 -0500
+++ b/scripts/display-trajectories.py	Fri Feb 21 17:09:19 2025 -0500
@@ -49,5 +49,5 @@
     nObjects = None
 
 objects = storage.loadTrajectoriesFromSqlite(databaseFilename, args.trajectoryType, nObjects)
-boundingBoxes = storage.loadBoundingBoxTableForDisplay(databaseFilename)
+boundingBoxes = storage.loadBoundingBoxTableForDisplay(databaseFilename) # not moving.BBMovingObjects, just list of rectangles to display
 cvutils.displayTrajectories(videoFilename, objects, boundingBoxes, invHomography, firstFrameNum, lastFrameNum, rescale = args.rescale, nFramesStep = args.nFramesStep, saveAllImages = args.saveAllImages, nZerosFilenameArg = args.nZerosFilenameArg, undistort = (undistort or args.undistort), intrinsicCameraMatrix = intrinsicCameraMatrix, distortionCoefficients = distortionCoefficients, undistortedImageMultiplication = undistortedImageMultiplication)
--- a/scripts/dltrack.py	Fri Feb 14 15:01:40 2025 -0500
+++ b/scripts/dltrack.py	Fri Feb 21 17:09:19 2025 -0500
@@ -31,7 +31,7 @@
 parser.add_argument('--intrinsic', dest = 'intrinsicCameraMatrixFilename', help = 'name of the intrinsic camera file')
 parser.add_argument('--distortion-coefficients', dest = 'distortionCoefficients', help = 'distortion coefficients', nargs = '*', type = float)
 parser.add_argument('--display', dest = 'display', help = 'show the raw detection and tracking results', action = 'store_true')
-parser.add_argument('--no-image-coordinates', dest = 'notSavingImageCoordinates', help = 'not saving the raw detection and tracking results', action = 'store_true')
+#parser.add_argument('--no-image-coordinates', dest = 'notSavingImageCoordinates', help = 'not saving the raw detection and tracking results', action = 'store_true')
 parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to process', type = int)
 parser.add_argument('-l', dest = 'lastFrameNum', help = 'number of last frame number to process', type = int, default = inf)
 parser.add_argument('--conf', dest = 'confidence', help = 'object confidence threshold for detection', type = float, default = 0.25)
--- 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):