Mercurial > hg > nsaunier > traffic-intelligence
comparison python/metadata.py @ 970:bf401567a933
work on initializing videos for metadata
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Thu, 07 Dec 2017 23:31:54 -0500 |
| parents | 5d788d2e8ffc |
| children | 9897a13772fb |
comparison
equal
deleted
inserted
replaced
| 969:5d788d2e8ffc | 970:bf401567a933 |
|---|---|
| 7 from sqlalchemy import orm, create_engine, Column, Integer, Float, DateTime, String, ForeignKey, Boolean, Interval | 7 from sqlalchemy import orm, create_engine, Column, Integer, Float, DateTime, String, ForeignKey, Boolean, Interval |
| 8 from sqlalchemy.orm import relationship, backref, sessionmaker | 8 from sqlalchemy.orm import relationship, backref, sessionmaker |
| 9 from sqlalchemy.ext.declarative import declarative_base | 9 from sqlalchemy.ext.declarative import declarative_base |
| 10 | 10 |
| 11 from utils import datetimeFormat, removeExtension, getExtension | 11 from utils import datetimeFormat, removeExtension, getExtension |
| 12 from cvutils import computeUndistortMaps, videoFilenameExtensions | 12 from cvutils import computeUndistortMaps, videoFilenameExtensions, infoVideo |
| 13 from moving import TimeInterval | 13 from moving import TimeInterval |
| 14 | 14 |
| 15 """ | 15 """ |
| 16 Metadata to describe how video data and configuration files for video analysis are stored | 16 Metadata to describe how video data and configuration files for video analysis are stored |
| 17 | 17 |
| 375 session.add_all(sites) | 375 session.add_all(sites) |
| 376 session.add_all(cameraViews) | 376 session.add_all(cameraViews) |
| 377 session.commit() | 377 session.commit() |
| 378 # TODO crawler for video files? | 378 # TODO crawler for video files? |
| 379 | 379 |
| 380 def initializeVideos(session, site, cameraView, directoryName, startTime = None, datetimeFormat = None): | 380 def initializeVideos(session, cameraView, directoryName, startTime = None, datetimeFormat = None): |
| 381 '''Initializes videos with time or tries to guess it from filename | 381 '''Initializes videos with time or tries to guess it from filename |
| 382 directoryName should contain the videos to find and be the relative path from the site location''' | 382 directoryName should contain the videos to find and be the relative path from the site location''' |
| 383 names = listdir(directoryName) | 383 names = listdir(directoryName) |
| 384 videoSequences = [] | 384 videoSequences = [] |
| 385 for name in names: | 385 for name in names: |
| 386 prefix = removeExtension(name) | |
| 386 extension = getExtension(name) | 387 extension = getExtension(name) |
| 387 print(name, extension) | |
| 388 if extension in videoFilenameExtensions: | 388 if extension in videoFilenameExtensions: |
| 389 videoSequences.append(VideoSequence(directoryName+sep+name, startTime, None, cameraView, directoryName+sep+'.sqlite')) | 389 vidinfo = infoVideo(directoryName+sep+name) |
| 390 return videoSequences | 390 duration = vidinfo['number of frames']#timedelta(minutes = 27, seconds = 33) |
| 391 fps = vidinfo['fps'] | |
| 392 duration = timedelta(seconds=duration/fps) | |
| 393 videoSequences.append(VideoSequence(directoryName+sep+name, startTime, duration, cameraView, directoryName+sep+prefix+'.sqlite')) | |
| 394 startTime += duration | |
| 395 session.add_all(videoSequences) | |
| 396 session.commit() |
