Mercurial Hosting > traffic-intelligence
comparison python/storage.py @ 587:cf578ba866da
added code to load bounding box corners as trajectories
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 04 Dec 2014 17:46:32 -0500 |
parents | ff4f0ce46ca6 |
children | c5406edbcf12 |
comparison
equal
deleted
inserted
replaced
586:ff4f0ce46ca6 | 587:cf578ba866da |
---|---|
247 | 247 |
248 def getTrajectoryIdQuery(objectNumbers, trajectoryType): | 248 def getTrajectoryIdQuery(objectNumbers, trajectoryType): |
249 if trajectoryType == 'feature': | 249 if trajectoryType == 'feature': |
250 statementBeginning = 'where trajectory_id ' | 250 statementBeginning = 'where trajectory_id ' |
251 elif trajectoryType == 'object': | 251 elif trajectoryType == 'object': |
252 statementBeginning = 'and OF.object_id ' | 252 statementBeginning = 'and OF.object_id ' |
253 elif trajectoryType == 'bbtop' or 'bbbottom': | |
254 statementBeginning = 'where object_id ' | |
253 else: | 255 else: |
254 print('no trajectory type was chosen') | 256 print('no trajectory type was chosen') |
255 | 257 |
256 if objectNumbers is None: | 258 if objectNumbers is None: |
257 query = '' | 259 query = '' |
267 | 269 |
268 returns a moving object''' | 270 returns a moving object''' |
269 cursor = connection.cursor() | 271 cursor = connection.cursor() |
270 | 272 |
271 try: | 273 try: |
274 trajectoryIdQuery = getTrajectoryIdQuery(objectNumbers, trajectoryType) | |
272 if trajectoryType == 'feature': | 275 if trajectoryType == 'feature': |
273 trajectoryIdQuery = getTrajectoryIdQuery(objectNumbers, trajectoryType) | 276 queryStatement = 'SELECT * from '+tableName+' '+trajectoryIdQuery+'ORDER BY trajectory_id, frame_number' |
274 queryStatement = 'SELECT * from '+tableName+' '+trajectoryIdQuery+'order by trajectory_id, frame_number' | |
275 cursor.execute(queryStatement) | 277 cursor.execute(queryStatement) |
276 logging.debug(queryStatement) | 278 logging.debug(queryStatement) |
277 elif trajectoryType == 'object': | 279 elif trajectoryType == 'object': |
278 objectIdQuery = getTrajectoryIdQuery(objectNumbers, trajectoryType) | 280 queryStatement = 'SELECT OF.object_id, P.frame_number, avg(P.x_coordinate), avg(P.y_coordinate) from '+tableName+' P, objects_features OF where P.trajectory_id = OF.trajectory_id '+objectIdQuery+'group by OF.object_id, P.frame_number ORDER BY OF.object_id, P.frame_number' |
279 queryStatement = 'SELECT OF.object_id, P.frame_number, avg(P.x_coordinate), avg(P.y_coordinate) from '+tableName+' P, objects_features OF where P.trajectory_id = OF.trajectory_id '+objectIdQuery+'group by OF.object_id, P.frame_number order by OF.object_id, P.frame_number' | 281 cursor.execute(queryStatement) |
282 logging.debug(queryStatement) | |
283 elif trajectoryType == 'bbtop' or trajectoryType == 'bbbottom': | |
284 if trajectoryType == 'bbtop': | |
285 corner = 'top_left' | |
286 elif trajectoryType == 'bbbottom': | |
287 corner = 'bottom_right' | |
288 queryStatement = 'SELECT object_id, frame_number, x_'+corner+', y_'+corner+' FROM '+tableName+' '+trajectoryIdQuery+'ORDER BY object_id, frame_number' | |
280 cursor.execute(queryStatement) | 289 cursor.execute(queryStatement) |
281 logging.debug(queryStatement) | 290 logging.debug(queryStatement) |
282 else: | 291 else: |
283 print('no trajectory type was chosen') | 292 print('no trajectory type was chosen') |
284 except sqlite3.OperationalError as error: | 293 except sqlite3.OperationalError as error: |
289 obj = None | 298 obj = None |
290 objects = [] | 299 objects = [] |
291 for row in cursor: | 300 for row in cursor: |
292 if row[0] != objId: | 301 if row[0] != objId: |
293 objId = row[0] | 302 objId = row[0] |
294 if obj: | 303 if obj != None: |
295 objects.append(obj) | 304 objects.append(obj) |
296 obj = moving.MovingObject(row[0], timeInterval = moving.TimeInterval(row[1], row[1]), positions = moving.Trajectory([[row[2]],[row[3]]])) | 305 obj = moving.MovingObject(row[0], timeInterval = moving.TimeInterval(row[1], row[1]), positions = moving.Trajectory([[row[2]],[row[3]]])) |
297 else: | 306 else: |
298 obj.timeInterval.last = row[1] | 307 obj.timeInterval.last = row[1] |
299 obj.positions.addPositionXY(row[2],row[3]) | 308 obj.positions.addPositionXY(row[2],row[3]) |
495 printDBError(error) | 504 printDBError(error) |
496 return boundingBoxes | 505 return boundingBoxes |
497 connection.close() | 506 connection.close() |
498 return boundingBoxes | 507 return boundingBoxes |
499 | 508 |
509 def loadBoundingBoxTable(filename): | |
510 connection = sqlite3.connect(filename) | |
511 cursor = connection.cursor() | |
512 boundingBoxes = [] | |
513 | |
514 try: | |
515 pass | |
516 except sqlite3.OperationalError as error: | |
517 printDBError(error) | |
518 return boundingBoxes | |
519 connection.close() | |
520 return boundingBoxes | |
521 | |
500 | 522 |
501 ######################### | 523 ######################### |
502 # txt files | 524 # txt files |
503 ######################### | 525 ######################### |
504 | 526 |