Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and update slideotracker #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 8 additions & 31 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -110,11 +90,8 @@ __________
#extract pdf pages to jpeg using ImageMagick
mkdir /tmp/mypdf/
convert <your.pdf> /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
Expand Down
84 changes: 84 additions & 0 deletions scripts/slideo
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

# Contact : [email protected] or [email protected]
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)
4 changes: 2 additions & 2 deletions slideo/slideotracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()])
Expand Down