comparison python/metadata.py @ 866:8fba46899e74

addition of class to represent tracking annotations
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 08 Dec 2016 17:51:03 -0500
parents 5afa1d30edd8
children 003445db1e30
comparison
equal deleted inserted replaced
865:5afa1d30edd8 866:8fba46899e74
1 # from moving import Point
2
3 from datetime import datetime, timedelta 1 from datetime import datetime, timedelta
4 from os import path 2 from os import path
5 from math import floor 3 from math import floor
6 4
7 from numpy import zeros, loadtxt, array 5 from numpy import zeros, loadtxt, array
11 from sqlalchemy.ext.declarative import declarative_base 9 from sqlalchemy.ext.declarative import declarative_base
12 10
13 from utils import datetimeFormat, removeExtension 11 from utils import datetimeFormat, removeExtension
14 from cvutils import computeUndistortMaps 12 from cvutils import computeUndistortMaps
15 from moving import TimeInterval 13 from moving import TimeInterval
14
15 """
16 Metadata to describe how video data and configuration files for video analysis are stored
17
18 Typical example is
19
20 site1/view1/2012-06-01/video.avi
21 /2012-06-02/video.avi
22 ...
23 /view2/2012-06-01/video.avi
24 /2012-06-02/video.avi
25 ...
26
27 - where site1 is the path to the directory containing all information pertaining to the site,
28 relative to directory of the SQLite file storing the metadata
29 represented by Site class
30 (can contain for example the aerial or map image of the site, used for projection)
31
32 - view1 is the directory for the first camera field of view (camera fixed position) at site site1
33 represented by CameraView class
34 (can contain for example the homography file, mask file and tracking configuration file)
35
36 - YYYY-MM-DD is the directory containing all the video files for that day
37 with camera view view1 at site site1
38
39
40 """
16 41
17 Base = declarative_base() 42 Base = declarative_base()
18 43
19 class Site(Base): 44 class Site(Base):
20 __tablename__ = 'sites' 45 __tablename__ = 'sites'
147 if resX is not None: 172 if resX is not None:
148 return session.query(CameraType).filter(CameraType.name.like('%'+cameraTypeId+'%')).filter(CameraType.resX == resX).all() 173 return session.query(CameraType).filter(CameraType.name.like('%'+cameraTypeId+'%')).filter(CameraType.resX == resX).all()
149 else: 174 else:
150 return session.query(CameraType).filter(CameraType.name.like('%'+cameraTypeId+'%')).all() 175 return session.query(CameraType).filter(CameraType.name.like('%'+cameraTypeId+'%')).all()
151 176
177 # class SiteDescription(Base): # list of lines and polygons describing the site, eg for sidewalks, center lines
178
152 class CameraView(Base): 179 class CameraView(Base):
153 __tablename__ = 'camera_views' 180 __tablename__ = 'camera_views'
154 idx = Column(Integer, primary_key=True) 181 idx = Column(Integer, primary_key=True)
155 description = Column(String) 182 description = Column(String)
156 homographyFilename = Column(String) # path to homograph file, relative to the site name 183 homographyFilename = Column(String) # path to homograph file, relative to the site name
159 trackingConfigurationFilename = Column(String) # path to configuration .cfg file, relative to site name 186 trackingConfigurationFilename = Column(String) # path to configuration .cfg file, relative to site name
160 maskFilename = Column(String) # path to mask file, relative to site name 187 maskFilename = Column(String) # path to mask file, relative to site name
161 virtual = Column(Boolean) # indicates it is not a real camera view, eg merged 188 virtual = Column(Boolean) # indicates it is not a real camera view, eg merged
162 189
163 site = relationship("Site", backref=backref('sites', order_by = idx)) 190 site = relationship("Site", backref=backref('sites', order_by = idx))
164 cameraType = relationship('CameraType', backref=backref('camera_views', order_by = idx)) 191 cameraType = relationship('CameraType', backref=backref('camera_types', order_by = idx))
165 192
166 def __init__(self, description, homographyFilename, site, cameraType, trackingConfigurationFilename, maskFilename, virtual = False): 193 def __init__(self, description, homographyFilename, site, cameraType, trackingConfigurationFilename, maskFilename, virtual = False):
167 self.description = description 194 self.description = description
168 self.homographyFilename = homographyFilename 195 self.homographyFilename = homographyFilename
169 self.site = site 196 self.site = site
194 return ProcessParameters(self.getTrackingConfigurationFilename()) 221 return ProcessParameters(self.getTrackingConfigurationFilename())
195 222
196 def getHomographyDistanceUnit(self): 223 def getHomographyDistanceUnit(self):
197 return self.site.worldDistanceUnit 224 return self.site.worldDistanceUnit
198 225
199 class Alignment(Base): 226 # class Alignment(Base):
200 __tablename__ = 'alignments' 227 # __tablename__ = 'alignments'
201 idx = Column(Integer, primary_key=True) 228 # idx = Column(Integer, primary_key=True)
202 cameraViewIdx = Column(Integer, ForeignKey('camera_views.idx')) 229 # cameraViewIdx = Column(Integer, ForeignKey('camera_views.idx')) # should be sites??
203 230
204 cameraView = relationship("CameraView", backref=backref('alignments', order_by = idx)) 231 # cameraView = relationship("CameraView", backref=backref('alignments', order_by = idx))
205 232
206 def __init__(self, cameraView): 233 # def __init__(self, cameraView):
207 self.cameraView = cameraView 234 # self.cameraView = cameraView
208 235
209 class Point(Base): 236 # class Point(Base):
210 __tablename__ = 'points' 237 # __tablename__ = 'points'
211 alignmentIdx = Column(Integer, ForeignKey('alignments.idx'), primary_key=True) 238 # alignmentIdx = Column(Integer, ForeignKey('alignments.idx'), primary_key=True)
212 index = Column(Integer, primary_key=True) # order of points in this alignment 239 # index = Column(Integer, primary_key=True) # order of points in this alignment
213 x = Column(Float) 240 # x = Column(Float)
214 y = Column(Float) 241 # y = Column(Float)
215 242
216 alignment = relationship("Alignment", backref=backref('points', order_by = index)) 243 # alignment = relationship("Alignment", backref=backref('alignments', order_by = index))
217 244
218 def __init__(self, alignmentIdx, index, x, y): 245 # def __init__(self, alignmentIdx, index, x, y):
219 self.alignmentIdx = alignmentIdx 246 # self.alignmentIdx = alignmentIdx
220 self.index = index 247 # self.index = index
221 self.x = x 248 # self.x = x
222 self.y = y 249 # self.y = y
223 250
224 class VideoSequence(Base): 251 class VideoSequence(Base):
225 __tablename__ = 'video_sequences' 252 __tablename__ = 'video_sequences'
226 idx = Column(Integer, primary_key=True) 253 idx = Column(Integer, primary_key=True)
227 name = Column(String) # path to the video file relative to the the site name 254 name = Column(String) # path to the video file relative to the the site name
229 duration = Column(Interval) # video sequence duration 256 duration = Column(Interval) # video sequence duration
230 databaseFilename = Column(String) # path to the database file relative to the the site name 257 databaseFilename = Column(String) # path to the database file relative to the the site name
231 virtual = Column(Boolean) # indicates it is not a real video sequence (no video file), eg merged 258 virtual = Column(Boolean) # indicates it is not a real video sequence (no video file), eg merged
232 cameraViewIdx = Column(Integer, ForeignKey('camera_views.idx')) 259 cameraViewIdx = Column(Integer, ForeignKey('camera_views.idx'))
233 260
234 cameraView = relationship("CameraView", backref=backref('video_sequences', order_by = idx)) 261 cameraView = relationship("CameraView", backref=backref('camera_views', order_by = idx))
235 262
236 def __init__(self, name, startTime, duration, cameraView, databaseFilename = None, virtual = False): 263 def __init__(self, name, startTime, duration, cameraView, databaseFilename = None, virtual = False):
237 '''startTime is passed as string in utils.datetimeFormat, eg 2011-06-22 10:00:39 264 '''startTime is passed as string in utils.datetimeFormat, eg 2011-06-22 10:00:39
238 duration is a timedelta object''' 265 duration is a timedelta object'''
239 self.name = name 266 self.name = name
281 308
282 class TrackingAnnotation(Base): 309 class TrackingAnnotation(Base):
283 __tablename__ = 'tracking_annotations' 310 __tablename__ = 'tracking_annotations'
284 idx = Column(Integer, primary_key=True) 311 idx = Column(Integer, primary_key=True)
285 description = Column(String) # description 312 description = Column(String) # description
286 313 groundTruthFilename = Column(String)
314 firstFrameNum = Column(Integer) # first frame num of annotated data (could be computed on less data)
315 lastFrameNum = Column(Integer)
316 videoSequenceIdx = Column(Integer, ForeignKey('video_sequences.idx'))
317 undistorted = Column(Boolean) # indicates whether the annotations were done in undistorted video space
318
319 videoSequence = relationship("VideoSequence", backref=backref('video_sequences', order_by = idx))
320
321 def __init__(self, description, groundTruthFilename, firstFrameNum, lastFrameNum, videoSequence, undistorted = True):
322 self.description = description
323 self.groundTruthFilename = groundTruthFilename
324 self.firstFrameNum = firstFrameNum
325 self.lastFrameNum = lastFrameNum
326 self.videoSequence = videoSequence
327 self.undistorted = undistorted
328
329 def getGroundTruthFilename(self, relativeToSiteFilename = True):
330 if relativeToSiteFilename:
331 return path.join(self.videoSequence.cameraView.site.getPath(), self.groundTruthFilename)
332 else:
333 return self.groundTruthFilename
334
335 def getTimeInterval(self):
336 return TimeInterval(self.firstFrameNum, self.lastFrameNum)
337
287 # 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) 338 # 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)
288
289 # class SiteDescription(Base): # list of lines and polygons describing the site, eg for sidewalks, center lines
290 339
291 # class Analysis(Base): # parameters necessary for processing the data: free form 340 # class Analysis(Base): # parameters necessary for processing the data: free form
292 # eg bounding box depends on camera view, tracking configuration depends on camera view 341 # eg bounding box depends on camera view, tracking configuration depends on camera view
293 # results: sqlite 342 # results: sqlite
294 343