Below is a C / C source code detected by the Canny operator, compiled in the OpenCV Beta 4.0, and the VC6.0 environment. For the use of the OpenCV library, please review the following related articles:
Http://forum.assuredigit.com/display_topic_threads.asp?forumid=11&topicid=3471
Run file download address:
http://www.assuredigit.com/program/edge.exe
=========
Program start
=========
#ifdef _ch_ # prgma package
#ENDIF
#ifndef _eic # include "CV.H" #include "highgui.h" #ENDIF
Char wndname [] = "edge"; char TBARNAME [] = "threshold"; int Edge_thresh = 1;
IPLIMAGE * image = 0, * CEDGE = 0, * Gray = 0, * Edge = 0;
// Define the Callback function void on_trackbar (int H) {CVSMooth (Gray, EDGE, CV_BLUR, CVSMOOTH; CVNOT (Gray, EDGE);
/ / The grayscale image detects Cvcanny (Gray, EDGE, (FLOAT) EDGE_THRESH, (FLOAT) EDGE_THRESH * 3, 3); CVZERO (CEDGE); // Copy Edge Points CVCopy (Image, Cedge, Edge); / / Display Image CvShowImage (WndName, Cedge);
INT main (int Argc, char ** argv) {char * filename = argc == 2? Argv [1]: (char *) "fruits.jpg"; if ((Image = CVLoadImage (filename, 1)) == 0) RETURN-1;
// Create the output image Cedge = CvcreateImage (cvsize (image-> width, image-> height), IPL_Depth_8u, 3);
// the color image is converted to grayscale gray = cvCreateImage (cvSize (image-> width, image-> height), IPL_DEPTH_8U, 1); edge = cvCreateImage (cvSize (image-> width, image-> height), IPL_DEPTH_8U , 1); CVCVTCOLOR (Image, Gray, CV_BGR2GRAY);
// Create a window cvnamedwindow (wndname, 1);
// Create a Toolbar CvcreateTrackbar (TBarname, WndName, & Edge_thresh, 100, ON_TRACKBAR);
// Show the image on_trackbar (0);
// Wait for a key stroke; The Same Function Arranges Events Processing CvwaitKey (0); CVRELEASEIMAGE (& Gray); CVRELEASEIMAGE (& Edge); CVDESTROYWINDOW (WNDNAME);
Return 0;}
#ifdef _eicmain (1, "Edge.c"); # ENDIF