1 #include <opencv2/imgproc/imgproc.hpp>
2 #include <opencv2/highgui/highgui.hpp>
4 char wndname[] = "Edge";
5 char tbarname[] = "Threshold";
8 IplImage *image = 0, *cedge = 0, *gray = 0, *edge = 0;
10 // define a trackbar callback
11 void on_trackbar(int h)
13 cvSmooth( gray, edge, CV_BLUR, 3, 3, 0, 0 );
16 // Run the edge detector on grayscale
17 cvCanny(gray, edge, (float)edge_thresh, (float)edge_thresh*3, 3);
21 cvCopy( image, cedge, edge );
23 cvShowImage(wndname, cedge);
26 int main( int argc, char** argv )
28 char* filename = argc == 2 ? argv[1] : (char*)"fruits.jpg";
30 if( (image = cvLoadImage( filename, 1)) == 0 )
33 // Create the output image
34 cedge = cvCreateImage(cvSize(image->width,image->height), IPL_DEPTH_8U, 3);
36 // Convert to grayscale
37 gray = cvCreateImage(cvSize(image->width,image->height), IPL_DEPTH_8U, 1);
38 edge = cvCreateImage(cvSize(image->width,image->height), IPL_DEPTH_8U, 1);
39 cvCvtColor(image, gray, CV_BGR2GRAY);
42 cvNamedWindow(wndname, 1);
45 cvCreateTrackbar(tbarname, wndname, &edge_thresh, 100, on_trackbar);
50 // Wait for a key stroke; the same function arranges events processing
52 cvReleaseImage(&image);
53 cvReleaseImage(&gray);
54 cvReleaseImage(&edge);
55 cvDestroyWindow(wndname);