Mercurial Hosting > traffic-intelligence
comparison scripts/merge-features.py @ 828:14e4ad7c7420
work on merging data for synchronized views
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 28 Jun 2016 17:18:45 -0400 |
parents | |
children | 0ddcc41663f5 |
comparison
equal
deleted
inserted
replaced
827:f6d5da619307 | 828:14e4ad7c7420 |
---|---|
1 #! /usr/bin/env python | |
2 | |
3 import sys, argparse, os.path | |
4 import cvutils, utils, moving | |
5 from metadata import createDatabase, Site, VideoSequence | |
6 from datetime import datetime, timedelta | |
7 | |
8 parser = argparse.ArgumentParser(description='The program merges feature trajectories recorded from the same site synchronously between start and end time.') | |
9 parser.add_argument('-i', dest = 'metadataFilename', help = 'name of the metadata file', required = True) | |
10 parser.add_argument('-n', dest = 'siteId', help = 'site id or site name', required = True) | |
11 parser.add_argument('--t1', dest = 'startTime', help = 'time to start merging features (format %Y-%m-%d %H:%M:%S, eg 2011-06-22 10:00:39)') # if not provided, take common time interval | |
12 parser.add_argument('--t2', dest = 'endTime', help = 'time to stop merging features (format %Y-%m-%d %H:%M:%S, eg 2011-06-22 10:00:39)') | |
13 | |
14 args = parser.parse_args() | |
15 | |
16 session = createDatabase(args.metadataFilename) | |
17 | |
18 site = Site.getSite(session, args.siteId) | |
19 if site is None: | |
20 print('Site {} was not found in {}. Exiting'.format(args.siteId, args.metadataFilename)) | |
21 sys.exit() | |
22 else: | |
23 site = site[0] | |
24 | |
25 startTime = datetime.strptime(args.startTime, utils.datetimeFormat) | |
26 endTime = datetime.strptime(args.endTime, utils.datetimeFormat) | |
27 processInterval = moving.TimeInterval(startTime, endTime) | |
28 videoSequences = session.query(VideoSequence).filter(VideoSequence.site == site).order_by(VideoSequence.startTime.asc()).all() #.order_by(VideoSequence.cameraViewIdx) .filter(VideoSequence.startTime <= startTime) | |
29 #timeIntervals = [v.intersection(startTime, endTime) for v in videoSequences] | |
30 | |
31 cameraViews = set([v.cameraView for v in videoSequences]) | |
32 | |
33 videoSequences = {cv: [v for v in videoSequences if v.cameraView == cv] for cv in cameraViews} | |
34 timeIntervals = {} | |
35 for cv in videoSequences: | |
36 timeIntervals[cv] = moving.TimeInterval.unionIntervals([v.getTimeInterval() for v in videoSequences[cv]]) | |
37 | |
38 commonTimeInterval = timeIntervals.values()[0] | |
39 for inter in timeIntervals.values()[1:]: | |
40 commonTimeInterval = moving.TimeInterval.intersection(commonTimeInterval, inter) | |
41 commonTimeInterval = moving.TimeInterval.intersection(commonTimeInterval, processInterval) | |
42 | |
43 # for all camera view, for all video, select from positions and velocities where frame_number is in the right range and insert in new database | |
44 | |
45 # should we save the information of the new "sequence" in the metadata? | |
46 #session.add(VideoSequence('merged', , timedelta(seconds = 31616./30.), laurierSite, laurierCameraViewSpot0)) | |
47 | |
48 #session.commit() |