The running result may be faulty. It is better to use the previous fixed value.
# Include "CV. H "# include" highgui. H "char wndname [] =" show "; char tbarname0 [] =" level "; char tbarname1 [] =" threshold1 "; char tbarname2 [] =" threshold2 "; int edge_thresh0 = 1; int edge_thresh1 = 50; iplimage * resize = 0; iplimage * DST = 0; void on_trackbar (INT h) {cvnamedwindow ("resize", 1 ); // show the image in the named window cvshowimage ("resize", resize); cvwaitkey (0); cvmemstorage * storage = cvcreatemstorage (0); cvseq * comp = NULL; cvpyrsegmentation (resize, DST, storage, & Comp, edge_thresh0, edge_thresh1, done * 3); cvreleasemstorage (& storage); // show the image in the named window cvshowimage (wndname, DST);} int main () {iplimage * src = cvloadimage ("D:/1.jpg", 1 ); // The image size must be divisible by 2 ^ level resize = cvcreateimage (cvsize (512,512), 512,512); DST = cvcreateimage (cvsize (),); cvresize (SRC, resize); cvnamedwindow (wndname, 1); cvcreatetrackbar (tbarname0, wndname, & found, 8, on_trackbar); cvcreatetrackbar (tbarname1, wndname, & found, 100, on_trackbar ); on_trackbar (1); // wait for a key stroke; the same function arranges events processing // press any key to exit. // clean up and don't be piggies cvwaitkey (0); cvreleaseimage (& SRC); cvreleaseimage (& DST); cvdestroywindow (wndname); Return 0 ;}