refactor logger in linef
authorTomas Musil <tomik.musil@gmail.com>
Thu, 26 Jun 2014 18:18:15 +0000 (20:18 +0200)
committerTomas Musil <tomik.musil@gmail.com>
Thu, 26 Jun 2014 18:18:15 +0000 (20:18 +0200)
imago_pack/intrsc.py
imago_pack/linef.py

index d577205..9fabcd5 100644 (file)
@@ -26,6 +26,7 @@ def dst_sort(lines):
 
 def board(image, lines, show_all, do_something):
     """Compute intersections, find stone colors and return board situation."""
+    # TODO refactor show_all, do_something
     lines = [dst_sort(l) for l in lines]
     intersections = intersections_from_angl_dist(lines, image.size)
 
index 77383b7..667442c 100644 (file)
@@ -13,13 +13,12 @@ except ImportError, msg:
 import filters
 from hough import Hough
 
-def prepare(image, show_image, verbose):
+def prepare(image, show_image, logger):
     # TODO comment
     im_l = image.convert('L')
     show_image(im_l, "ITU-R 601-2 luma transform")
 
-    if verbose:
-        print >> sys.stderr, "edge detection"
+    logger("edge detection")
     im_edges = filters.edge_detection(im_l)
     show_image(im_edges, "edge detection")
 
@@ -47,23 +46,26 @@ def transform(image, hough, show_image):
 def find_lines(image, show_image, verbose):
     """Find lines in the *image*."""
     # TODO refactor into smaller functions
-
+    
     if verbose:
-        print >> sys.stderr, "preprocessing"
-
+        def logger(m):
+            print >> sys.stderr, m
+    else:
+        def logger(m):
+            pass
+        
+    logger("preprocessing")
     show_image(image, "original image")
 
-    im_h = prepare(image, show_image, verbose)
+    im_h = prepare(image, show_image, logger)
 
     hough = Hough.default(im_h)
 
-    if verbose:
-        print >> sys.stderr, "hough transform"
+    logger("hough transform")
     
     im_h2 = transform(im_h, hough, show_image)
 
-    if verbose:
-        print >> sys.stderr, "second hough transform"
+    logger("second hough transform")
 
     # im_hough might be used instead im_h2, but at the moment it brings a lot of
     # noise to the second transform, which later confuses the center-finding
@@ -78,8 +80,7 @@ def find_lines(image, show_image, verbose):
     im_h3 = filters.components(im_h3)
     show_image(im_h3, "half centers")
 
-    if verbose:
-        print >> sys.stderr, "finding the grid"
+    logger("finding the grid")
 
     lines_m = hough2.all_lines_h(im_h3)
     lines = []