Mercurial Hosting > traffic-intelligence
annotate python/metadata.py @ 830:2a5856961933
first working version of feature merging (works with feature grouping)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 29 Jun 2016 17:56:19 -0400 |
parents | 14e4ad7c7420 |
children | 7058a40a4bbc |
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 |
821
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
3 from datetime import datetime, timedelta |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
4 from os import path |
821
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
5 from math import floor |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
6 |
828
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
7 from numpy import zeros |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
8 |
821
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
9 from sqlalchemy import orm, create_engine, Column, Integer, Float, DateTime, String, ForeignKey, Boolean, Interval |
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
|
10 from sqlalchemy.orm import relationship, backref, sessionmaker |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
11 from sqlalchemy.ext.declarative import declarative_base |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
12 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
13 from utils import datetimeFormat, removeExtension |
828
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
14 from moving import TimeInterval |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
15 |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
16 Base = declarative_base() |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
17 |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
18 class Site(Base): |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
19 __tablename__ = 'sites' |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
20 idx = Column(Integer, primary_key=True) |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
21 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
|
22 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
|
23 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
|
24 ycoordinate = Column(Float) |
805
180b6b0231c0
added saving/loading points of interests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
580
diff
changeset
|
25 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
|
26 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
|
27 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
|
28 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
29 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
|
30 self.name = name |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
31 self.description = description |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
32 self.xcoordinate = xcoordinate |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
33 self.ycoordinate = ycoordinate |
805
180b6b0231c0
added saving/loading points of interests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
580
diff
changeset
|
34 self.mapImageFilename = mapImageFilename |
180b6b0231c0
added saving/loading points of interests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
580
diff
changeset
|
35 self.nUnitsPerPixel = nUnitsPerPixel |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
36 self.worldDistanceUnit = worldDistanceUnit |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
37 |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
38 def getFilename(self): |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
39 return self.name |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
40 |
828
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
41 @staticmethod |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
42 def getSite(session, siteId): |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
43 'Returns the site(s) matching the index or the name' |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
44 if str.isdigit(siteId): |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
45 return session.query(Site).filter(Site.idx == int(siteId)).all() |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
46 else: |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
47 return session.query(Site).filter(Site.description.like('%'+siteId+'%')).all() |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
48 |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
49 |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
50 class EnvironementalFactors(Base): |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
51 '''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
|
52 * changing weather conditions |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
53 * changing road configuration, geometry, signalization, etc. |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
54 ex: sunny, rainy, before counter-measure, after counter-measure''' |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
55 __tablename__ = 'environmental_factors' |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
56 idx = Column(Integer, primary_key=True) |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
57 startTime = Column(DateTime) |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
58 endTime = Column(DateTime) |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
59 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
|
60 siteIdx = Column(Integer, ForeignKey('sites.idx')) |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
61 |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
62 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
|
63 |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
64 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
|
65 '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
|
66 self.startTime = datetime.strptime(startTime, datetimeFormat) |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
67 self.endTime = datetime.strptime(endTime, datetimeFormat) |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
68 self.description = description |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
69 self.site = site |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
70 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
71 class CameraType(Base): |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
72 ''' Represents parameters of the specific camera used. |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
73 |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
74 Taken and adapted from tvalib''' |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
75 __tablename__ = 'camera_types' |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
76 idx = Column(Integer, primary_key=True) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
77 name = Column(String) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
78 resX = Column(Integer) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
79 resY = Column(Integer) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
80 frameRate = Column(Float) |
821
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
81 frameRateTimeUnit = Column(String, default = 's') |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
82 intrinsicCameraMatrix00 = Column(Float) |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
83 intrinsicCameraMatrix01 = Column(Float) |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
84 intrinsicCameraMatrix02 = Column(Float) |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
85 intrinsicCameraMatrix10 = Column(Float) |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
86 intrinsicCameraMatrix11 = Column(Float) |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
87 intrinsicCameraMatrix12 = Column(Float) |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
88 intrinsicCameraMatrix20 = Column(Float) |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
89 intrinsicCameraMatrix21 = Column(Float) |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
90 intrinsicCameraMatrix22 = Column(Float) |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
91 distortionCoefficients0 = Column(Float) |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
92 distortionCoefficients1 = Column(Float) |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
93 distortionCoefficients2 = Column(Float) |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
94 distortionCoefficients3 = Column(Float) |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
95 distortionCoefficients4 = Column(Float) |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
96 undistortedImageMultiplication = Column(Float) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
97 |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
98 def __init__(self, name, resX, resY, frameRate, frameRateTimeUnit = 's', trackingConfigurationFilename = None, intrinsicCameraMatrix = None, distortionCoefficients = None, undistortedImageMultiplication = None): |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
99 self.name = name |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
100 self.resX = resX |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
101 self.resY = resY |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
102 self.frameRate = frameRate |
821
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
103 self.frameRateTimeUnit = frameRateTimeUnit |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
104 |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
105 if trackingConfigurationFilename is not None: |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
106 from storage import ProcessParameters |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
107 params = ProcessParameters(trackingConfigurationFilename) |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
108 self.intrinsicCameraMatrix = params.intrinsicCameraMatrix |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
109 self.distortionCoefficients = params.distortionCoefficients |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
110 self.undistortedImageMultiplication = params.undistortedImageMultiplication |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
111 else: |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
112 self.intrinsicCameraMatrix = intrinsicCameraMatrix |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
113 self.distortionCoefficients = distortionCoefficients |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
114 self.undistortedImageMultiplication = undistortedImageMultiplication |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
115 |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
116 if self.intrinsicCameraMatrix is not None and self.intrinsicCameraMatrix.size == 9: |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
117 self.intrinsicCameraMatrix00 = self.intrinsicCameraMatrix[0,0] |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
118 self.intrinsicCameraMatrix01 = self.intrinsicCameraMatrix[0,1] |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
119 self.intrinsicCameraMatrix02 = self.intrinsicCameraMatrix[0,2] |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
120 self.intrinsicCameraMatrix10 = self.intrinsicCameraMatrix[1,0] |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
121 self.intrinsicCameraMatrix11 = self.intrinsicCameraMatrix[1,1] |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
122 self.intrinsicCameraMatrix12 = self.intrinsicCameraMatrix[1,2] |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
123 self.intrinsicCameraMatrix20 = self.intrinsicCameraMatrix[2,0] |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
124 self.intrinsicCameraMatrix21 = self.intrinsicCameraMatrix[2,1] |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
125 self.intrinsicCameraMatrix22 = self.intrinsicCameraMatrix[2,2] |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
126 if self.distortionCoefficients is not None and len(self.distortionCoefficients) == 5: |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
127 self.distortionCoefficients0 = self.distortionCoefficients[0] |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
128 self.distortionCoefficients1 = self.distortionCoefficients[1] |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
129 self.distortionCoefficients2 = self.distortionCoefficients[2] |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
130 self.distortionCoefficients3 = self.distortionCoefficients[3] |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
131 self.distortionCoefficients4 = self.distortionCoefficients[4] |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
132 |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
133 @orm.reconstructor |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
134 def initOnLoad(self): |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
135 if self.intrinsicCameraMatrix00 is not None: |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
136 self.intrinsicCameraMatrix = zeros((3,3)) |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
137 self.intrinsicCameraMatrix[0,0] = self.intrinsicCameraMatrix00 |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
138 self.intrinsicCameraMatrix[0,1] = self.intrinsicCameraMatrix01 |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
139 self.intrinsicCameraMatrix[0,2] = self.intrinsicCameraMatrix02 |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
140 self.intrinsicCameraMatrix[1,0] = self.intrinsicCameraMatrix10 |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
141 self.intrinsicCameraMatrix[1,1] = self.intrinsicCameraMatrix11 |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
142 self.intrinsicCameraMatrix[1,2] = self.intrinsicCameraMatrix12 |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
143 self.intrinsicCameraMatrix[2,0] = self.intrinsicCameraMatrix20 |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
144 self.intrinsicCameraMatrix[2,1] = self.intrinsicCameraMatrix21 |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
145 self.intrinsicCameraMatrix[2,2] = self.intrinsicCameraMatrix22 |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
146 else: |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
147 self.intrinsicCameraMatrix = None |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
148 if self.distortionCoefficients0 is not None: |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
149 self.distortionCoefficients = [0]*5 |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
150 self.distortionCoefficients[0] = self.distortionCoefficients0 |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
151 self.distortionCoefficients[1] = self.distortionCoefficients1 |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
152 self.distortionCoefficients[2] = self.distortionCoefficients2 |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
153 self.distortionCoefficients[3] = self.distortionCoefficients3 |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
154 self.distortionCoefficients[4] = self.distortionCoefficients4 |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
155 else: |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
156 self.distortionCoefficients = None |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
157 |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
158 class CameraView(Base): |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
159 __tablename__ = 'camera_views' |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
160 idx = Column(Integer, primary_key=True) |
821
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
161 description = Column(String) |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
162 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
|
163 siteIdx = Column(Integer, ForeignKey('sites.idx')) |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
164 cameraTypeIdx = Column(Integer, ForeignKey('camera_types.idx')) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
165 trackingConfigurationFilename = Column(String) # path to configuration .cfg file, relative to site name |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
166 maskFilename = Column(String) # path to mask file, relative to site name |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
167 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
168 site = relationship("Site", backref=backref('sites', order_by = idx)) |
821
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
169 cameraType = 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
|
170 |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
171 def __init__(self, description, homographyFilename, site, cameraType, trackingConfigurationFilename, maskFilename): |
821
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
172 self.description = description |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
173 self.homographyFilename = homographyFilename |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
174 self.site = site |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
175 self.cameraType = cameraType |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
176 self.trackingConfigurationFilename = trackingConfigurationFilename |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
177 self.maskFilename = maskFilename |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
178 |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
179 def getHomographyFilename(self, relativeToSiteFilename = True): |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
180 if relativeToSiteFilename: |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
181 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
|
182 else: |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
183 return self.homographyFilename |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
184 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
185 def getTrackingConfigurationFilename(self, relativeToSiteFilename = True): |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
186 if relativeToSiteFilename: |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
187 return self.site.getFilename()+path.sep+self.trackingConfigurationFilename |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
188 else: |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
189 return self.trackingConfigurationFilename |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
190 |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
191 def getMaskFilename(self, relativeToSiteFilename = True): |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
192 if relativeToSiteFilename: |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
193 return self.site.getFilename()+path.sep+self.maskFilename |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
194 else: |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
195 return self.maskFilename |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
196 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
197 def getTrackingParameters(self): |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
198 return ProcessParameters(self.getTrackingConfigurationFilename()) |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
199 |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
200 def getHomographyDistanceUnit(self): |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
201 return self.site.worldDistanceUnit |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
202 |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
203 class Alignment(Base): |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
204 __tablename__ = 'alignments' |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
205 idx = Column(Integer, primary_key=True) |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
206 cameraViewIdx = Column(Integer, ForeignKey('camera_views.idx')) |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
207 |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
208 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
|
209 |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
210 def __init__(self, cameraView): |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
211 self.cameraView = cameraView |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
212 |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
213 class Point(Base): |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
214 __tablename__ = 'points' |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
215 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
|
216 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
|
217 x = Column(Float) |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
218 y = Column(Float) |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
219 |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
220 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
|
221 |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
222 def __init__(self, alignmentIdx, index, x, y): |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
223 self.alignmentIdx = alignmentIdx |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
224 self.index = index |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
225 self.x = x |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
226 self.y = y |
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
227 |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
228 class VideoSequence(Base): |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
229 __tablename__ = 'video_sequences' |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
230 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
|
231 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
|
232 startTime = Column(DateTime) |
821
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
233 duration = Column(Interval) # video sequence duration |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
234 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
|
235 cameraViewIdx = Column(Integer, ForeignKey('camera_views.idx')) |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
236 |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
237 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
|
238 |
830
2a5856961933
first working version of feature merging (works with feature grouping)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
828
diff
changeset
|
239 def __init__(self, name, startTime, duration, cameraView, databaseFilename = None): |
821
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
240 '''startTime is passed as string in utils.datetimeFormat, eg 2011-06-22 10:00:39 |
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
241 duration is a timedelta object''' |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
242 self.name = name |
828
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
243 if isinstance(startTime, str): |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
244 self.startTime = datetime.strptime(startTime, datetimeFormat) |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
245 else: |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
246 self.startTime = startTime |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
247 self.duration = duration |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
248 self.cameraView = cameraView |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
249 if databaseFilename is None and len(self.name) > 0: |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
250 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
|
251 |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
252 def getVideoSequenceFilename(self, relativeToSiteFilename = True): |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
253 if relativeToSiteFilename: |
830
2a5856961933
first working version of feature merging (works with feature grouping)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
828
diff
changeset
|
254 return self.cameraView.site.getFilename()+path.sep+self.name |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
255 else: |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
256 return self.name |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
257 |
830
2a5856961933
first working version of feature merging (works with feature grouping)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
828
diff
changeset
|
258 def getDatabaseFilename(self, relativeToSiteFilename = True): |
2a5856961933
first working version of feature merging (works with feature grouping)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
828
diff
changeset
|
259 if relativeToSiteFilename: |
2a5856961933
first working version of feature merging (works with feature grouping)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
828
diff
changeset
|
260 return self.cameraView.site.getFilename()+path.sep+self.databaseFilename |
2a5856961933
first working version of feature merging (works with feature grouping)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
828
diff
changeset
|
261 else: |
2a5856961933
first working version of feature merging (works with feature grouping)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
828
diff
changeset
|
262 return self.databaseFilename |
2a5856961933
first working version of feature merging (works with feature grouping)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
828
diff
changeset
|
263 |
828
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
264 def getTimeInterval(self): |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
265 return TimeInterval(self.startTime, self.startTime+self.duration) |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
266 |
821
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
267 def containsInstant(self, instant): |
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
268 'instant is a datetime' |
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
269 return self.startTime <= instant and self.startTime+self.duration |
828
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
270 |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
271 def intersection(self, startTime, endTime): |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
272 'returns the moving.TimeInterval intersection with [startTime, endTime]' |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
273 return TimeInterval.intersection(self.getTimeInterval(), TimeInterval(startTime, endTime)) |
821
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
274 |
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
275 def getFrameNum(self, instant): |
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
276 'Warning, there is no check of correct time units' |
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
277 if self.containsInstant(instant): |
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
278 return int(floor((instant-self.startTime).seconds*self.cameraView.cameraType.frameRate)) |
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
279 else: |
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
280 return None |
424 | 281 |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
282 # 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
|
283 |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
284 # 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
|
285 |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
286 # 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
|
287 # eg bounding box depends on camera view, tracking configuration depends on camera view |
424 | 288 # results: sqlite |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
289 |
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
|
290 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
|
291 '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
|
292 engine = create_engine('sqlite:///'+filename) |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
293 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
|
294 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
|
295 return Session() |
425
a31dde19caa8
connect function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
424
diff
changeset
|
296 |
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
|
297 def connectDatabase(filename): |
425
a31dde19caa8
connect function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
424
diff
changeset
|
298 'creates a session to query the filename' |
a31dde19caa8
connect function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
424
diff
changeset
|
299 engine = create_engine('sqlite:///'+filename) |
a31dde19caa8
connect function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
424
diff
changeset
|
300 Session = sessionmaker(bind=engine) |
a31dde19caa8
connect function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
424
diff
changeset
|
301 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
|
302 |
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
|
303 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
|
304 '''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
|
305 |
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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 # TODO crawler for video files? |