3 print "OpenCV Python version of edge"
7 # import the necessary things for OpenCV
9 from opencv import highgui
13 trackbar_name = "Threshold"
15 # the callback on the trackbar
16 def on_trackbar (position):
18 cv.cvSmooth (gray, edge, cv.CV_BLUR, 3, 3, 0)
21 # run the edge dector on gray scale
22 cv.cvCanny (gray, edge, position, position * 3, 3)
25 cv.cvSetZero (col_edge)
28 cv.cvCopy (image, col_edge, edge)
31 highgui.cvShowImage (win_name, col_edge)
33 if __name__ == '__main__':
34 filename = "../c/fruits.jpg"
37 filename = sys.argv[1]
39 # load the image gived on the command line
40 image = highgui.cvLoadImage (filename)
43 print "Error loading image '%s'" % filename
46 # create the output image
47 col_edge = cv.cvCreateImage (cv.cvSize (image.width, image.height), 8, 3)
49 # convert to grayscale
50 gray = cv.cvCreateImage (cv.cvSize (image.width, image.height), 8, 1)
51 edge = cv.cvCreateImage (cv.cvSize (image.width, image.height), 8, 1)
52 cv.cvCvtColor (image, gray, cv.CV_BGR2GRAY)
55 highgui.cvNamedWindow (win_name, highgui.CV_WINDOW_AUTOSIZE)
58 highgui.cvCreateTrackbar (trackbar_name, win_name, 1, 100, on_trackbar)
63 # wait a key pressed to end