Package pyvision :: Package edge :: Module canny
[hide private]
[frames] | no frames]

Source Code for Module pyvision.edge.canny

  1  # PyVision License 
  2  # 
  3  # Copyright (c) 2006-2008 David S. Bolme 
  4  # All rights reserved. 
  5  # 
  6  # Redistribution and use in source and binary forms, with or without 
  7  # modification, are permitted provided that the following conditions 
  8  # are met: 
  9  #  
 10  # 1. Redistributions of source code must retain the above copyright 
 11  # notice, this list of conditions and the following disclaimer. 
 12  #  
 13  # 2. Redistributions in binary form must reproduce the above copyright 
 14  # notice, this list of conditions and the following disclaimer in the 
 15  # documentation and/or other materials provided with the distribution. 
 16  #  
 17  # 3. Neither name of copyright holders nor the names of its contributors 
 18  # may be used to endorse or promote products derived from this software 
 19  # without specific prior written permission. 
 20  #  
 21  #  
 22  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 23  # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 24  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 25  # A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR 
 26  # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
 27  # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
 28  # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
 29  # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
 30  # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
 31  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
 32  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 33   
 34  import unittest 
 35  import os.path 
 36   
 37  import cv 
 38   
 39  import pyvision as pv 
 40   
 41  #import numpy as np 
 42  #from scipy.ndimage import convolve 
 43  #from scipy.ndimage import maximum_filter 
 44   
 45   
46 -def canny(im,threshold1=40.0,threshold2=100.0,aperture_size=3,sigma=None):
47 ''' 48 void cvCanny( const CvArr* image, CvArr* edges, double threshold1, double threshold2, int aperture_size=3 ); 49 ''' 50 gray = im.asOpenCVBW() 51 edges = cv.CreateImage( cv.GetSize(gray), 8, 1 ); 52 53 54 if sigma!=None: 55 cv.Smooth(gray,gray,cv.CV_GAUSSIAN,int(sigma+1)*4+1,int(sigma+1)*4+1,sigma,sigma) 56 if threshold1 < threshold2: 57 threshold1, threshold2 = threshold2,threshold1 58 cv.Canny(gray,edges,threshold1,threshold2 ,aperture_size) 59 60 return pv.Image(edges)
61 62
63 -class _TestCanny(unittest.TestCase):
64 ''' Unit tests for the canny detector''' 65
66 - def setUp(self):
67 self.show_results = False
68 69
70 - def test_canny1(self):
71 ''' 72 This will run the code, but what is a good test for canny? 73 ''' 74 filename = os.path.join(pv.__path__[0],'data','nonface','NONFACE_46.jpg') 75 76 img = pv.Image(filename) 77 out = canny(img) 78 if self.show_results: out.show()
79 80
81 - def test_canny2(self):
82 ''' 83 This will run the code, but what is a good test for canny? 84 ''' 85 filename = os.path.join(pv.__path__[0],'data','nonface','NONFACE_10.jpg') 86 87 img = pv.Image(filename) 88 out = canny(img) 89 if self.show_results: out.show()
90 91
92 - def test_canny3(self):
93 ''' 94 This will run the code, but what is a good test for canny? 95 ''' 96 filename = os.path.join(pv.__path__[0],'data','nonface','NONFACE_22.jpg') 97 98 img = pv.Image(filename) 99 out = canny(img) 100 if self.show_results: out.show()
101 102
103 - def test_canny4(self):
104 ''' 105 This will run the code, but what is a good test for canny? 106 ''' 107 filename = os.path.join(pv.__path__[0],'data','nonface','NONFACE_44.jpg') 108 109 img = pv.Image(filename) 110 out = canny(img) 111 if self.show_results: out.show()
112
113 - def test_canny5(self):
114 ''' 115 This will run the code, but what is a good test for canny? 116 ''' 117 filename = os.path.join(pv.__path__[0],'data','nonface','NONFACE_37.jpg') 118 119 img = pv.Image(filename) 120 out = canny(img) 121 if self.show_results: out.show()
122