From 787fe6a93f8234b49220bda86bc316f9b17e08a0 Mon Sep 17 00:00:00 2001 From: Alexander Mordvintsev Date: Fri, 10 Jun 2011 07:54:21 +0000 Subject: [PATCH] multiple cameras and frame saving in video.py --- samples/python2/browse.py | 2 +- samples/python2/video.py | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/samples/python2/browse.py b/samples/python2/browse.py index 721fbaa..579b0e8 100644 --- a/samples/python2/browse.py +++ b/samples/python2/browse.py @@ -16,7 +16,7 @@ if len(sys.argv) > 1: img = cv2.imread(fn) else: sz = 4096 - print 'generating %dx%d procudural image ...' % (sz, sz) + print 'generating %dx%d procedural image ...' % (sz, sz) img = np.zeros((sz, sz), np.uint8) track = np.cumsum(np.random.rand(500000, 2)-0.5, axis=0) track = np.int32(track*10 + (sz/2, sz/2)) diff --git a/samples/python2/video.py b/samples/python2/video.py index 762f01a..3b5a98e 100644 --- a/samples/python2/video.py +++ b/samples/python2/video.py @@ -49,13 +49,30 @@ def create_capture(source): if __name__ == '__main__': import sys - try: fn = sys.argv[1] - except: fn = 'synth:bg=../cpp/lena.jpg:noise=0.1' + import argparse + + parser = argparse.ArgumentParser() + parser.add_argument('sources', nargs='*', default=['synth:bg=../cpp/lena.jpg:noise=0.1']) + parser.add_argument('-shotdir', nargs=1, default='.') + args = parser.parse_args() + print args - cap = create_capture(fn) + print 'Press SPACE to save current frame' + + caps = map(create_capture, args.sources) + shot_idx = 0 while True: - ret, img = cap.read() - cv2.imshow('img', img) + imgs = [] + for i, cap in enumerate(caps): + ret, img = cap.read() + imgs.append(img) + cv2.imshow('capture %d' % i, img) ch = cv2.waitKey(1) if ch == 27: break + if ch == ord(' '): + for i, img in enumerate(imgs): + fn = '%s/shot_%d_%03d.bmp' % (args.shotdir[0], i, shot_idx) + cv2.imwrite(fn, img) + print fn, 'saved' + shot_idx += 1 -- 2.7.4