Mercurial > hg > nsaunier > traffic-intelligence
comparison python/metadata.py @ 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 |
comparison
equal
deleted
inserted
replaced
| 420:def795d1120f | 421:4fce27946c60 |
|---|---|
| 1 # from moving import Point | 1 # from moving import Point |
| 2 | 2 |
| 3 from sqlalchemy import create_engine, Column, Integer, Float, DateTime, String, ForeignKey | 3 from datetime import datetime |
| 4 | |
| 5 from sqlalchemy import Column, Integer, Float, DateTime, String, ForeignKey | |
| 4 from sqlalchemy.orm import relationship, backref | 6 from sqlalchemy.orm import relationship, backref |
| 5 from sqlalchemy.ext.declarative import declarative_base | 7 from sqlalchemy.ext.declarative import declarative_base |
| 8 | |
| 9 from utils import datetimeFormat | |
| 6 | 10 |
| 7 Base = declarative_base() | 11 Base = declarative_base() |
| 8 | 12 |
| 9 class Site(Base): | 13 class Site(Base): |
| 10 __tablename__ = 'sites' | 14 __tablename__ = 'sites' |
| 35 description = Column(String) # eg sunny, before, after | 39 description = Column(String) # eg sunny, before, after |
| 36 siteId = Column(Integer, ForeignKey('sites.id')) | 40 siteId = Column(Integer, ForeignKey('sites.id')) |
| 37 | 41 |
| 38 site = relationship("Site", backref=backref('environmental_factors', order_by = id)) | 42 site = relationship("Site", backref=backref('environmental_factors', order_by = id)) |
| 39 | 43 |
| 44 def __init__(self, startTime, endTime, description, site): | |
| 45 'startTime is passed as string in utils.datetimeFormat, eg 2011-06-22 10:00:39' | |
| 46 self.startTime = datetime.strptime(startTime, datetimeFormat) | |
| 47 self.endTime = datetime.strptime(endTime, datetimeFormat) | |
| 48 self.description = description | |
| 49 self.site = site | |
| 50 | |
| 40 class CameraView(Base): | 51 class CameraView(Base): |
| 41 __tablename__ = 'camera_views' | 52 __tablename__ = 'camera_views' |
| 42 id = Column(Integer, primary_key=True) | 53 id = Column(Integer, primary_key=True) |
| 43 frameRate = Column(Float) | 54 frameRate = Column(Float) |
| 44 homographyFilename = Column(String) # path to homograph filename, relative to SiteId | 55 homographyFilename = Column(String) # path to homograph filename, relative to SiteId |
| 45 siteId = Column(Integer, ForeignKey('sites.id')) | 56 siteId = Column(Integer, ForeignKey('sites.id')) |
| 57 # add distanceUnit related to homography? | |
| 46 | 58 |
| 47 site = relationship("Site", backref=backref('camera_views', order_by = id)) | 59 site = relationship("Site", backref=backref('camera_views', order_by = id)) |
| 60 | |
| 61 def __init__(self, frameRate, homographyFilename, site): | |
| 62 self.frameRate = frameRate | |
| 63 self.homographyFilename = homographyFilename | |
| 64 self.site = site | |
| 48 | 65 |
| 49 class VideoSequence(Base): | 66 class VideoSequence(Base): |
| 50 __tablename__ = 'video_sequences' | 67 __tablename__ = 'video_sequences' |
| 51 id = Column(Integer, primary_key=True) | 68 id = Column(Integer, primary_key=True) |
| 52 startTime = Column(DateTime) | |
| 53 name = Column(String) # path that can be composed with the site name | 69 name = Column(String) # path that can be composed with the site name |
| 54 startTime = Column(DateTime) | 70 startTime = Column(DateTime) |
| 55 duration = Column(Float) # video sequence duration | 71 duration = Column(Float) # video sequence duration |
| 56 siteId = Column(Integer, ForeignKey('sites.id')) | 72 siteId = Column(Integer, ForeignKey('sites.id')) |
| 57 cameraViewId = Column(Integer, ForeignKey('camera_views.id')) | 73 cameraViewId = Column(Integer, ForeignKey('camera_views.id')) |
| 58 | 74 |
| 59 site = relationship("Site", backref=backref('video_sequences', order_by = id)) | 75 site = relationship("Site", backref=backref('video_sequences', order_by = id)) |
| 60 cameraView = relationship("CameraView", backref=backref('video_sequences', order_by = id)) | 76 cameraView = relationship("CameraView", backref=backref('video_sequences', order_by = id)) |
| 61 | 77 |
| 78 def __init__(self, name, startTime, duration, site, cameraView): | |
| 79 'startTime is passed as string in utils.datetimeFormat, eg 2011-06-22 10:00:39' | |
| 80 self.name = name | |
| 81 self.startTime = datetime.strptime(startTime, datetimeFormat) | |
| 82 self.duration = duration | |
| 83 self.site = site | |
| 84 self.cameraView = cameraView | |
| 85 | |
| 62 # class SiteDescription(Base): # list of lines and polygons describing the site, eg for sidewalks, center lines | 86 # class SiteDescription(Base): # list of lines and polygons describing the site, eg for sidewalks, center lines |
| 87 | |
| 88 # class Analysis(Base): # parameters necessary for processing the data: free form | |
| 89 # eg bounding box depends on camera view, tracking configuration depends on camera view | |
| 90 | |
| 91 def createDatabases(engine): | |
| 92 Base.metadata.create_all(engine) |
