From d9185ec21b42198b55b97bef119a9621da34258a Mon Sep 17 00:00:00 2001 From: Alexander Mordvintesv Date: Wed, 22 Aug 2012 16:42:19 +0300 Subject: [PATCH] added _doc.py -- doc-string ckecking utility added some sample description --- samples/python2/_coverage.py | 37 ++++++++++++++++++++--------------- samples/python2/_doc.py | 14 +++++++++++++ samples/python2/common.py | 4 ++++ samples/python2/demo.py | 4 ++++ samples/python2/distrans.py | 17 ++++++++++------ samples/python2/floodfill.py | 14 ++++++++----- samples/python2/inpaint.py | 17 +++++++++++----- samples/python2/morphology.py | 18 +++++++++++++---- samples/python2/squares.py | 6 ++++++ 9 files changed, 95 insertions(+), 36 deletions(-) create mode 100644 samples/python2/_doc.py diff --git a/samples/python2/_coverage.py b/samples/python2/_coverage.py index e64c7c9bcb..3a365dc589 100644 --- a/samples/python2/_coverage.py +++ b/samples/python2/_coverage.py @@ -1,24 +1,29 @@ +''' +Utility for measuring python opencv API coverage by samples. +''' + from glob import glob import cv2 import re -cv2_callable = set(['cv2.'+name for name in dir(cv2) if callable( getattr(cv2, name) )]) +if __name__ == '__main__': + cv2_callable = set(['cv2.'+name for name in dir(cv2) if callable( getattr(cv2, name) )]) -found = set() -for fn in glob('*.py'): - print ' --- ', fn - code = open(fn).read() - found |= set(re.findall('cv2?\.\w+', code)) + found = set() + for fn in glob('*.py'): + print ' --- ', fn + code = open(fn).read() + found |= set(re.findall('cv2?\.\w+', code)) -cv2_used = found & cv2_callable -cv2_unused = cv2_callable - cv2_used -with open('unused_api.txt', 'w') as f: - f.write('\n'.join(sorted(cv2_unused))) + cv2_used = found & cv2_callable + cv2_unused = cv2_callable - cv2_used + with open('unused_api.txt', 'w') as f: + f.write('\n'.join(sorted(cv2_unused))) -r = 1.0 * len(cv2_used) / len(cv2_callable) -print '\ncv2 api coverage: %d / %d (%.1f%%)' % ( len(cv2_used), len(cv2_callable), r*100 ) + r = 1.0 * len(cv2_used) / len(cv2_callable) + print '\ncv2 api coverage: %d / %d (%.1f%%)' % ( len(cv2_used), len(cv2_callable), r*100 ) -print '\nold (cv) symbols:' -for s in found: - if s.startswith('cv.'): - print s + print '\nold (cv) symbols:' + for s in found: + if s.startswith('cv.'): + print s diff --git a/samples/python2/_doc.py b/samples/python2/_doc.py new file mode 100644 index 0000000000..1204ae65a5 --- /dev/null +++ b/samples/python2/_doc.py @@ -0,0 +1,14 @@ +''' +Scans current directory for *.py files and reports +ones with missing __doc__ string. +''' + +from glob import glob + +if __name__ == '__main__': + print '--- undocumented files:' + for fn in glob('*.py'): + loc = {} + execfile(fn, loc) + if '__doc__' not in loc: + print fn diff --git a/samples/python2/common.py b/samples/python2/common.py index 883aa9ae23..5415942d5a 100644 --- a/samples/python2/common.py +++ b/samples/python2/common.py @@ -1,3 +1,7 @@ +''' +This module contais some common routines used by other samples. +''' + import numpy as np import cv2 import os diff --git a/samples/python2/demo.py b/samples/python2/demo.py index 3f75703303..9dd7779e19 100644 --- a/samples/python2/demo.py +++ b/samples/python2/demo.py @@ -1,3 +1,7 @@ +''' +Sample-launcher application. +''' + import Tkinter as tk from ScrolledText import ScrolledText from glob import glob diff --git a/samples/python2/distrans.py b/samples/python2/distrans.py index 2cbca0ca20..15b1fac425 100644 --- a/samples/python2/distrans.py +++ b/samples/python2/distrans.py @@ -1,20 +1,25 @@ -import numpy as np -import cv2 -import cv2.cv as cv -from common import make_cmap +''' +Distance transform sample. -help_message = '''USAGE: distrans.py [] +Usage: + distrans.py [] Keys: ESC - exit v - toggle voronoi mode ''' + +import numpy as np +import cv2 +import cv2.cv as cv +from common import make_cmap + if __name__ == '__main__': import sys try: fn = sys.argv[1] except: fn = '../cpp/fruits.jpg' - print help_message + print __doc__ img = cv2.imread(fn, 0) cm = make_cmap('jet') diff --git a/samples/python2/floodfill.py b/samples/python2/floodfill.py index c2d0d70578..7ddc4c01df 100644 --- a/samples/python2/floodfill.py +++ b/samples/python2/floodfill.py @@ -1,9 +1,10 @@ -import numpy as np -import cv2 +''' +Floodfill sample. -help_message = '''USAGE: floodfill.py [] +Usage: + floodfill.py [] -Click on the image to set seed point + Click on the image to set seed point Keys: f - toggle floating range @@ -11,11 +12,14 @@ Keys: ESC - exit ''' +import numpy as np +import cv2 + if __name__ == '__main__': import sys try: fn = sys.argv[1] except: fn = '../cpp/fruits.jpg' - print help_message + print __doc__ img = cv2.imread(fn, True) h, w = img.shape[:2] diff --git a/samples/python2/inpaint.py b/samples/python2/inpaint.py index 6a52d01627..9ed6bab101 100644 --- a/samples/python2/inpaint.py +++ b/samples/python2/inpaint.py @@ -1,8 +1,11 @@ -import numpy as np -import cv2 -from common import Sketcher +''' +Inpainting sample. -help_message = '''USAGE: inpaint.py [] +Inpainting repairs damage to images by floodfilling +the damage with surrounding image areas. + +Usage: + inpaint.py [] Keys: SPACE - inpaint @@ -10,11 +13,15 @@ Keys: ESC - exit ''' +import numpy as np +import cv2 +from common import Sketcher + if __name__ == '__main__': import sys try: fn = sys.argv[1] except: fn = '../cpp/fruits.jpg' - print help_message + print __doc__ img = cv2.imread(fn) img_mark = img.copy() diff --git a/samples/python2/morphology.py b/samples/python2/morphology.py index b7f84fbb28..b2f6e0ebfd 100644 --- a/samples/python2/morphology.py +++ b/samples/python2/morphology.py @@ -1,8 +1,22 @@ +''' +Morphology operations. + +Usage: + morphology.py [] + +Keys: + 1 - change operation + 2 - change structure element shape + ESC - exit +''' + import numpy as np import cv2 if __name__ == '__main__': + print __doc__ + import sys from itertools import cycle from common import draw_str @@ -44,10 +58,6 @@ if __name__ == '__main__': cv2.createTrackbar('op/size', 'morphology', 12, 20, update) cv2.createTrackbar('iters', 'morphology', 1, 10, update) update() - print "Controls:" - print " 1 - change operation" - print " 2 - change structure element shape" - print while True: ch = 0xFF & cv2.waitKey() if ch == 27: diff --git a/samples/python2/squares.py b/samples/python2/squares.py index 6c6b899d83..60b04f2882 100644 --- a/samples/python2/squares.py +++ b/samples/python2/squares.py @@ -1,3 +1,9 @@ +''' +Simple "Square Detector" program. + +Loads several images sequentially and tries to find squares in each image. +''' + import numpy as np import cv2