annotate scripts/play-synced-videos.py @ 830:2a5856961933

first working version of feature merging (works with feature grouping)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 29 Jun 2016 17:56:19 -0400
parents 14e4ad7c7420
children 8d1dd771aeb3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
821
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1 #! /usr/bin/env python
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3 import sys, argparse, os.path
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4 import cvutils, utils
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
5 from metadata import createDatabase, Site, VideoSequence
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
6 from datetime import datetime, timedelta
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
7
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
8 parser = argparse.ArgumentParser(description='The program displays several views of the same site synchronously.')
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
9 parser.add_argument('-i', dest = 'metadataFilename', help = 'name of the metadata file', required = True)
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
10 parser.add_argument('-n', dest = 'siteId', help = 'site id or site name', required = True)
830
2a5856961933 first working version of feature merging (works with feature grouping)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 828
diff changeset
11 parser.add_argument('-f', dest = 'startTime', help = 'time to start playing (format %Y-%m-%d %H:%M:%S, eg 2011-06-22 10:00:39)', required = True)
821
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
12 parser.add_argument('--fps', dest = 'frameRate', help = 'approximate frame rate to replay', default = -1, type = float)
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
13 parser.add_argument('-r', dest = 'rescale', help = 'rescaling factor for the displayed image', default = 1., type = float)
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
14 parser.add_argument('-s', dest = 'step', help = 'display every s image', default = 1, type = int)
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
15
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
16 args = parser.parse_args()
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
17
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
18 session = createDatabase(args.metadataFilename)
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
19
828
14e4ad7c7420 work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 822
diff changeset
20 site = Site.getSite(session, args.siteId)
821
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
21 if site is None:
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
22 print('Site {} was not found in {}. Exiting'.format(args.siteId, args.metadataFilename))
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
23 sys.exit()
828
14e4ad7c7420 work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 822
diff changeset
24 else:
14e4ad7c7420 work on merging data for synchronized views
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 822
diff changeset
25 site = site[0]
821
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
26
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
27 dirname = os.path.split(args.metadataFilename)[0]
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
28
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
29 startTime = datetime.strptime(args.startTime, utils.datetimeFormat)
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
30 videoSequences = session.query(VideoSequence).filter(VideoSequence.site == site).filter(VideoSequence.startTime <= startTime).all()
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
31 videoSequences = [v for v in videoSequences if v.containsInstant(startTime)]
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
32 filenames = [dirname+os.path.sep+v.getVideoSequenceFilename() for v in videoSequences]
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
33 firstFrameNums = [v.getFrameNum(startTime) for v in videoSequences]
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
34
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
35 cvutils.playVideo(filenames, [v.cameraView.description for v in videoSequences], firstFrameNums, args.frameRate, rescale = args.rescale, step = args.step)