From 6977a895257dc8511ddce36d2eb2bf45a2bf0242 Mon Sep 17 00:00:00 2001 From: Alexander Mordvintsev Date: Mon, 2 Jul 2012 04:44:31 +0000 Subject: [PATCH] descriptions for watershed.py and video.py --- samples/python2/fitline.py | 2 ++ samples/python2/video.py | 38 +++++++++++++++++++++++++++++------- samples/python2/watershed.py | 29 +++++++++++++++++++-------- 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/samples/python2/fitline.py b/samples/python2/fitline.py index f8bb89aa4..71e2cb055 100644 --- a/samples/python2/fitline.py +++ b/samples/python2/fitline.py @@ -63,6 +63,8 @@ def update(_=None): cv2.imshow('fit line', img) if __name__ == '__main__': + print __doc__ + cv2.namedWindow('fit line') cv2.createTrackbar('noise', 'fit line', 3, 50, update) cv2.createTrackbar('point n', 'fit line', 100, 500, update) diff --git a/samples/python2/video.py b/samples/python2/video.py index ab5981459..8d95bf0cd 100644 --- a/samples/python2/video.py +++ b/samples/python2/video.py @@ -1,3 +1,32 @@ +''' +Video capture sample. + +Sample shows how VideoCapture class can be used to acquire video +frames from a camera of a movie file. Also the sample provides +an example of procedural video generation by an object, mimicking +the VideoCapture interface (see Chess class). + +'create_capture' is a convinience function for capture creation, +falling back to procedural video in case of error. + +Usage: + video.py [--shotdir ] [source0] [source1] ...' + + sourceN is an + - integer number for camera capture + - name of video file + - synth: for procedural video + +Synth examples: + synth:bg=../cpp/lena.jpg:noise=0.1 + synth:class=chess:bg=../cpp/lena.jpg:noise=0.1:size=640x480 + +Keys: + ESC - exit + SPACE - save current frame to directory + +''' + import numpy as np import cv2 from time import clock @@ -100,8 +129,7 @@ presets = dict( def create_capture(source = 0, fallback = presets['chess']): - ''' - source: or '||synth [:= [:...]]' + '''source: or '||synth [:= [:...]]' ''' source = str(source).strip() chunks = source.split(':') @@ -136,9 +164,7 @@ if __name__ == '__main__': import sys import getopt - print 'USAGE: video.py [--shotdir ] [source0] [source1] ...' - print "source: '' or '' or 'synth:'" - print + print __doc__ args, sources = getopt.getopt(sys.argv[1:], '', 'shotdir=') args = dict(args) @@ -146,8 +172,6 @@ if __name__ == '__main__': if len(sources) == 0: sources = [ 0 ] - print 'Press SPACE to save current frame' - caps = map(create_capture, sources) shot_idx = 0 while True: diff --git a/samples/python2/watershed.py b/samples/python2/watershed.py index 56d7ebc9e..e02e0202a 100644 --- a/samples/python2/watershed.py +++ b/samples/python2/watershed.py @@ -1,18 +1,31 @@ -import numpy as np -import cv2 -from common import Sketcher +''' +Watershed segmentation +========= -help_message = ''' - USAGE: watershed.py [] +This program demonstrates the watershed segmentation algorithm +in OpenCV: watershed(). - Use keys 1 - 7 to switch marker color +Usage +----- +watershed.py [image filename] + +Keys +---- + 1-7 - switch marker color SPACE - update segmentation r - reset - a - switch autoupdate + a - toggle autoupdate ESC - exit ''' + + + +import numpy as np +import cv2 +from common import Sketcher + class App: def __init__(self, fn): self.img = cv2.imread(fn) @@ -60,5 +73,5 @@ if __name__ == '__main__': import sys try: fn = sys.argv[1] except: fn = '../cpp/fruits.jpg' - print help_message + print __doc__ App(fn).run()