Update to 2.0.0 tree from current Fremantle build
[opencv] / samples / octave / edge.m
1 #! /usr/bin/env octave
2
3 printf("OpenCV Octave version of edge\n");
4
5 global g;
6
7 ## import the necessary things for OpenCV
8 cv;
9 highgui;
10
11 ## some definitions
12 g.win_name = "Edge";
13 g.trackbar_name = "Threshold";
14
15 ## the callback on the trackbar
16 function on_trackbar (position)
17   global g;
18   global cv;
19   global highgui;
20
21   cv.cvSmooth (g.gray, g.edge, cv.CV_BLUR, 3, 3, 0);
22   cv.cvNot (g.gray, g.edge);
23
24   ## run the edge dector on gray scale
25   cv.cvCanny (g.gray, g.edge, position, position * 3, 3);
26
27   ## reset
28   cv.cvSetZero (g.col_edge);
29
30   ## copy edge points
31   cv.cvCopy (g.image, g.col_edge, g.edge);
32   
33   ## show the image
34   highgui.cvShowImage (g.win_name, g.col_edge);
35 endfunction
36
37 filename = "../c/fruits.jpg";
38
39 if (size(argv, 1)>1)
40   filename = argv(){1};
41 endif
42
43 ## load the image gived on the command line
44 g.image = highgui.cvLoadImage (filename);
45
46 if (!swig_this(g.image))
47   printf("Error loading image '%s'",filename);
48   exit(-1);
49 endif
50
51 ## create the output image
52 g.col_edge = cv.cvCreateImage (cv.cvSize (g.image.width, g.image.height), 8, 3);
53
54 ## convert to grayscale
55 g.gray = cv.cvCreateImage (cv.cvSize (g.image.width, g.image.height), 8, 1);
56 g.edge = cv.cvCreateImage (cv.cvSize (g.image.width, g.image.height), 8, 1);
57 cv.cvCvtColor (g.image, g.gray, cv.CV_BGR2GRAY);
58
59 ## create the window
60 highgui.cvNamedWindow (g.win_name, highgui.CV_WINDOW_AUTOSIZE);
61
62 ## create the trackbar
63 highgui.cvCreateTrackbar (g.trackbar_name, g.win_name, 1, 100, @on_trackbar);
64
65 ## show the image
66 on_trackbar (0);
67
68 ## wait a key pressed to end
69 highgui.cvWaitKey (0);