Mercurial Hosting > traffic-intelligence
annotate python/metadata.py @ 819:fc8b3ce629d1
important modifications to metadata
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 22 Jun 2016 14:51:00 -0400 |
parents | 180b6b0231c0 |
children | 26daf35180ad |
rev | line source |
---|---|
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
1 # from moving import Point |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
2 |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
3 from datetime import datetime |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
4 from os import path |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
5 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
6 from sqlalchemy import orm, create_engine, Column, Integer, Float, DateTime, String, ForeignKey, Boolean |
426
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
7 from sqlalchemy.orm import relationship, backref, sessionmaker |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
8 from sqlalchemy.ext.declarative import declarative_base |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
9 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
10 from utils import datetimeFormat, removeExtension |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
11 |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
12 Base = declarative_base() |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
13 |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
14 class Site(Base): |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
15 __tablename__ = 'sites' |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
16 idx = Column(Integer, primary_key=True) |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
17 name = Column(String) # same as path, relative to the database position |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
18 description = Column(String) # longer names, eg intersection of road1 and road2 |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
19 xcoordinate = Column(Float) # ideally moving.Point, but needs to be |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
20 ycoordinate = Column(Float) |
805
180b6b0231c0
added saving/loading points of interests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
580
diff
changeset
|
21 mapImageFilename = Column(String) # path to filename, relative to site name, ie sitename/mapImageFilename |
180b6b0231c0
added saving/loading points of interests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
580
diff
changeset
|
22 nUnitsPerPixel = Column(Float) # number of units of distance per pixel in map image |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
23 worldDistanceUnit = Column(String, default = 'm') # make sure it is default in the database |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
24 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
25 def __init__(self, name, description = "", xcoordinate = None, ycoordinate = None, mapImageFilename = None, nUnitsPerPixel = 1., worldDistanceUnit = 'm'): |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
26 self.name = name |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
27 self.description = description |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
28 self.xcoordinate = xcoordinate |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
29 self.ycoordinate = ycoordinate |
805
180b6b0231c0
added saving/loading points of interests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
580
diff
changeset
|
30 self.mapImageFilename = mapImageFilename |
180b6b0231c0
added saving/loading points of interests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
580
diff
changeset
|
31 self.nUnitsPerPixel = nUnitsPerPixel |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
32 self.worldDistanceUnit = worldDistanceUnit |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
33 |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
34 def getFilename(self): |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
35 return self.name |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
36 |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
37 class EnvironementalFactors(Base): |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
38 '''Represents any environmental factors that may affect the results, in particular |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
39 * changing weather conditions |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
40 * changing road configuration, geometry, signalization, etc. |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
41 ex: sunny, rainy, before counter-measure, after counter-measure''' |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
42 __tablename__ = 'environmental_factors' |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
43 idx = Column(Integer, primary_key=True) |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
44 startTime = Column(DateTime) |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
45 endTime = Column(DateTime) |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
46 description = Column(String) # eg sunny, before, after |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
47 siteIdx = Column(Integer, ForeignKey('sites.idx')) |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
48 |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
49 site = relationship("Site", backref=backref('environmental_factors', order_by = idx)) |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
50 |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
51 def __init__(self, startTime, endTime, description, site): |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
52 'startTime is passed as string in utils.datetimeFormat, eg 2011-06-22 10:00:39' |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
53 self.startTime = datetime.strptime(startTime, datetimeFormat) |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
54 self.endTime = datetime.strptime(endTime, datetimeFormat) |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
55 self.description = description |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
56 self.site = site |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
57 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
58 class CameraType(Base): |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
59 ''' Represents parameters of the specific camera used. |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
60 |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
61 Taken and adapted from tvalib''' |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
62 __tablename__ = 'camera_types' |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
63 idx = Column(Integer, primary_key=True) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
64 name = Column(String) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
65 resX = Column(Integer) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
66 resY = Column(Integer) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
67 frameRate = Column(Float) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
68 undistort = Column(Boolean) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
69 intrinsicCameraMatrixStr = Column(String) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
70 distortionCoefficientsStr = Column(String) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
71 undistortedImageMultiplication = Column(Float) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
72 |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
73 def __init__(self, name, resX, resY, frameRate, trackingConfigurationFilename = None, undistort = None, intrinsicCameraMatrix = None, distortionCoefficients = None, undistortedImageMultiplication = None): |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
74 self.name = name |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
75 self.resX = resX |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
76 self.resY = resY |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
77 self.frameRate = frameRate |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
78 self.undistort = False |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
79 |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
80 if trackingConfigurationFilename is not None: |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
81 from storage import ProcessParameters |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
82 params = ProcessParameters(trackingConfigurationFilename) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
83 if params.undistort: |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
84 self.undistort = params.undistort |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
85 self.intrinsicCameraMatrix = params.intrinsicCameraMatrix |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
86 self.distortionCoefficients = params.distortionCoefficients |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
87 self.undistortedImageMultiplication = params.undistortedImageMultiplication |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
88 elif undistort is not None: |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
89 self.undistort = undistort |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
90 self.intrinsicCameraMatrix = intrinsicCameraMatrix |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
91 self.distortionCoefficients = distortionCoefficients |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
92 self.undistortedImageMultiplication = undistortedImageMultiplication |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
93 |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
94 # populate the db |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
95 if self.intrinsicCameraMatrix is not None and self.distortionCoefficients is not None: |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
96 self.intrinsicCameraMatrixStr = ' '.join('{}'.format(x) for x in self.intrinsicCameraMatrix.flatten('C')) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
97 self.distortionCoefficientsStr = ' '.join('{}'.format(x)for x in self.distortionCoefficients) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
98 |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
99 @orm.reconstructor |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
100 def initOnLoad(self): |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
101 from numpy import array |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
102 if len(self.intrinsicCameraMatrixStr) > 0: |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
103 self.intrinsicCameraMatrix = array([float(x) for x in self.intrinsicCameraMatrixStr.split(" ")]).reshape(3,3) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
104 if len(self.distortionCoefficientsStr) > 0: |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
105 self.distortionCoefficients = [float(x) for x in self.distortionCoefficientsStr.split(" ")] |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
106 |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
107 class CameraView(Base): |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
108 __tablename__ = 'camera_views' |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
109 idx = Column(Integer, primary_key=True) |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
110 homographyFilename = Column(String) # path to homograph filename, relative to the site name |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
111 siteIdx = Column(Integer, ForeignKey('sites.idx')) |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
112 cameraTypeIdx = Column(Integer, ForeignKey('camera_types.idx')) |
424 | 113 homographyDistanceUnit = Column(String, default = 'm') # make sure it is default in the database |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
114 trackingConfigurationFilename = Column(String) # path to configuration .cfg file, relative to site name |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
115 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
116 site = relationship("Site", backref=backref('sites', order_by = idx)) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
117 camera = relationship('CameraType', backref=backref('camera_views', order_by = idx)) |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
118 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
119 def __init__(self, homographyFilename, site, cameraType, trackingConfigurationFilename): |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
120 self.homographyFilename = homographyFilename |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
121 self.site = site |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
122 self.cameraType = cameraType |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
123 self.trackingConfigurationFilename = trackingConfigurationFilename |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
124 |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
125 def getHomographyFilename(self, relativeToSiteFilename = True): |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
126 if relativeToSiteFilename: |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
127 return self.site.getFilename()+path.sep+self.homographyFilename |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
128 else: |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
129 return self.homographyFilename |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
130 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
131 def getTrackingConfigurationFilename(self, relativeToSiteFilename = True): |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
132 if relativeToSiteFilename: |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
133 return self.site.getFilename()+path.sep+self.trackingConfigurationFilename |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
134 else: |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
135 return self.trackingConfigurationFilename |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
136 |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
137 def getTrackingParameters(self): |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
138 return ProcessParameters(getTrackingConfigurationFilename()) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
139 |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
140 class Alignment(Base): |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
141 __tablename__ = 'alignments' |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
142 idx = Column(Integer, primary_key=True) |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
143 cameraViewIdx = Column(Integer, ForeignKey('camera_views.idx')) |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
144 |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
145 cameraView = relationship("CameraView", backref=backref('alignments', order_by = idx)) |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
146 |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
147 def __init__(self, cameraView): |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
148 self.cameraView = cameraView |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
149 |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
150 class Point(Base): |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
151 __tablename__ = 'points' |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
152 alignmentIdx = Column(Integer, ForeignKey('alignments.idx'), primary_key=True) |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
153 index = Column(Integer, primary_key=True) # order of points in this alignment |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
154 x = Column(Float) |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
155 y = Column(Float) |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
156 |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
157 alignment = relationship("Alignment", backref=backref('points', order_by = index)) |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
158 |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
159 def __init__(self, alignmentIdx, index, x, y): |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
160 self.alignmentIdx = alignmentIdx |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
161 self.index = index |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
162 self.x = x |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
163 self.y = y |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
164 |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
165 class VideoSequence(Base): |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
166 __tablename__ = 'video_sequences' |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
167 idx = Column(Integer, primary_key=True) |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
168 name = Column(String) # path relative to the the site name |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
169 startTime = Column(DateTime) |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
170 duration = Column(Float) # video sequence duration |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
171 durationUnit = Column(String, default = 's') |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
172 databaseFilename = Column(String) # path relative to the the site name |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
173 siteIdx = Column(Integer, ForeignKey('sites.idx')) |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
174 cameraViewIdx = Column(Integer, ForeignKey('camera_views.idx')) |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
175 |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
176 site = relationship("Site", backref=backref('video_sequences', order_by = idx)) |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
177 cameraView = relationship("CameraView", backref=backref('video_sequences', order_by = idx)) |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
178 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
179 def __init__(self, name, startTime, duration, site, cameraView, databaseFilename = None): |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
180 'startTime is passed as string in utils.datetimeFormat, eg 2011-06-22 10:00:39' |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
181 self.name = name |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
182 self.startTime = datetime.strptime(startTime, datetimeFormat) |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
183 self.duration = duration |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
184 self.site = site |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
185 self.cameraView = cameraView |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
186 if databaseFilename is None and len(self.name) > 0: |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
187 self.databaseFilename = removeExtension(self.name)+'.sqlite' |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
188 |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
189 def getVideoSequenceFilename(self, relativeToSiteFilename = True): |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
190 if relativeToSiteFilename: |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
191 return self.site.getFilename()+path.sep+self.name |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
192 else: |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
193 return self.name |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
194 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
195 |
424 | 196 |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
197 # add class for Analysis: foreign key VideoSequenceId, dataFilename, configFilename (get the one from camera view by default), mask? (no, can be referenced in the tracking cfg file) |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
198 |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
199 # class SiteDescription(Base): # list of lines and polygons describing the site, eg for sidewalks, center lines |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
200 |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
201 # class Analysis(Base): # parameters necessary for processing the data: free form |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
202 # eg bounding box depends on camera view, tracking configuration depends on camera view |
424 | 203 # results: sqlite |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
204 |
426
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
205 def createDatabase(filename): |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
206 'creates a session to query the filename' |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
207 engine = create_engine('sqlite:///'+filename) |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
208 Base.metadata.create_all(engine) |
426
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
209 Session = sessionmaker(bind=engine) |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
210 return Session() |
425
a31dde19caa8
connect function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
424
diff
changeset
|
211 |
426
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
212 def connectDatabase(filename): |
425
a31dde19caa8
connect function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
424
diff
changeset
|
213 'creates a session to query the filename' |
a31dde19caa8
connect function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
424
diff
changeset
|
214 engine = create_engine('sqlite:///'+filename) |
a31dde19caa8
connect function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
424
diff
changeset
|
215 Session = sessionmaker(bind=engine) |
a31dde19caa8
connect function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
424
diff
changeset
|
216 return Session() |
426
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
217 |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
218 def initializeSites(session, directoryName): |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
219 '''Initializes default site objects and Camera Views |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
220 |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
221 eg somedirectory/montreal/ contains intersection1, intersection2, etc. |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
222 The site names would be somedirectory/montreal/intersection1, somedirectory/montreal/intersection2, etc.''' |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
223 from os import listdir, path |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
224 sites = [] |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
225 cameraViews = [] |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
226 names = listdir(directoryName) |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
227 for name in names: |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
228 if path.isdir(directoryName+'/'+name): |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
229 sites.append(Site(directoryName+'/'+name, None)) |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
230 cameraViews.append(CameraView(-1, None, None, sites[-1], None)) |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
231 session.add_all(sites) |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
232 session.add_all(cameraViews) |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
233 session.commit() |
334e1151828b
corrected creation and connection to database + helper function to generate sites and camera views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
425
diff
changeset
|
234 # TODO crawler for video files? |