Mercurial Hosting > traffic-intelligence
comparison python/storage.py @ 394:6567fee37c16
renamed table for bounding boxes
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 26 Jul 2013 17:24:33 -0400 |
parents | eaf7765221d9 |
children | a2ff03a52b73 |
comparison
equal
deleted
inserted
replaced
393:eaf7765221d9 | 394:6567fee37c16 |
---|---|
194 if dataType == 'object': | 194 if dataType == 'object': |
195 utils.dropTables(connection, ['objects', 'objects_features']) | 195 utils.dropTables(connection, ['objects', 'objects_features']) |
196 elif dataType == 'interaction': | 196 elif dataType == 'interaction': |
197 utils.dropTables(connection, ['interactions', 'indicators']) | 197 utils.dropTables(connection, ['interactions', 'indicators']) |
198 elif dataType == 'bb': | 198 elif dataType == 'bb': |
199 utils.dropTables(connection, ['boundingbox']) | 199 utils.dropTables(connection, ['bounding_boxes']) |
200 else: | 200 else: |
201 print('Unknown data type {} to delete from database'.format(dataType)) | 201 print('Unknown data type {} to delete from database'.format(dataType)) |
202 connection.close() | 202 connection.close() |
203 | 203 |
204 def createInteractionTable(cursor): | 204 def createInteractionTable(cursor): |
295 '''Create the table to store the object bounding boxes | 295 '''Create the table to store the object bounding boxes |
296 ''' | 296 ''' |
297 connection = sqlite3.connect(filename) | 297 connection = sqlite3.connect(filename) |
298 cursor = connection.cursor() | 298 cursor = connection.cursor() |
299 try: | 299 try: |
300 cursor.execute('CREATE TABLE IF NOT EXISTS boundingbox (object_id INTEGER, frame_number INTEGER, x_top_left REAL, y_top_left REAL, x_bottom_right REAL, y_bottom_right REAL, PRIMARY KEY(object_id, frame_number))') | 300 cursor.execute('CREATE TABLE IF NOT EXISTS bounding_boxes (object_id INTEGER, frame_number INTEGER, x_top_left REAL, y_top_left REAL, x_bottom_right REAL, y_bottom_right REAL, PRIMARY KEY(object_id, frame_number))') |
301 cursor.execute('INSERT INTO boundingbox SELECT object_id, frame_number, min(x), min(y), max(x), max(y) from ' | 301 cursor.execute('INSERT INTO bounding_boxes SELECT object_id, frame_number, min(x), min(y), max(x), max(y) from ' |
302 '(SELECT object_id, frame_number, (x*{}+y*{}+{})/w as x, (x*{}+y*{}+{})/w as y from ' | 302 '(SELECT object_id, frame_number, (x*{}+y*{}+{})/w as x, (x*{}+y*{}+{})/w as y from ' |
303 '(SELECT OF.object_id, P.frame_number, P.x_coordinate as x, P.y_coordinate as y, P.x_coordinate*{}+P.y_coordinate*{}+{} as w from positions P, objects_features OF where P.trajectory_id = OF.trajectory_id)) '.format(invHomography[0,0], invHomography[0,1], invHomography[0,2], invHomography[1,0], invHomography[1,1], invHomography[1,2], invHomography[2,0], invHomography[2,1], invHomography[2,2])+ | 303 '(SELECT OF.object_id, P.frame_number, P.x_coordinate as x, P.y_coordinate as y, P.x_coordinate*{}+P.y_coordinate*{}+{} as w from positions P, objects_features OF where P.trajectory_id = OF.trajectory_id)) '.format(invHomography[0,0], invHomography[0,1], invHomography[0,2], invHomography[1,0], invHomography[1,1], invHomography[1,2], invHomography[2,0], invHomography[2,1], invHomography[2,2])+ |
304 'GROUP BY object_id, frame_number') | 304 'GROUP BY object_id, frame_number') |
305 except sqlite3.OperationalError as error: | 305 except sqlite3.OperationalError as error: |
306 utils.printDBError(error) | 306 utils.printDBError(error) |
310 def loadBoundingBoxTable(filename): | 310 def loadBoundingBoxTable(filename): |
311 connection = sqlite3.connect(filename) | 311 connection = sqlite3.connect(filename) |
312 cursor = connection.cursor() | 312 cursor = connection.cursor() |
313 boundingBoxes = {} # list of bounding boxes for each instant | 313 boundingBoxes = {} # list of bounding boxes for each instant |
314 try: | 314 try: |
315 cursor.execute('SELECT name FROM sqlite_master WHERE type=\'table\' AND name=\'boundingbox\'') | 315 cursor.execute('SELECT name FROM sqlite_master WHERE type=\'table\' AND name=\'bounding_boxes\'') |
316 result = [row for row in cursor] | 316 result = [row for row in cursor] |
317 if len(result) > 0: | 317 if len(result) > 0: |
318 cursor.execute('SELECT * FROM boundingbox') | 318 cursor.execute('SELECT * FROM bounding_boxes') |
319 #objId = -1 | 319 #objId = -1 |
320 for row in cursor: | 320 for row in cursor: |
321 #if row[0] != objId: | 321 #if row[0] != objId: |
322 boundingBoxes.setdefault(row[1], []).append([moving.Point(row[2], row[3]), moving.Point(row[4], row[5])]) | 322 boundingBoxes.setdefault(row[1], []).append([moving.Point(row[2], row[3]), moving.Point(row[4], row[5])]) |
323 except sqlite3.OperationalError as error: | 323 except sqlite3.OperationalError as error: |