Update the changelog
[opencv] / apps / Hawk / demos / DemFloodFill.c
1 /************************************************************************************\r
2 *\r
3 *\r
4 *  This program is demonstration for functions cvFloodFill() and cvFloodFill8()\r
5 *\r
6 *\r
7 *  Trackbar specify maximal difference of the values of appurtenant to \r
8 *  repainted area pixel and one of its neighbors.\r
9 *\r
10 *  Autor:  Denis Burenkov\r
11 *\r
12 *\r
13 ************************************************************************************/\r
14 \r
15 char file_name[] = "EXPO0002.bmp";\r
16 \r
17 char wndname01[] = "Source image";\r
18 char wndname02[] = "Result image for cvFloodFill";\r
19 char wndname03[] = "Result image for cvFloodFill8";\r
20 char barname01[] = "Maximal difference";\r
21 int slider_pos[1] = {5};\r
22 \r
23 CvPoint seed;\r
24 CvConnectedComp comp;\r
25 \r
26 \r
27 // Load the source image. HighGUI use.\r
28 IPLIMAGE image01 = load_iplimage( file_name );\r
29 \r
30 if(image01==NULL)\r
31 {\r
32     printf("File '%s' not found.\n", file_name);\r
33     \r
34 }\r
35 \r
36 \r
37 // Create the destination images. HighGUI use.\r
38 IPLIMAGE image02 = cvCreateImage( cvSize(image01->width,image01->height),\r
39                                     IPL_DEPTH_8U,\r
40                                     1);\r
41 \r
42 IPLIMAGE image03 = cvCreateImage( cvSize(image01->width,image01->height),\r
43                                     IPL_DEPTH_8U,\r
44                                     1);\r
45 \r
46 \r
47 // Make onechannel image. IPL use.\r
48 cvCvtColor(image01,image02,CV_BGR2GRAY);\r
49 \r
50 \r
51 // Create windows. HighGUI use.\r
52 named_window( wndname01, 0 );\r
53 named_window( wndname02, 0 );\r
54 \r
55 \r
56 \r
57 // Specify coordinates of the seed point inside the image ROI.\r
58 seed.x=200;\r
59 seed.y=20;\r
60 \r
61 \r
62 // Define trackbar callback functons. This function make a\r
63 // flood filling of connected area of the image.\r
64 void on_trackbar_FloodFill( int h )\r
65 {\r
66 \r
67     cvCopyImage(image02 , image03);\r
68     \r
69     // Flood filling\r
70     cvFloodFill( image03, seed, 0, slider_pos[0], slider_pos[0], &comp,4);\r
71 \r
72     // Show the result image. HighGUI use.\r
73     show_iplimage( wndname02, image03 );\r
74 \r
75 }\r
76 \r
77 \r
78 \r
79 \r
80 // Create toolbars. HighGUI use.\r
81 create_trackbar( barname01, wndname02, &slider_pos[0], 30, on_trackbar_FloodFill );\r
82 \r
83 \r
84 \r
85 on_trackbar_FloodFill(0);\r
86 \r
87 \r
88 \r
89 // Show the source image. HighGUI use.\r
90 show_iplimage( wndname01, image02 );\r
91 \r
92 \r
93 // Wait for a key stroke; the same function arranges events processing                \r
94 wait_key(0);\r
95 cvReleaseImage(&image01);\r
96 cvReleaseImage(&image02);\r
97 cvReleaseImage(&image03);\r
98 \r
99 \r
100 destroy_window(wndname01);\r
101 destroy_window(wndname02);\r