Update to 2.0.0 tree from current Fremantle build
[opencv] / samples / c / edge.c
1 #ifdef _CH_
2 #pragma package <opencv>
3 #endif
4
5 #define CV_NO_BACKWARD_COMPATIBILITY
6
7 #ifndef _EiC
8 #include "cv.h"
9 #include "highgui.h"
10 #endif
11
12 char wndname[] = "Edge";
13 char tbarname[] = "Threshold";
14 int edge_thresh = 1;
15
16 IplImage *image = 0, *cedge = 0, *gray = 0, *edge = 0;
17
18 // define a trackbar callback
19 void on_trackbar(int h)
20 {
21     cvSmooth( gray, edge, CV_BLUR, 3, 3, 0, 0 );
22     cvNot( gray, edge );
23
24     // Run the edge detector on grayscale
25     cvCanny(gray, edge, (float)edge_thresh, (float)edge_thresh*3, 3);
26
27     cvZero( cedge );
28     // copy edge points
29     cvCopy( image, cedge, edge );
30
31     cvShowImage(wndname, cedge);
32 }
33
34 int main( int argc, char** argv )
35 {
36     char* filename = argc == 2 ? argv[1] : (char*)"fruits.jpg";
37
38     if( (image = cvLoadImage( filename, 1)) == 0 )
39         return -1;
40
41     // Create the output image
42     cedge = cvCreateImage(cvSize(image->width,image->height), IPL_DEPTH_8U, 3);
43
44     // Convert to grayscale
45     gray = cvCreateImage(cvSize(image->width,image->height), IPL_DEPTH_8U, 1);
46     edge = cvCreateImage(cvSize(image->width,image->height), IPL_DEPTH_8U, 1);
47     cvCvtColor(image, gray, CV_BGR2GRAY);
48
49     // Create a window
50     cvNamedWindow(wndname, 1);
51
52     // create a toolbar
53     cvCreateTrackbar(tbarname, wndname, &edge_thresh, 100, on_trackbar);
54
55     // Show the image
56     on_trackbar(0);
57
58     // Wait for a key stroke; the same function arranges events processing
59     cvWaitKey(0);
60     cvReleaseImage(&image);
61     cvReleaseImage(&gray);
62     cvReleaseImage(&edge);
63     cvDestroyWindow(wndname);
64
65     return 0;
66 }
67
68 #ifdef _EiC
69 main(1,"edge.c");
70 #endif