comparison 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
comparison
equal deleted inserted replaced
1295:51893de43293 1296:d073524de272
245 print('Object {} is missing {} positions'.format(obj.getNum(), int(obj.length())-obj.positions.length())) 245 print('Object {} is missing {} positions'.format(obj.getNum(), int(obj.length())-obj.positions.length()))
246 246
247 return objects 247 return objects
248 248
249 def loadObjectAttributesFromTable(cursor, objectNumbers, loadNObjects = False): 249 def loadObjectAttributesFromTable(cursor, objectNumbers, loadNObjects = False):
250 '''Loads the object user_type and n_objects fields'''
250 objectCriteria = getObjectCriteria(objectNumbers) 251 objectCriteria = getObjectCriteria(objectNumbers)
251 queryStatement = 'SELECT object_id, road_user_type' 252 queryStatement = 'SELECT object_id, road_user_type'
252 if loadNObjects: 253 if loadNObjects:
253 queryStatement += ', n_objects' 254 queryStatement += ', n_objects'
254 queryStatement += ' FROM objects' 255 queryStatement += ' FROM objects'
467 cursor = connection.cursor() 468 cursor = connection.cursor()
468 for obj in objects: 469 for obj in objects:
469 cursor.execute('update objects set road_user_type = {} WHERE object_id = {}'.format(obj.getUserType(), obj.getNum())) 470 cursor.execute('update objects set road_user_type = {} WHERE object_id = {}'.format(obj.getUserType(), obj.getNum()))
470 connection.commit() 471 connection.commit()
471 472
472 def loadBBMovingObjectsFromSqlite(filename, objectType = 'bb', objectNumbers = None, timeStep = None): 473 # todo addBBTrajectories -> remove class and just add, comme curvilinear
474 def addBoundingBoxTrajectoriesFromSqlite(filename, objects):
475 '''Adds curvilinear positions (s_coordinate, y_coordinate, lane)
476 from a database to an existing MovingObject dict (indexed by each objects's num) or list'''
477 pass
478
479 def loadBBMovingObjectsFromSqlite(filename, objectNumbers = None, timeStep = None):
473 '''Loads bounding box moving object from an SQLite 480 '''Loads bounding box moving object from an SQLite
474 (format of SQLite output by the ground truth annotation tool 481 (format of SQLite output by the ground truth annotation tool
475 or Urban Tracker''' 482 or Urban Tracker'''
476 objects = [] 483 objects = []
477 if Path(filename).is_file(): 484 if Path(filename).is_file():
478 with sqlite3.connect(filename) as connection: 485 with sqlite3.connect(filename) as connection:
479 if objectType == 'bb': 486 topCorners = loadTrajectoriesFromTable(connection, 'bounding_boxes', 'bbtop', objectNumbers, timeStep)
480 topCorners = loadTrajectoriesFromTable(connection, 'bounding_boxes', 'bbtop', objectNumbers, timeStep) 487 bottomCorners = loadTrajectoriesFromTable(connection, 'bounding_boxes', 'bbbottom', objectNumbers, timeStep)
481 bottomCorners = loadTrajectoriesFromTable(connection, 'bounding_boxes', 'bbbottom', objectNumbers, timeStep) 488 userTypes = loadObjectAttributesFromTable(connection.cursor(), objectNumbers) # string format is same as object
482 userTypes = loadObjectAttributesFromTable(connection.cursor(), objectNumbers) # string format is same as object 489
483 490 for i in range(len(topCorners)):#t, b in zip(topCorners, bottomCorners):
484 for t, b in zip(topCorners, bottomCorners): 491 num = topCorners[i].getNum()
485 num = t.getNum() 492 if num == bottomCorners[i].getNum():
486 if t.getNum() == b.getNum(): 493 annotation = moving.BBMovingObject(topCorners[i], bottomCorners[i], num, topCorners[i].getTimeInterval(), userTypes[num])
487 annotation = moving.BBMovingObject(num, t, b, t.getTimeInterval(), userTypes[num]) 494 objects.append(annotation)
488 objects.append(annotation) 495 else:
489 else: 496 print('Mismatch id for top left and bottom right corners (resp. {} {})'.format(num, bottomCorners[i].getNum()))
490 print ('Unknown type of bounding box {}'.format(objectType))
491 return objects 497 return objects
492 498
493 def saveBBMovingObjectsToSqlite(outputFilename, objects): 499 def saveBBMovingObjectsToSqlite(outputFilename, objects):
494 '''Saves bounding boxes as obtained from annotation 500 '''Saves bounding boxes as obtained from annotation
495 object detector-based tracking tool like dltrack 501 object detector-based tracking tool like dltrack