Mercurial > hg > nsaunier > traffic-intelligence
comparison trafficintelligence/metadata.py @ 1140:78dddfe7aa0f
added alignments for sites
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Wed, 15 Apr 2020 00:18:35 -0400 |
| parents | 9cc51a2d3c46 |
| children | b3ee75b4978a |
comparison
equal
deleted
inserted
replaced
| 1137:e9c12982ed28 | 1140:78dddfe7aa0f |
|---|---|
| 9 from sqlalchemy.orm import relationship, backref, sessionmaker | 9 from sqlalchemy.orm import relationship, backref, sessionmaker |
| 10 from sqlalchemy.ext.declarative import declarative_base | 10 from sqlalchemy.ext.declarative import declarative_base |
| 11 | 11 |
| 12 from trafficintelligence.utils import datetimeFormat, removeExtension, getExtension, TimeConverter | 12 from trafficintelligence.utils import datetimeFormat, removeExtension, getExtension, TimeConverter |
| 13 from trafficintelligence.cvutils import computeUndistortMaps, videoFilenameExtensions, infoVideo | 13 from trafficintelligence.cvutils import computeUndistortMaps, videoFilenameExtensions, infoVideo |
| 14 from trafficintelligence.moving import TimeInterval | 14 from trafficintelligence.moving import TimeInterval, Trajectory |
| 15 | 15 |
| 16 """ | 16 """ |
| 17 Metadata to describe how video data and configuration files for video analysis are stored | 17 Metadata to describe how video data and configuration files for video analysis are stored |
| 18 | 18 |
| 19 Typical example is | 19 Typical example is |
| 210 return ProcessParameters(self.getTrackingConfigurationFilename()) | 210 return ProcessParameters(self.getTrackingConfigurationFilename()) |
| 211 | 211 |
| 212 def getHomographyDistanceUnit(self): | 212 def getHomographyDistanceUnit(self): |
| 213 return self.site.worldDistanceUnit | 213 return self.site.worldDistanceUnit |
| 214 | 214 |
| 215 # class Alignment(Base): | 215 class Alignment(Base): |
| 216 # __tablename__ = 'alignments' | 216 __tablename__ = 'alignments' |
| 217 # idx = Column(Integer, primary_key=True) | 217 idx = Column(Integer, primary_key=True) |
| 218 # siteIdx = Column(Integer, ForeignKey('sites.idx')) | 218 siteIdx = Column(Integer, ForeignKey('sites.idx')) |
| 219 | 219 |
| 220 # cameraView = relationship("Site", backref = backref('alignments')) | 220 site = relationship("Site", backref = backref('alignments')) |
| 221 | 221 |
| 222 # def __init__(self, cameraView): | 222 def __init__(self, site): |
| 223 # self.cameraView = cameraView | 223 self.site = site |
| 224 | 224 |
| 225 # class Point(Base): | 225 def getTrajectory(self): |
| 226 # __tablename__ = 'points' | 226 t = Trajectory() |
| 227 # alignmentIdx = Column(Integer, ForeignKey('alignments.idx'), primary_key=True) | 227 for p in self.point: |
| 228 # index = Column(Integer, primary_key=True) # order of points in this alignment | 228 t.addPositionXY(p.x_coordinate, p.y_coordinate) |
| 229 # x = Column(Float) | 229 return t |
| 230 # y = Column(Float) | 230 |
| 231 | 231 class Point(Base): |
| 232 # alignment = relationship("Alignment", backref = backref('points', order_by = index)) | 232 __tablename__ = 'positions' |
| 233 | 233 trajectory_id = Column(Integer, ForeignKey('alignments.idx'), primary_key=True) |
| 234 # def __init__(self, alignmentIdx, index, x, y): | 234 frame_number = Column(Integer, primary_key=True) # order of points in this alignment, as index |
| 235 # self.alignmentIdx = alignmentIdx | 235 x_coordinate = Column(Float) |
| 236 # self.index = index | 236 y_coordinate = Column(Float) |
| 237 # self.x = x | 237 |
| 238 # self.y = y | 238 alignment = relationship("Alignment", backref = backref('points', order_by = trajectory_id)) |
| 239 | |
| 240 def __init__(self, alignment, index, x, y): | |
| 241 self.alignment = alignment | |
| 242 self.frame_number = index | |
| 243 self.x_coordinate = x | |
| 244 self.y_coordinate = y | |
| 239 | 245 |
| 240 class VideoSequence(Base): | 246 class VideoSequence(Base): |
| 241 __tablename__ = 'video_sequences' | 247 __tablename__ = 'video_sequences' |
| 242 idx = Column(Integer, primary_key=True) | 248 idx = Column(Integer, primary_key=True) |
| 243 name = Column(String) # path to the video file relative to the the site name | 249 name = Column(String) # path to the video file relative to the the site name |
| 423 session.add_all(videoSequences) | 429 session.add_all(videoSequences) |
| 424 session.commit() | 430 session.commit() |
| 425 | 431 |
| 426 def generateTimeIntervals(videoSequences, maxTimeGap): | 432 def generateTimeIntervals(videoSequences, maxTimeGap): |
| 427 '' | 433 '' |
| 434 | |
| 435 def addAlignment(session, site, t): | |
| 436 'Adds trajectory (moving.Trajectory) t to metadata of site' | |
| 437 al = Alignment(site) | |
| 438 session.add(al) | |
| 439 session.commit() | |
| 440 points = [] | |
| 441 for i,p in enumerate(t): | |
| 442 points.append(Point(al, i, p.x, p.y)) | |
| 443 session.add_all(points) | |
| 444 session.commit() | |
| 428 | 445 |
| 429 # management | 446 # management |
| 430 # TODO need to be able to copy everything from a site from one sqlite to another, and delete everything attached to a site | 447 # TODO need to be able to copy everything from a site from one sqlite to another, and delete everything attached to a site |
