Mercurial Hosting > traffic-intelligence
changeset 768:f8e0a8ea8402 dev
updated the bounding box code (the name so that it is general for ground truth and UT)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 14 Jan 2016 11:44:39 -0500 |
parents | 04497166d8f0 |
children | dfdb2a3722cc |
files | python/moving.py python/storage.py python/tests/moving.txt scripts/compute-clearmot.py |
diffstat | 4 files changed, 30 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/python/moving.py Mon Dec 21 15:16:33 2015 -0500 +++ b/python/moving.py Thu Jan 14 11:44:39 2016 -0500 @@ -1560,15 +1560,19 @@ # Annotations ################## -class BBAnnotation(MovingObject): - '''Class for a series of ground truth annotations using bounding boxes - Its center is the center of the containing shape +class BBMovingObject(MovingObject): + '''Class for a moving object represented as a bounding box + used for series of ground truth annotations using bounding boxes + and for the output of Urban Tracker http://www.jpjodoin.com/urbantracker/ By default in image space + + Its center is the center of the box (generalize to other shapes?) + (computed after projecting if homography available) ''' def __init__(self, num = None, timeInterval = None, topLeftPositions = None, bottomRightPositions = None, userType = userType2Num['unknown']): - super(BBAnnotation, self).__init__(num, timeInterval, userType = userType) + super(BBMovingObject, self).__init__(num, timeInterval, userType = userType) self.topLeftPositions = topLeftPositions.getPositions() self.bottomRightPositions = bottomRightPositions.getPositions() @@ -1595,7 +1599,7 @@ Keni, Bernardin, and Stiefelhagen Rainer. "Evaluating multiple object tracking performance: the CLEAR MOT metrics." EURASIP Journal on Image and Video Processing 2008 (2008) objects and annotations are supposed to in the same space - current implementation is BBAnnotations (bounding boxes) + current implementation is BBMovingObject (bounding boxes) mathingDistance is threshold on matching between annotation and object TO: tracker output (objects)
--- a/python/storage.py Mon Dec 21 15:16:33 2015 -0500 +++ b/python/storage.py Thu Jan 14 11:44:39 2016 -0500 @@ -300,26 +300,30 @@ def loadPrototypesFromSqlite(filename): pass -def loadGroundTruthFromSqlite(filename, gtType = 'bb', gtNumbers = None): - 'Loads bounding box annotations (ground truth) from an SQLite ' - connection = sqlite3.connect(filename) - gt = [] +def loadBBMovingObjectsFromSqlite(filename, objectType = 'bb', objectNumbers = None): + '''Loads bounding box moving object from an SQLite + (format of SQLite output by the ground truth annotation tool + or Urban Tracker - if gtType == 'bb': - topCorners = loadTrajectoriesFromTable(connection, 'bounding_boxes', 'bbtop', gtNumbers) - bottomCorners = loadTrajectoriesFromTable(connection, 'bounding_boxes', 'bbbottom', gtNumbers) - userTypes = loadUserTypesFromTable(connection.cursor(), 'object', gtNumbers) # string format is same as object + Load descriptions?''' + connection = sqlite3.connect(filename) + objects = [] + + if objectType == 'bb': + topCorners = loadTrajectoriesFromTable(connection, 'bounding_boxes', 'bbtop', objectNumbers) + bottomCorners = loadTrajectoriesFromTable(connection, 'bounding_boxes', 'bbbottom', objectNumbers) + userTypes = loadUserTypesFromTable(connection.cursor(), 'object', objectNumbers) # string format is same as object for t, b in zip(topCorners, bottomCorners): num = t.getNum() if t.getNum() == b.getNum(): - annotation = moving.BBAnnotation(num, t.getTimeInterval(), t, b, userTypes[num]) - gt.append(annotation) + annotation = moving.BBMovingObject(num, t.getTimeInterval(), t, b, userTypes[num]) + objects.append(annotation) else: - print ('Unknown type of annotation {}'.format(gtType)) + print ('Unknown type of bounding box {}'.format(objectType)) connection.close() - return gt + return objects def deleteFromSqlite(filename, dataType): 'Deletes (drops) some tables in the filename depending on type of data' @@ -442,7 +446,7 @@ boundingBoxes = {} # list of bounding boxes for each instant try: cursor.execute('SELECT name FROM sqlite_master WHERE type=\'table\' AND name=\'bounding_boxes\'') - result = [row for row in cursor] + result = cursor.fetchall() if len(result) > 0: cursor.execute('SELECT * FROM bounding_boxes') for row in cursor:
--- a/python/tests/moving.txt Mon Dec 21 15:16:33 2015 -0500 +++ b/python/tests/moving.txt Thu Jan 14 11:44:39 2016 -0500 @@ -176,7 +176,7 @@ 'pedestrian' >>> o1 = MovingObject.generate(Point(0.,0.), Point(1.,0.), TimeInterval(0,10)) ->>> gt1 = BBAnnotation(1, TimeInterval(0,10), MovingObject.generate(Point(0.2,0.6), Point(1.,0.), TimeInterval(0,10)), MovingObject.generate(Point(-0.2,-0.4), Point(1.,0.), TimeInterval(0,10))) +>>> gt1 = BBMovingObject(1, TimeInterval(0,10), MovingObject.generate(Point(0.2,0.6), Point(1.,0.), TimeInterval(0,10)), MovingObject.generate(Point(-0.2,-0.4), Point(1.,0.), TimeInterval(0,10))) >>> gt1.computeCentroidTrajectory() >>> computeClearMOT([gt1], [], 0.2, 0, 10) (None, 0.0, 11, 0, 0, 11) @@ -189,9 +189,9 @@ >>> o1 = MovingObject(1, TimeInterval(0,3), positions = Trajectory([range(4), [0.1, 0.1, 1.1, 1.1]])) >>> o2 = MovingObject(2, TimeInterval(0,3), positions = Trajectory([range(4), [0.9, 0.9, -0.1, -0.1]])) ->>> gt1 = BBAnnotation(1, TimeInterval(0,3), MovingObject(positions = Trajectory([range(4), [0.]*4])), MovingObject(positions = Trajectory([range(4), [0.]*4]))) +>>> gt1 = BBMovingObject(1, TimeInterval(0,3), MovingObject(positions = Trajectory([range(4), [0.]*4])), MovingObject(positions = Trajectory([range(4), [0.]*4]))) >>> gt1.computeCentroidTrajectory() ->>> gt2 = BBAnnotation(2, TimeInterval(0,3), MovingObject(positions = Trajectory([range(4), [1.]*4])), MovingObject(positions = Trajectory([range(4), [1.]*4]))) +>>> gt2 = BBMovingObject(2, TimeInterval(0,3), MovingObject(positions = Trajectory([range(4), [1.]*4])), MovingObject(positions = Trajectory([range(4), [1.]*4]))) >>> gt2.computeCentroidTrajectory() >>> computeClearMOT([gt1, gt2], [o1, o2], 0.2, 0, 3) # doctest:+ELLIPSIS (0.1..., 0.75, 0, 2, 0, 8)
--- a/scripts/compute-clearmot.py Mon Dec 21 15:16:33 2015 -0500 +++ b/scripts/compute-clearmot.py Thu Jan 14 11:44:39 2016 -0500 @@ -41,7 +41,7 @@ maskObjects += obj.getObjectsInMask(mask, inv(homography), 2) # TODO add option to keep object if at least one feature in mask objects = maskObjects -annotations = storage.loadGroundTruthFromSqlite(args.groundTruthDatabaseFilename) +annotations = storage.loadBBMovingObjectsFromSqlite(args.groundTruthDatabaseFilename) for a in annotations: a.computeCentroidTrajectory(homography)