diff --git a/README.rst b/README.rst index d7244c7..2b677c9 100644 --- a/README.rst +++ b/README.rst @@ -49,36 +49,16 @@ Usage .. - Usage: slideotracker.py [options] + Usage: slideotracker.py [options] [slides] - Options: - -h, --help show this help message and exit - -i index, --index=index - index file is a simple text file, the first line in - the video path, others lines are paths on slide images - (use ImageMagick, to convert pdf in several images) - -p PRECISION, --precision=PRECISION - precision in number of frame (default 25) - -o OUTFILE, --out=OUTFILE - output file name, by default results.js - -f FORMAT, --format=FORMAT - output file format js (default),csv - -d, --debug debug trace - - -Usage -===== - -.. - - Usage: slideotracker.py [options] + Parameters: + sli des paths to slide images (use ImageMagick, to + convert pdf into several images) Options: -h, --help show this help message and exit - -i index, --index=index - index file is a simple text file, the first line in - the video path, others lines are paths on slide images - (use ImageMagick, to convert pdf in several images) + -v video, --video=index + video path -p PRECISION, --precision=PRECISION precision in number of frame (default 25) -o OUTFILE, --out=OUTFILE @@ -99,7 +79,7 @@ Download and extract : Run :: - slideo -i tests/data/test.txt + slideo -i test/data/video.avi tests/data/slide*.jpg Common use @@ -110,11 +90,8 @@ __________ #extract pdf pages to jpeg using ImageMagick mkdir /tmp/mypdf/ convert /tmp/mypdf/slide.jpg - #build a index file - echo './path/to/my/video.ogv' > /tmp/index - ls -1 /tmp/mypdf/slide* >>/tmp/index #Run the tracker - python slideotracker.py -i /tmp/index -o results.txt + python slideotracker.py -v ./path/to/my/video.ogv -o results.txt /tmp/mypdf/slide* try also : python slideotracker.py -i tests/data/short_test.txt diff --git a/scripts/slideo b/scripts/slideo new file mode 100755 index 0000000..f2f1290 --- /dev/null +++ b/scripts/slideo @@ -0,0 +1,84 @@ +#!/usr/bin/python +# SlideoTracker : synchronising slides and video conference +# Copyright (C) 2010 Sebastien Campion + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +# Contact : sebastien.campion@gmail.com or seb@scamp.fr +import os +import sys +from slideo.slideotracker import SlideoTracker +import numpy as np + +def save(outfile, track_results, precision, format): + ''' + Save method in JavaScript or CSV + ''' + o = open(outfile, 'w') + if format == 'js': + frames = np.array(track_results.keys()) + frames = [int(i) for i in frames] + o.writelines('slides=%s;\n' % str(track_results.values())) + o.writelines('frames=%s;\n' % frames) + + elif format == 'csv': + o.writelines("#slide_number;star_frame;end_frame\n") + current_frame = 0 + for sn, fn in track_results.items(): + sn, sf, ef = sn, precision * current_frame, precision * fn + o.writelines("%i;%i;%i\n" % (sn, sf, ef)) + current_frame = fn + else: + raise NotImplementedError('Output format %s not available' % format) + o.close() + +if __name__ == '__main__': + from optparse import OptionParser + parser = OptionParser(usage="""Slide timing extraction from video + video filename name is given through the -v option + slides filenames are given as parameters.""") + parser.add_option('-v', '--video', action='store', type='string', + dest="video", metavar="video", + help="video filename") + parser.add_option("-r", "--rate", action="store", type='int', + dest='rate', default=25, + help='precision in number of frame (default 25)') + parser.add_option("-o", "--out", action="store", dest='outfile', + help='output file name, by default results.js ', + default='results.js') + parser.add_option("-f", "--format", action="store", dest='format', + help='output file format js (default),csv ', + default='js') + parser.add_option("-d", "--debug", action="store_true", dest='debug', + help='debug trace', default=False) + (options, args) = parser.parse_args() + + if not os.path.exists(options.video or ""): + print "Video filename should be given through the -v option" + sys.exit(1) + if not args: + print "Slide filenames should be given as arguments" + sys.exit(1) + + videopath = os.path.abspath(options.video) + slidepath = [ os.path.abspath(n) for n in args ] + print '#videopath %s' % videopath + print '#nb of slides %i' % len(slidepath) + slideo = SlideoTracker(videopath, slidepath, + frame_rate=options.rate, + debug=options.debug) + results = dict([(frame_id, slidepath) + for frame_id, slidepath in slideo.track()]) + + save(options.outfile, results, options.rate, options.format) diff --git a/slideo/slideotracker.py b/slideo/slideotracker.py index 6f5fde3..c6b99ac 100644 --- a/slideo/slideotracker.py +++ b/slideo/slideotracker.py @@ -19,7 +19,7 @@ import numpy as np import math import os -from scikits.learn import neighbors as knn +from sklearn import neighbors as knn import cv import operator import time @@ -48,7 +48,7 @@ class SlideoTracker: def __init__(self, videopath, slidepaths, frame_rate=25, debug=False): self.frame_rate = frame_rate self.videopath = videopath - self.slidepaths = slidepaths + self.slidepaths = dict(enumerate(slidepaths)) print '#Compute slides features ...' self.slidefeats = dict([(id, self._image_feats_by_file(path)) for id, path in self.slidepaths.items()])