Mercurial Hosting > traffic-intelligence
annotate python/metadata.py @ 979:cc89267b5ff9
work on learning and assigning
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 19 Feb 2018 10:47:19 -0500 |
parents | b50145235f9e |
children | 75601be6019f |
rev | line source |
---|---|
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
|
1 from datetime import datetime, timedelta |
969
5d788d2e8ffc
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
968
diff
changeset
|
2 from os import path, listdir, sep |
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 math import floor |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
4 |
861
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
5 from numpy import zeros, loadtxt, array |
828
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
6 |
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
|
7 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
|
8 from sqlalchemy.orm import relationship, backref, sessionmaker |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
9 from sqlalchemy.ext.declarative import declarative_base |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
10 |
971
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
11 from utils import datetimeFormat, removeExtension, getExtension, TimeConverter |
970
bf401567a933
work on initializing videos for metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
969
diff
changeset
|
12 from cvutils import computeUndistortMaps, videoFilenameExtensions, infoVideo |
828
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
13 from moving import TimeInterval |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
14 |
866
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
15 """ |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
16 Metadata to describe how video data and configuration files for video analysis are stored |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
17 |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
18 Typical example is |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
19 |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
20 site1/view1/2012-06-01/video.avi |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
21 /2012-06-02/video.avi |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
22 ... |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
23 /view2/2012-06-01/video.avi |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
24 /2012-06-02/video.avi |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
25 ... |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
26 |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
27 - where site1 is the path to the directory containing all information pertaining to the site, |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
28 relative to directory of the SQLite file storing the metadata |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
29 represented by Site class |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
30 (can contain for example the aerial or map image of the site, used for projection) |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
31 |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
32 - view1 is the directory for the first camera field of view (camera fixed position) at site site1 |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
33 represented by CameraView class |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
34 (can contain for example the homography file, mask file and tracking configuration file) |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
35 |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
36 - YYYY-MM-DD is the directory containing all the video files for that day |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
37 with camera view view1 at site site1 |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
38 |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
39 |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
40 """ |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
41 |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
42 Base = declarative_base() |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
43 |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
44 class Site(Base): |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
45 __tablename__ = 'sites' |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
46 idx = Column(Integer, primary_key=True) |
865
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
47 name = Column(String) # path to directory containing all site information (in subdirectories), relative to the database position |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
48 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
|
49 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
|
50 ycoordinate = Column(Float) |
865
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
51 mapImageFilename = Column(String) # path to map image file, relative to site name, ie sitename/mapImageFilename |
805
180b6b0231c0
added saving/loading points of interests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
580
diff
changeset
|
52 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
|
53 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
|
54 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
55 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
|
56 self.name = name |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
57 self.description = description |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
58 self.xcoordinate = xcoordinate |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
59 self.ycoordinate = ycoordinate |
805
180b6b0231c0
added saving/loading points of interests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
580
diff
changeset
|
60 self.mapImageFilename = mapImageFilename |
180b6b0231c0
added saving/loading points of interests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
580
diff
changeset
|
61 self.nUnitsPerPixel = nUnitsPerPixel |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
62 self.worldDistanceUnit = worldDistanceUnit |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
63 |
865
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
64 def getPath(self): |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
65 return self.name |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
66 |
865
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
67 def getMapImageFilename(self, relativeToSiteFilename = True): |
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
68 if relativeToSiteFilename: |
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
69 return path.join(self.getPath(), self.mapImageFilename) |
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
70 else: |
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
71 return self.mapImageFilename |
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
72 |
828
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
73 |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
74 class EnvironementalFactors(Base): |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
75 '''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
|
76 * changing weather conditions |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
77 * changing road configuration, geometry, signalization, etc. |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
78 ex: sunny, rainy, before counter-measure, after counter-measure''' |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
79 __tablename__ = 'environmental_factors' |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
80 idx = Column(Integer, primary_key=True) |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
81 startTime = Column(DateTime) |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
82 endTime = Column(DateTime) |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
83 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
|
84 siteIdx = Column(Integer, ForeignKey('sites.idx')) |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
85 |
955
a15e843af55a
correcting errors in metadata names for backrefs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
872
diff
changeset
|
86 site = relationship("Site", backref = backref('environmentalFactors')) |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
87 |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
88 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
|
89 '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
|
90 self.startTime = datetime.strptime(startTime, datetimeFormat) |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
91 self.endTime = datetime.strptime(endTime, datetimeFormat) |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
92 self.description = description |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
93 self.site = site |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
94 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
95 class CameraType(Base): |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
96 ''' Represents parameters of the specific camera used. |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
97 |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
98 Taken and adapted from tvalib''' |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
99 __tablename__ = 'camera_types' |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
100 idx = Column(Integer, primary_key=True) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
101 name = Column(String) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
102 resX = Column(Integer) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
103 resY = Column(Integer) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
104 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
|
105 frameRateTimeUnit = Column(String, default = 's') |
861
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
106 intrinsicCameraMatrixStr = Column(String) |
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
107 distortionCoefficientsStr = Column(String) |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
108 |
957
5d9899504977
removed unnecessary field undistortedImageMultiplication
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
955
diff
changeset
|
109 def __init__(self, name, resX, resY, frameRate, frameRateTimeUnit = 's', trackingConfigurationFilename = None, intrinsicCameraFilename = None, intrinsicCameraMatrix = None, distortionCoefficients = None): |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
110 self.name = name |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
111 self.resX = resX |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
112 self.resY = resY |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
113 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
|
114 self.frameRateTimeUnit = frameRateTimeUnit |
861
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
115 self.intrinsicCameraMatrix = None # should be np.array |
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
116 self.distortionCoefficients = None # list |
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
117 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
118 if trackingConfigurationFilename is not None: |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
119 from storage import ProcessParameters |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
120 params = ProcessParameters(trackingConfigurationFilename) |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
121 self.intrinsicCameraMatrix = params.intrinsicCameraMatrix |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
122 self.distortionCoefficients = params.distortionCoefficients |
861
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
123 elif intrinsicCameraFilename is not None: |
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
124 self.intrinsicCameraMatrix = loadtxt(intrinsicCameraFilename) |
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
125 self.distortionCoefficients = distortionCoefficients |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
126 else: |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
127 self.intrinsicCameraMatrix = intrinsicCameraMatrix |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
128 self.distortionCoefficients = distortionCoefficients |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
129 |
861
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
130 if self.intrinsicCameraMatrix is not None: |
872
c70adaeeddf5
solved issue with latest version of scikit-learn
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
867
diff
changeset
|
131 self.intrinsicCameraMatrixStr = str(self.intrinsicCameraMatrix.tolist()) |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
132 if self.distortionCoefficients is not None and len(self.distortionCoefficients) == 5: |
872
c70adaeeddf5
solved issue with latest version of scikit-learn
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
867
diff
changeset
|
133 self.distortionCoefficientsStr = str(self.distortionCoefficients) |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
134 |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
135 @orm.reconstructor |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
136 def initOnLoad(self): |
861
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
137 if self.intrinsicCameraMatrixStr is not None: |
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
138 from ast import literal_eval |
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
139 self.intrinsicCameraMatrix = array(literal_eval(self.intrinsicCameraMatrixStr)) |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
140 else: |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
141 self.intrinsicCameraMatrix = None |
861
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
142 if self.distortionCoefficientsStr is not None: |
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
143 self.distortionCoefficients = literal_eval(self.distortionCoefficientsStr) |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
144 else: |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
145 self.distortionCoefficients = None |
838
2918de3d40fc
first working version of display of merged tracking
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
836
diff
changeset
|
146 |
957
5d9899504977
removed unnecessary field undistortedImageMultiplication
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
955
diff
changeset
|
147 def computeUndistortMaps(self, undistortedImageMultiplication = None): |
5d9899504977
removed unnecessary field undistortedImageMultiplication
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
955
diff
changeset
|
148 if undistortedImageMultiplication is not None and self.intrinsicCameraMatrix is not None and self.distortionCoefficients is not None: |
5d9899504977
removed unnecessary field undistortedImageMultiplication
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
955
diff
changeset
|
149 [self.map1, self.map2], newCameraMatrix = computeUndistortMaps(self.resX, self.resY, undistortedImageMultiplication, self.intrinsicCameraMatrix, self.distortionCoefficients) |
838
2918de3d40fc
first working version of display of merged tracking
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
836
diff
changeset
|
150 else: |
2918de3d40fc
first working version of display of merged tracking
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
836
diff
changeset
|
151 self.map1 = None |
2918de3d40fc
first working version of display of merged tracking
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
836
diff
changeset
|
152 self.map2 = None |
861
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
153 |
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
154 @staticmethod |
862
2d6249fe905a
correcting bug
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
861
diff
changeset
|
155 def getCameraType(session, cameraTypeId, resX = None): |
861
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
156 'Returns the site(s) matching the index or the name' |
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
157 if str.isdigit(cameraTypeId): |
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
158 return session.query(CameraType).filter(CameraType.idx == int(cameraTypeId)).all() |
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
159 else: |
862
2d6249fe905a
correcting bug
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
861
diff
changeset
|
160 if resX is not None: |
2d6249fe905a
correcting bug
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
861
diff
changeset
|
161 return session.query(CameraType).filter(CameraType.name.like('%'+cameraTypeId+'%')).filter(CameraType.resX == resX).all() |
2d6249fe905a
correcting bug
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
861
diff
changeset
|
162 else: |
2d6249fe905a
correcting bug
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
861
diff
changeset
|
163 return session.query(CameraType).filter(CameraType.name.like('%'+cameraTypeId+'%')).all() |
861
f9c9457b60c2
modification of storage of intrinsic camera and distortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
846
diff
changeset
|
164 |
866
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
165 # class SiteDescription(Base): # list of lines and polygons describing the site, eg for sidewalks, center lines |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
166 |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
167 class CameraView(Base): |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
168 __tablename__ = 'camera_views' |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
169 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
|
170 description = Column(String) |
865
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
171 homographyFilename = Column(String) # path to homograph file, relative to the site name |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
172 siteIdx = Column(Integer, ForeignKey('sites.idx')) |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
173 cameraTypeIdx = Column(Integer, ForeignKey('camera_types.idx')) |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
174 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
|
175 maskFilename = Column(String) # path to mask file, relative to site name |
836
7058a40a4bbc
updated metadata and code to merge features from different cameras
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
830
diff
changeset
|
176 virtual = Column(Boolean) # indicates it is not a real camera view, eg merged |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
177 |
955
a15e843af55a
correcting errors in metadata names for backrefs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
872
diff
changeset
|
178 site = relationship("Site", backref = backref('cameraViews')) |
a15e843af55a
correcting errors in metadata names for backrefs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
872
diff
changeset
|
179 cameraType = relationship('CameraType', backref = backref('cameraViews')) |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
180 |
836
7058a40a4bbc
updated metadata and code to merge features from different cameras
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
830
diff
changeset
|
181 def __init__(self, description, homographyFilename, site, cameraType, trackingConfigurationFilename, maskFilename, virtual = False): |
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
|
182 self.description = description |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
183 self.homographyFilename = homographyFilename |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
184 self.site = site |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
185 self.cameraType = cameraType |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
186 self.trackingConfigurationFilename = trackingConfigurationFilename |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
187 self.maskFilename = maskFilename |
836
7058a40a4bbc
updated metadata and code to merge features from different cameras
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
830
diff
changeset
|
188 self.virtual = virtual |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
189 |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
190 def getHomographyFilename(self, relativeToSiteFilename = True): |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
191 if relativeToSiteFilename: |
865
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
192 return path.join(self.site.getPath(), self.homographyFilename) |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
193 else: |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
194 return self.homographyFilename |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
195 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
196 def getTrackingConfigurationFilename(self, relativeToSiteFilename = True): |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
197 if relativeToSiteFilename: |
865
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
198 return path.join(self.site.getPath(), self.trackingConfigurationFilename) |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
199 else: |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
200 return self.trackingConfigurationFilename |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
201 |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
202 def getMaskFilename(self, relativeToSiteFilename = True): |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
203 if relativeToSiteFilename: |
865
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
204 return path.join(self.site.getPath(), self.maskFilename) |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
205 else: |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
206 return self.maskFilename |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
207 |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
208 def getTrackingParameters(self): |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
209 return ProcessParameters(self.getTrackingConfigurationFilename()) |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
210 |
825
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
211 def getHomographyDistanceUnit(self): |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
212 return self.site.worldDistanceUnit |
6e4357e9116d
corrected and changed matrix to individual columns
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
821
diff
changeset
|
213 |
866
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
214 # class Alignment(Base): |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
215 # __tablename__ = 'alignments' |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
216 # idx = Column(Integer, primary_key=True) |
955
a15e843af55a
correcting errors in metadata names for backrefs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
872
diff
changeset
|
217 # siteIdx = Column(Integer, ForeignKey('sites.idx')) |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
218 |
955
a15e843af55a
correcting errors in metadata names for backrefs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
872
diff
changeset
|
219 # cameraView = relationship("Site", backref = backref('alignments')) |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
220 |
866
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
221 # def __init__(self, cameraView): |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
222 # self.cameraView = cameraView |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
223 |
866
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
224 # class Point(Base): |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
225 # __tablename__ = 'points' |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
226 # alignmentIdx = Column(Integer, ForeignKey('alignments.idx'), primary_key=True) |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
227 # index = Column(Integer, primary_key=True) # order of points in this alignment |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
228 # x = Column(Float) |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
229 # y = Column(Float) |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
230 |
955
a15e843af55a
correcting errors in metadata names for backrefs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
872
diff
changeset
|
231 # alignment = relationship("Alignment", backref = backref('points', order_by = index)) |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
232 |
866
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
233 # def __init__(self, alignmentIdx, index, x, y): |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
234 # self.alignmentIdx = alignmentIdx |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
235 # self.index = index |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
236 # self.x = x |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
237 # self.y = y |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
238 |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
239 class VideoSequence(Base): |
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
240 __tablename__ = 'video_sequences' |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
241 idx = Column(Integer, primary_key=True) |
865
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
242 name = Column(String) # path to the video file relative to the the site name |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
243 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
|
244 duration = Column(Interval) # video sequence duration |
865
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
245 databaseFilename = Column(String) # path to the database file relative to the the site name |
836
7058a40a4bbc
updated metadata and code to merge features from different cameras
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
830
diff
changeset
|
246 virtual = Column(Boolean) # indicates it is not a real video sequence (no video file), eg merged |
580
1262faae12e7
alignments may be stored in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
247 cameraViewIdx = Column(Integer, ForeignKey('camera_views.idx')) |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
248 |
955
a15e843af55a
correcting errors in metadata names for backrefs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
872
diff
changeset
|
249 cameraView = relationship("CameraView", backref = backref('videoSequences', order_by = idx)) |
420
def795d1120f
first work on video metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
250 |
836
7058a40a4bbc
updated metadata and code to merge features from different cameras
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
830
diff
changeset
|
251 def __init__(self, name, startTime, duration, cameraView, databaseFilename = None, virtual = False): |
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
|
252 '''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
|
253 duration is a timedelta object''' |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
254 self.name = name |
828
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
255 if isinstance(startTime, str): |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
256 self.startTime = datetime.strptime(startTime, datetimeFormat) |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
257 else: |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
258 self.startTime = startTime |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
259 self.duration = duration |
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
260 self.cameraView = cameraView |
819
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
261 if databaseFilename is None and len(self.name) > 0: |
fc8b3ce629d1
important modifications to metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
805
diff
changeset
|
262 self.databaseFilename = removeExtension(self.name)+'.sqlite' |
846 | 263 else: |
264 self.databaseFilename = databaseFilename | |
836
7058a40a4bbc
updated metadata and code to merge features from different cameras
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
830
diff
changeset
|
265 self.virtual = virtual |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
266 |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
267 def getVideoSequenceFilename(self, relativeToSiteFilename = True): |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
268 if relativeToSiteFilename: |
865
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
269 return path.join(self.cameraView.site.getPath(), self.name) |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
270 else: |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
271 return self.name |
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
272 |
830
2a5856961933
first working version of feature merging (works with feature grouping)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
828
diff
changeset
|
273 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
|
274 if relativeToSiteFilename: |
865
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
275 return path.join(self.cameraView.site.getPath(), self.databaseFilename) |
830
2a5856961933
first working version of feature merging (works with feature grouping)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
828
diff
changeset
|
276 else: |
2a5856961933
first working version of feature merging (works with feature grouping)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
828
diff
changeset
|
277 return self.databaseFilename |
2a5856961933
first working version of feature merging (works with feature grouping)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
828
diff
changeset
|
278 |
828
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
279 def getTimeInterval(self): |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
280 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
|
281 |
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
|
282 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
|
283 '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
|
284 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
|
285 |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
286 def intersection(self, startTime, endTime): |
14e4ad7c7420
work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
825
diff
changeset
|
287 '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
|
288 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
|
289 |
26daf35180ad
finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
819
diff
changeset
|
290 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
|
291 '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
|
292 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
|
293 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
|
294 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
|
295 return None |
424 | 296 |
865
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
297 class TrackingAnnotation(Base): |
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
298 __tablename__ = 'tracking_annotations' |
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
299 idx = Column(Integer, primary_key=True) |
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
300 description = Column(String) # description |
866
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
301 groundTruthFilename = Column(String) |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
302 firstFrameNum = Column(Integer) # first frame num of annotated data (could be computed on less data) |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
303 lastFrameNum = Column(Integer) |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
304 videoSequenceIdx = Column(Integer, ForeignKey('video_sequences.idx')) |
867
003445db1e30
forgot annotation mask filename
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
866
diff
changeset
|
305 maskFilename = Column(String) # path to mask file (can be different from camera view, for annotations), relative to site name |
866
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
306 undistorted = Column(Boolean) # indicates whether the annotations were done in undistorted video space |
865
5afa1d30edd8
minor improvement to path description and path accessors
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
862
diff
changeset
|
307 |
955
a15e843af55a
correcting errors in metadata names for backrefs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
872
diff
changeset
|
308 videoSequence = relationship("VideoSequence", backref = backref('trackingAnnotations')) |
866
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
309 |
867
003445db1e30
forgot annotation mask filename
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
866
diff
changeset
|
310 def __init__(self, description, groundTruthFilename, firstFrameNum, lastFrameNum, videoSequence, maskFilename, undistorted = True): |
866
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
311 self.description = description |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
312 self.groundTruthFilename = groundTruthFilename |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
313 self.firstFrameNum = firstFrameNum |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
314 self.lastFrameNum = lastFrameNum |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
315 self.videoSequence = videoSequence |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
316 self.undistorted = undistorted |
867
003445db1e30
forgot annotation mask filename
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
866
diff
changeset
|
317 self.maskFilename = maskFilename |
866
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
318 |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
319 def getGroundTruthFilename(self, relativeToSiteFilename = True): |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
320 if relativeToSiteFilename: |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
321 return path.join(self.videoSequence.cameraView.site.getPath(), self.groundTruthFilename) |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
322 else: |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
323 return self.groundTruthFilename |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
324 |
867
003445db1e30
forgot annotation mask filename
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
866
diff
changeset
|
325 def getMaskFilename(self, relativeToSiteFilename = True): |
003445db1e30
forgot annotation mask filename
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
866
diff
changeset
|
326 if relativeToSiteFilename: |
003445db1e30
forgot annotation mask filename
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
866
diff
changeset
|
327 return path.join(self.videoSequence.cameraView.site.getPath(), self.maskFilename) |
003445db1e30
forgot annotation mask filename
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
866
diff
changeset
|
328 else: |
003445db1e30
forgot annotation mask filename
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
866
diff
changeset
|
329 return self.maskFilename |
003445db1e30
forgot annotation mask filename
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
866
diff
changeset
|
330 |
866
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
331 def getTimeInterval(self): |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
332 return TimeInterval(self.firstFrameNum, self.lastFrameNum) |
8fba46899e74
addition of class to represent tracking annotations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
865
diff
changeset
|
333 |
422
67c7ff5d6b26
added new fields for units, getting filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
421
diff
changeset
|
334 # 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
|
335 |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
336 # 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
|
337 # eg bounding box depends on camera view, tracking configuration depends on camera view |
424 | 338 # results: sqlite |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
339 |
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
|
340 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
|
341 '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
|
342 engine = create_engine('sqlite:///'+filename) |
421
4fce27946c60
first example of video metadata using sqlalchemy
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
420
diff
changeset
|
343 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
|
344 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
|
345 return Session() |
425
a31dde19caa8
connect function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
424
diff
changeset
|
346 |
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
|
347 def connectDatabase(filename): |
425
a31dde19caa8
connect function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
424
diff
changeset
|
348 'creates a session to query the filename' |
a31dde19caa8
connect function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
424
diff
changeset
|
349 engine = create_engine('sqlite:///'+filename) |
a31dde19caa8
connect function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
424
diff
changeset
|
350 Session = sessionmaker(bind=engine) |
a31dde19caa8
connect function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
424
diff
changeset
|
351 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
|
352 |
971
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
353 def getSite(session, siteId): |
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
354 'Returns the site(s) matching the index or the name' |
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
355 if str.isdigit(siteId): |
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
356 return session.query(Site).filter(Site.idx == int(siteId)).all() |
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
357 else: |
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
358 return session.query(Site).filter(Site.description.like('%'+siteId+'%')).all() |
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
359 |
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
360 def getCameraView(session, viewId): |
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
361 'Returns the site(s) matching the index' |
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
362 return session.query(CameraView).filter(CameraView.idx == int(viewId)).first() |
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
363 |
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
364 def initializeSites(session, directoryName, nViewsPerSite = 1): |
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
365 '''Initializes default site objects and n camera views per site |
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
|
366 |
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
|
367 eg somedirectory/montreal/ contains intersection1, intersection2, etc. |
971
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
368 The site names would be somedirectory/montreal/intersection1, somedirectory/montreal/intersection2, etc. |
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
369 The views should be directories in somedirectory/montreal/intersection1''' |
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
|
370 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
|
371 cameraViews = [] |
972 | 372 names = sorted(listdir(directoryName)) |
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
|
373 for name in names: |
968
32a34a143c27
work on sumo and metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
957
diff
changeset
|
374 if path.isdir(directoryName+sep+name): |
32a34a143c27
work on sumo and metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
957
diff
changeset
|
375 sites.append(Site(directoryName+sep+name, None)) |
971
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
376 for cameraViewIdx in range(1, nViewsPerSite+1): |
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
377 cameraViews.append(CameraView('view{}'.format(cameraViewIdx), None, sites[-1], None, None, None)) |
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
|
378 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
|
379 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
|
380 session.commit() |
969
5d788d2e8ffc
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
968
diff
changeset
|
381 |
970
bf401567a933
work on initializing videos for metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
969
diff
changeset
|
382 def initializeVideos(session, cameraView, directoryName, startTime = None, datetimeFormat = None): |
969
5d788d2e8ffc
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
968
diff
changeset
|
383 '''Initializes videos with time or tries to guess it from filename |
5d788d2e8ffc
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
968
diff
changeset
|
384 directoryName should contain the videos to find and be the relative path from the site location''' |
972 | 385 names = sorted(listdir(directoryName)) |
969
5d788d2e8ffc
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
968
diff
changeset
|
386 videoSequences = [] |
971
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
387 if datetimeFormat is not None: |
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
388 timeConverter = TimeConverter(datetimeFormat) |
969
5d788d2e8ffc
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
968
diff
changeset
|
389 for name in names: |
970
bf401567a933
work on initializing videos for metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
969
diff
changeset
|
390 prefix = removeExtension(name) |
969
5d788d2e8ffc
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
968
diff
changeset
|
391 extension = getExtension(name) |
5d788d2e8ffc
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
968
diff
changeset
|
392 if extension in videoFilenameExtensions: |
971
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
393 if datetimeFormat is not None: |
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
394 from argparse import ArgumentTypeError |
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
395 try: |
972 | 396 t1 = timeConverter.convert(name[:name.rfind('_')]) |
971
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
397 print('DB time {} / Time from filename {}'.format(startTime, t1)) |
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
398 except ArgumentTypeError as e: |
9897a13772fb
added utils to load video sequence in metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
970
diff
changeset
|
399 print('File format error for time {} (prefix {})'.format(name, prefix)) |
970
bf401567a933
work on initializing videos for metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
969
diff
changeset
|
400 vidinfo = infoVideo(directoryName+sep+name) |
bf401567a933
work on initializing videos for metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
969
diff
changeset
|
401 duration = vidinfo['number of frames']#timedelta(minutes = 27, seconds = 33) |
bf401567a933
work on initializing videos for metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
969
diff
changeset
|
402 fps = vidinfo['fps'] |
bf401567a933
work on initializing videos for metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
969
diff
changeset
|
403 duration = timedelta(seconds=duration/fps) |
bf401567a933
work on initializing videos for metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
969
diff
changeset
|
404 videoSequences.append(VideoSequence(directoryName+sep+name, startTime, duration, cameraView, directoryName+sep+prefix+'.sqlite')) |
bf401567a933
work on initializing videos for metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
969
diff
changeset
|
405 startTime += duration |
bf401567a933
work on initializing videos for metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
969
diff
changeset
|
406 session.add_all(videoSequences) |
bf401567a933
work on initializing videos for metadata
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
969
diff
changeset
|
407 session.commit() |