Mercurial Hosting > traffic-intelligence
comparison python/metadata.py @ 969:5d788d2e8ffc
work in progress
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 07 Dec 2017 17:03:09 -0500 |
parents | 32a34a143c27 |
children | bf401567a933 |
comparison
equal
deleted
inserted
replaced
968:32a34a143c27 | 969:5d788d2e8ffc |
---|---|
1 from datetime import datetime, timedelta | 1 from datetime import datetime, timedelta |
2 from os import path | 2 from os import path, listdir, sep |
3 from math import floor | 3 from math import floor |
4 | 4 |
5 from numpy import zeros, loadtxt, array | 5 from numpy import zeros, loadtxt, array |
6 | 6 |
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 | 11 from utils import datetimeFormat, removeExtension, getExtension |
12 from cvutils import computeUndistortMaps | 12 from cvutils import computeUndistortMaps, videoFilenameExtensions |
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 |
361 def initializeSites(session, directoryName): | 361 def initializeSites(session, directoryName): |
362 '''Initializes default site objects and Camera Views | 362 '''Initializes default site objects and Camera Views |
363 | 363 |
364 eg somedirectory/montreal/ contains intersection1, intersection2, etc. | 364 eg somedirectory/montreal/ contains intersection1, intersection2, etc. |
365 The site names would be somedirectory/montreal/intersection1, somedirectory/montreal/intersection2, etc.''' | 365 The site names would be somedirectory/montreal/intersection1, somedirectory/montreal/intersection2, etc.''' |
366 from os import listdir, path, sep | |
367 sites = [] | 366 sites = [] |
368 cameraViews = [] | 367 cameraViews = [] |
369 names = listdir(directoryName) | 368 names = listdir(directoryName) |
370 cameraViewIdx = 1 | 369 cameraViewIdx = 1 |
371 for name in names: | 370 for name in names: |
375 cameraViewIdx += 1 | 374 cameraViewIdx += 1 |
376 session.add_all(sites) | 375 session.add_all(sites) |
377 session.add_all(cameraViews) | 376 session.add_all(cameraViews) |
378 session.commit() | 377 session.commit() |
379 # TODO crawler for video files? | 378 # TODO crawler for video files? |
379 | |
380 def initializeVideos(session, site, cameraView, directoryName, startTime = None, datetimeFormat = None): | |
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''' | |
383 names = listdir(directoryName) | |
384 videoSequences = [] | |
385 for name in names: | |
386 extension = getExtension(name) | |
387 print(name, extension) | |
388 if extension in videoFilenameExtensions: | |
389 videoSequences.append(VideoSequence(directoryName+sep+name, startTime, None, cameraView, directoryName+sep+'.sqlite')) | |
390 return videoSequences |