Mercurial Hosting > traffic-intelligence
changeset 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 |
files | python/metadata.py |
diffstat | 1 files changed, 74 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/python/metadata.py Thu Dec 08 11:07:14 2016 -0500 +++ b/python/metadata.py Thu Dec 08 17:51:03 2016 -0500 @@ -1,5 +1,3 @@ -# from moving import Point - from datetime import datetime, timedelta from os import path from math import floor @@ -14,6 +12,33 @@ from cvutils import computeUndistortMaps from moving import TimeInterval +""" +Metadata to describe how video data and configuration files for video analysis are stored + +Typical example is + +site1/view1/2012-06-01/video.avi + /2012-06-02/video.avi + ... + /view2/2012-06-01/video.avi + /2012-06-02/video.avi + ... + +- where site1 is the path to the directory containing all information pertaining to the site, +relative to directory of the SQLite file storing the metadata +represented by Site class +(can contain for example the aerial or map image of the site, used for projection) + +- view1 is the directory for the first camera field of view (camera fixed position) at site site1 +represented by CameraView class +(can contain for example the homography file, mask file and tracking configuration file) + +- YYYY-MM-DD is the directory containing all the video files for that day +with camera view view1 at site site1 + + +""" + Base = declarative_base() class Site(Base): @@ -149,6 +174,8 @@ else: return session.query(CameraType).filter(CameraType.name.like('%'+cameraTypeId+'%')).all() +# class SiteDescription(Base): # list of lines and polygons describing the site, eg for sidewalks, center lines + class CameraView(Base): __tablename__ = 'camera_views' idx = Column(Integer, primary_key=True) @@ -161,7 +188,7 @@ virtual = Column(Boolean) # indicates it is not a real camera view, eg merged site = relationship("Site", backref=backref('sites', order_by = idx)) - cameraType = relationship('CameraType', backref=backref('camera_views', order_by = idx)) + cameraType = relationship('CameraType', backref=backref('camera_types', order_by = idx)) def __init__(self, description, homographyFilename, site, cameraType, trackingConfigurationFilename, maskFilename, virtual = False): self.description = description @@ -196,30 +223,30 @@ def getHomographyDistanceUnit(self): return self.site.worldDistanceUnit -class Alignment(Base): - __tablename__ = 'alignments' - idx = Column(Integer, primary_key=True) - cameraViewIdx = Column(Integer, ForeignKey('camera_views.idx')) +# class Alignment(Base): +# __tablename__ = 'alignments' +# idx = Column(Integer, primary_key=True) +# cameraViewIdx = Column(Integer, ForeignKey('camera_views.idx')) # should be sites?? - cameraView = relationship("CameraView", backref=backref('alignments', order_by = idx)) +# cameraView = relationship("CameraView", backref=backref('alignments', order_by = idx)) - def __init__(self, cameraView): - self.cameraView = cameraView +# def __init__(self, cameraView): +# self.cameraView = cameraView -class Point(Base): - __tablename__ = 'points' - alignmentIdx = Column(Integer, ForeignKey('alignments.idx'), primary_key=True) - index = Column(Integer, primary_key=True) # order of points in this alignment - x = Column(Float) - y = Column(Float) +# class Point(Base): +# __tablename__ = 'points' +# alignmentIdx = Column(Integer, ForeignKey('alignments.idx'), primary_key=True) +# index = Column(Integer, primary_key=True) # order of points in this alignment +# x = Column(Float) +# y = Column(Float) - alignment = relationship("Alignment", backref=backref('points', order_by = index)) +# alignment = relationship("Alignment", backref=backref('alignments', order_by = index)) - def __init__(self, alignmentIdx, index, x, y): - self.alignmentIdx = alignmentIdx - self.index = index - self.x = x - self.y = y +# def __init__(self, alignmentIdx, index, x, y): +# self.alignmentIdx = alignmentIdx +# self.index = index +# self.x = x +# self.y = y class VideoSequence(Base): __tablename__ = 'video_sequences' @@ -231,7 +258,7 @@ virtual = Column(Boolean) # indicates it is not a real video sequence (no video file), eg merged cameraViewIdx = Column(Integer, ForeignKey('camera_views.idx')) - cameraView = relationship("CameraView", backref=backref('video_sequences', order_by = idx)) + cameraView = relationship("CameraView", backref=backref('camera_views', order_by = idx)) def __init__(self, name, startTime, duration, cameraView, databaseFilename = None, virtual = False): '''startTime is passed as string in utils.datetimeFormat, eg 2011-06-22 10:00:39 @@ -283,11 +310,33 @@ __tablename__ = 'tracking_annotations' idx = Column(Integer, primary_key=True) description = Column(String) # description + groundTruthFilename = Column(String) + firstFrameNum = Column(Integer) # first frame num of annotated data (could be computed on less data) + lastFrameNum = Column(Integer) + videoSequenceIdx = Column(Integer, ForeignKey('video_sequences.idx')) + undistorted = Column(Boolean) # indicates whether the annotations were done in undistorted video space + videoSequence = relationship("VideoSequence", backref=backref('video_sequences', order_by = idx)) + + def __init__(self, description, groundTruthFilename, firstFrameNum, lastFrameNum, videoSequence, undistorted = True): + self.description = description + self.groundTruthFilename = groundTruthFilename + self.firstFrameNum = firstFrameNum + self.lastFrameNum = lastFrameNum + self.videoSequence = videoSequence + self.undistorted = undistorted + + def getGroundTruthFilename(self, relativeToSiteFilename = True): + if relativeToSiteFilename: + return path.join(self.videoSequence.cameraView.site.getPath(), self.groundTruthFilename) + else: + return self.groundTruthFilename + + def getTimeInterval(self): + return TimeInterval(self.firstFrameNum, self.lastFrameNum) + # 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) -# class SiteDescription(Base): # list of lines and polygons describing the site, eg for sidewalks, center lines - # class Analysis(Base): # parameters necessary for processing the data: free form # eg bounding box depends on camera view, tracking configuration depends on camera view # results: sqlite