annotate scripts/play-synced-videos.py @ 822:41558145e131

minor rename
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 22 Jun 2016 16:41:19 -0400
parents scripts/play-synced-video.py@26daf35180ad
children 14e4ad7c7420
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)
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
11 parser.add_argument('-t', dest = 'startTime', help = 'time to start playing (format %Y-%m-%d %H:%M:%S, eg 2011-06-22 10:00:39)', 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
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
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
20 if str.isdigit(args.siteId):
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
21 site = session.query(Site).filter(Site.idx == int(args.siteId)).first()
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
22 else:
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
23 site = session.query(Site).filter(Site.description.like('%'+args.siteId+'%')).first()
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
24
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
25 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
26 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
27 sys.exit()
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 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
30
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
31 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
32 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
33 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
34 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
35 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
36
26daf35180ad finished modification and demo script to replay synchronized video (with same frame rate)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
37 cvutils.playVideo(filenames, [v.cameraView.description for v in videoSequences], firstFrameNums, args.frameRate, rescale = args.rescale, step = args.step)