1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 import unittest
35 import os.path
36
37 import cv
38
39 import pyvision as pv
40
41
42
43
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
64 ''' Unit tests for the canny detector'''
65
67 self.show_results = False
68
69
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
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
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
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
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