Mercurial > hg > nsaunier > traffic-intelligence
comparison python/utils.py @ 397:b36b00dd27c3
added function to read scene metadata
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Sun, 28 Jul 2013 18:04:20 -0400 |
| parents | 6fba1ab040f1 |
| children | 3399bd48cb40 |
comparison
equal
deleted
inserted
replaced
| 396:167f6ec44ec5 | 397:b36b00dd27c3 |
|---|---|
| 1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
| 2 ''' Generic utilities.''' | 2 ''' Generic utilities.''' |
| 3 | 3 |
| 4 #from numpy import * | 4 #from numpy import * |
| 5 #from pylab import * | 5 #from pylab import * |
| 6 from datetime import time | 6 from datetime import time, datetime |
| 7 | 7 |
| 8 __metaclass__ = type | 8 __metaclass__ = type |
| 9 | 9 |
| 10 commentChar = '#' | 10 commentChar = '#' |
| 11 | 11 |
| 147 | 147 |
| 148 def framesToTime(nFrames, frameRate, initialTime = time()): | 148 def framesToTime(nFrames, frameRate, initialTime = time()): |
| 149 '''returns a datetime.time for the time in hour, minutes and seconds | 149 '''returns a datetime.time for the time in hour, minutes and seconds |
| 150 initialTime is a datetime.time''' | 150 initialTime is a datetime.time''' |
| 151 from math import floor | 151 from math import floor |
| 152 from datetime import time | |
| 153 seconds = int(floor(float(nFrames)/float(frameRate))+initialTime.hour*3600+initialTime.minute*60+initialTime.second) | 152 seconds = int(floor(float(nFrames)/float(frameRate))+initialTime.hour*3600+initialTime.minute*60+initialTime.second) |
| 154 h = int(floor(seconds/3600.)) | 153 h = int(floor(seconds/3600.)) |
| 155 seconds = seconds - h*3600 | 154 seconds = seconds - h*3600 |
| 156 m = int(floor(seconds/60)) | 155 m = int(floor(seconds/60)) |
| 157 seconds = seconds - m*60 | 156 seconds = seconds - m*60 |
| 499 print(optionValues) | 498 print(optionValues) |
| 500 sys.exit() | 499 sys.exit() |
| 501 | 500 |
| 502 return optionValues | 501 return optionValues |
| 503 | 502 |
| 503 | |
| 504 ######################### | |
| 505 # Utils to read .ini type text files for configuration, meta data... | |
| 506 ######################### | |
| 507 | |
| 504 class TrackingParameters: | 508 class TrackingParameters: |
| 505 def loadConfigFile(self, filename): | 509 def loadConfigFile(self, filename): |
| 506 from ConfigParser import ConfigParser | 510 from ConfigParser import ConfigParser |
| 507 from numpy import loadtxt | 511 from numpy import loadtxt |
| 508 from os import path | 512 from os import path |
| 529 self.minAcceleration = config.getfloat(self.sectionHeader, 'min-acceleration')/self.videoFrameRate**2 | 533 self.minAcceleration = config.getfloat(self.sectionHeader, 'min-acceleration')/self.videoFrameRate**2 |
| 530 self.maxAcceleration = config.getfloat(self.sectionHeader, 'max-acceleration')/self.videoFrameRate**2 | 534 self.maxAcceleration = config.getfloat(self.sectionHeader, 'max-acceleration')/self.videoFrameRate**2 |
| 531 self.maxSteering = config.getfloat(self.sectionHeader, 'max-steering')/self.videoFrameRate | 535 self.maxSteering = config.getfloat(self.sectionHeader, 'max-steering')/self.videoFrameRate |
| 532 self.useFeaturesForPrediction = config.getboolean(self.sectionHeader, 'use-features-prediction') | 536 self.useFeaturesForPrediction = config.getboolean(self.sectionHeader, 'use-features-prediction') |
| 533 | 537 |
| 538 class SceneParameters: | |
| 539 def __init__(self, config, sectionName): | |
| 540 from ConfigParser import NoOptionError | |
| 541 from ast import literal_eval | |
| 542 try: | |
| 543 self.sitename = config.get(sectionName, 'sitename') | |
| 544 self.databaseFilename = config.get(sectionName, 'data_filename') | |
| 545 self.homographyFilename = config.get(sectionName, 'homography_filename') | |
| 546 self.videoFilename = config.get(sectionName, 'video_filename') | |
| 547 self.date = datetime.strptime(config.get(sectionName, 'date'), "%Y-%m-%d %H:%M:%S") # 2011-06-22 11:00:39 | |
| 548 self.translation = literal_eval(config.get(sectionName, 'translation')) # = [0.0, 0.0] | |
| 549 self.rotation = config.getfloat(sectionName, 'rotation') | |
| 550 self.duration = config.getint(sectionName, 'duration') | |
| 551 except NoOptionError as e: | |
| 552 print(e) | |
| 553 print('Not a section for scene meta-data') | |
| 554 | |
| 555 @staticmethod | |
| 556 def loadConfigFile(filename): | |
| 557 from ConfigParser import ConfigParser | |
| 558 config = ConfigParser() | |
| 559 config.readfp(openCheck(filename)) | |
| 560 return [SceneParameters(config, sectionName) for sectionName in config.sections()] | |
| 561 | |
| 562 | |
| 534 ######################### | 563 ######################### |
| 535 # sqlite | 564 # sqlite |
| 536 ######################### | 565 ######################### |
| 537 | 566 |
| 538 def printDBError(error): | 567 def printDBError(error): |
