nsaunier/traffic-intelligence
work on bounding boxes
Commit d073524de272 · Nicolas Saunier · 2025-02-21 17:09 -0500
Comments
No comments yet.
Diff
diff --git a/scripts/display-trajectories.py b/scripts/display-trajectories.py
--- a/scripts/display-trajectories.py
+++ b/scripts/display-trajectories.py
@@ -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)
diff --git a/scripts/dltrack.py b/scripts/dltrack.py
--- a/scripts/dltrack.py
+++ b/scripts/dltrack.py
@@ -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)
diff --git a/trafficintelligence/storage.py b/trafficintelligence/storage.py
--- a/trafficintelligence/storage.py
+++ b/trafficintelligence/storage.py
@@ -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):