comparison python/storage.py @ 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 a05b70f307dd
children bf4a1790cfac
comparison
equal deleted inserted replaced
767:04497166d8f0 768:f8e0a8ea8402
298 connection.close() 298 connection.close()
299 299
300 def loadPrototypesFromSqlite(filename): 300 def loadPrototypesFromSqlite(filename):
301 pass 301 pass
302 302
303 def loadGroundTruthFromSqlite(filename, gtType = 'bb', gtNumbers = None): 303 def loadBBMovingObjectsFromSqlite(filename, objectType = 'bb', objectNumbers = None):
304 'Loads bounding box annotations (ground truth) from an SQLite ' 304 '''Loads bounding box moving object from an SQLite
305 connection = sqlite3.connect(filename) 305 (format of SQLite output by the ground truth annotation tool
306 gt = [] 306 or Urban Tracker
307 307
308 if gtType == 'bb': 308 Load descriptions?'''
309 topCorners = loadTrajectoriesFromTable(connection, 'bounding_boxes', 'bbtop', gtNumbers) 309 connection = sqlite3.connect(filename)
310 bottomCorners = loadTrajectoriesFromTable(connection, 'bounding_boxes', 'bbbottom', gtNumbers) 310 objects = []
311 userTypes = loadUserTypesFromTable(connection.cursor(), 'object', gtNumbers) # string format is same as object 311
312 if objectType == 'bb':
313 topCorners = loadTrajectoriesFromTable(connection, 'bounding_boxes', 'bbtop', objectNumbers)
314 bottomCorners = loadTrajectoriesFromTable(connection, 'bounding_boxes', 'bbbottom', objectNumbers)
315 userTypes = loadUserTypesFromTable(connection.cursor(), 'object', objectNumbers) # string format is same as object
312 316
313 for t, b in zip(topCorners, bottomCorners): 317 for t, b in zip(topCorners, bottomCorners):
314 num = t.getNum() 318 num = t.getNum()
315 if t.getNum() == b.getNum(): 319 if t.getNum() == b.getNum():
316 annotation = moving.BBAnnotation(num, t.getTimeInterval(), t, b, userTypes[num]) 320 annotation = moving.BBMovingObject(num, t.getTimeInterval(), t, b, userTypes[num])
317 gt.append(annotation) 321 objects.append(annotation)
318 else: 322 else:
319 print ('Unknown type of annotation {}'.format(gtType)) 323 print ('Unknown type of bounding box {}'.format(objectType))
320 324
321 connection.close() 325 connection.close()
322 return gt 326 return objects
323 327
324 def deleteFromSqlite(filename, dataType): 328 def deleteFromSqlite(filename, dataType):
325 'Deletes (drops) some tables in the filename depending on type of data' 329 'Deletes (drops) some tables in the filename depending on type of data'
326 import os 330 import os
327 if os.path.isfile(filename): 331 if os.path.isfile(filename):
440 connection = sqlite3.connect(filename) 444 connection = sqlite3.connect(filename)
441 cursor = connection.cursor() 445 cursor = connection.cursor()
442 boundingBoxes = {} # list of bounding boxes for each instant 446 boundingBoxes = {} # list of bounding boxes for each instant
443 try: 447 try:
444 cursor.execute('SELECT name FROM sqlite_master WHERE type=\'table\' AND name=\'bounding_boxes\'') 448 cursor.execute('SELECT name FROM sqlite_master WHERE type=\'table\' AND name=\'bounding_boxes\'')
445 result = [row for row in cursor] 449 result = cursor.fetchall()
446 if len(result) > 0: 450 if len(result) > 0:
447 cursor.execute('SELECT * FROM bounding_boxes') 451 cursor.execute('SELECT * FROM bounding_boxes')
448 for row in cursor: 452 for row in cursor:
449 boundingBoxes.setdefault(row[1], []).append([moving.Point(row[2], row[3]), moving.Point(row[4], row[5])]) 453 boundingBoxes.setdefault(row[1], []).append([moving.Point(row[2], row[3]), moving.Point(row[4], row[5])])
450 except sqlite3.OperationalError as error: 454 except sqlite3.OperationalError as error: