Mercurial Hosting > traffic-intelligence
changeset 421:4fce27946c60
first example of video metadata using sqlalchemy
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 09 Oct 2013 23:25:51 -0400 |
parents | def795d1120f |
children | 67c7ff5d6b26 |
files | python/metadata.py python/utils.py |
diffstat | 2 files changed, 35 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/python/metadata.py Tue Oct 08 18:26:20 2013 -0400 +++ b/python/metadata.py Wed Oct 09 23:25:51 2013 -0400 @@ -1,9 +1,13 @@ # from moving import Point -from sqlalchemy import create_engine, Column, Integer, Float, DateTime, String, ForeignKey +from datetime import datetime + +from sqlalchemy import Column, Integer, Float, DateTime, String, ForeignKey from sqlalchemy.orm import relationship, backref from sqlalchemy.ext.declarative import declarative_base +from utils import datetimeFormat + Base = declarative_base() class Site(Base): @@ -37,19 +41,31 @@ site = relationship("Site", backref=backref('environmental_factors', order_by = id)) + def __init__(self, startTime, endTime, description, site): + 'startTime is passed as string in utils.datetimeFormat, eg 2011-06-22 10:00:39' + self.startTime = datetime.strptime(startTime, datetimeFormat) + self.endTime = datetime.strptime(endTime, datetimeFormat) + self.description = description + self.site = site + class CameraView(Base): __tablename__ = 'camera_views' id = Column(Integer, primary_key=True) frameRate = Column(Float) homographyFilename = Column(String) # path to homograph filename, relative to SiteId siteId = Column(Integer, ForeignKey('sites.id')) + # add distanceUnit related to homography? site = relationship("Site", backref=backref('camera_views', order_by = id)) + def __init__(self, frameRate, homographyFilename, site): + self.frameRate = frameRate + self.homographyFilename = homographyFilename + self.site = site + class VideoSequence(Base): __tablename__ = 'video_sequences' id = Column(Integer, primary_key=True) - startTime = Column(DateTime) name = Column(String) # path that can be composed with the site name startTime = Column(DateTime) duration = Column(Float) # video sequence duration @@ -59,4 +75,18 @@ site = relationship("Site", backref=backref('video_sequences', order_by = id)) cameraView = relationship("CameraView", backref=backref('video_sequences', order_by = id)) + def __init__(self, name, startTime, duration, site, cameraView): + 'startTime is passed as string in utils.datetimeFormat, eg 2011-06-22 10:00:39' + self.name = name + self.startTime = datetime.strptime(startTime, datetimeFormat) + self.duration = duration + self.site = site + self.cameraView = cameraView + # class SiteDescription(Base): # list of lines and polygons describing the site, eg for sidewalks, center lines + +# class Analysis(Base): # parameters necessary for processing the data: free form +# eg bounding box depends on camera view, tracking configuration depends on camera view + +def createDatabases(engine): + Base.metadata.create_all(engine)
--- a/python/utils.py Tue Oct 08 18:26:20 2013 -0400 +++ b/python/utils.py Wed Oct 09 23:25:51 2013 -0400 @@ -11,6 +11,8 @@ delimiterChar = '%'; +datetimeFormat = "%Y-%m-%d %H:%M:%S" + ######################### # Enumerations ######################### @@ -546,7 +548,7 @@ self.calibrationFilename = config.get(sectionName, 'calibration-filename') self.videoFilename = config.get(sectionName, 'video-filename') self.frameRate = config.getfloat(sectionName, 'framerate') - self.date = datetime.strptime(config.get(sectionName, 'date'), "%Y-%m-%d %H:%M:%S") # 2011-06-22 11:00:39 + self.date = datetime.strptime(config.get(sectionName, 'date'), datetimeFormat) # 2011-06-22 11:00:39 self.translation = literal_eval(config.get(sectionName, 'translation')) # = [0.0, 0.0] self.rotation = config.getfloat(sectionName, 'rotation') self.duration = config.getint(sectionName, 'duration')