Update the changelog
[opencv] / apps / Hawk / demos / pyramid_segmentation.c
1 IPLIMAGE  image[2], image0, image1;\r
2 CvSize size;\r
3 \r
4 int  w0, h0,i;\r
5 int  threshold1, threshold2;\r
6 int  l,level;\r
7 int sthreshold1, sthreshold2;\r
8 int  l_comp;\r
9 int block_size = 1000;\r
10 float  parameter;\r
11 double threshold;\r
12 double rezult, min_rezult;\r
13 CvFilter filter = CV_GAUSSIAN_5x5;\r
14 CvConnectedComp *cur_comp, min_comp;\r
15 CvSeq *comp;\r
16 CvMemStorage *storage;\r
17 \r
18 CvPoint pt1, pt2;\r
19 \r
20 void ON_SEGMENT(int a)\r
21 {       \r
22     \r
23     cvPyrSegmentation(image0, image1, storage, &comp, \r
24                       level, threshold1, threshold2);\r
25 \r
26         l_comp = comp->total;\r
27 \r
28     printf("  l_comp = %d \n ",l_comp);\r
29         i = 0;\r
30     min_comp.value = 0;\r
31         while(i<l_comp)\r
32         {\r
33         cur_comp = (CvConnectedComp*)cvGetSeqElem ( comp, i, 0);\r
34         if(fabs(CV_RGB(255,0,0)- min_comp.value)>\r
35            fabs(CV_RGB(255,0,0)- cur_comp->value))\r
36            min_comp = *cur_comp;\r
37 /*          \r
38     pt1.x = cur_comp->rect.x;\r
39         pt2.x = cur_comp->rect.x + cur_comp->rect.width;\r
40         pt1.y = cur_comp->rect.y;\r
41         pt2.y = cur_comp->rect.y + cur_comp->rect.height;\r
42     cvRectangle(image1, pt1, pt2, 255, 3);\r
43 */               \r
44         i++;\r
45         }\r
46 /*    \r
47     pt1.x = min_comp.rect.x;\r
48         pt2.x = min_comp.rect.x + min_comp.rect.width;\r
49         pt1.y = min_comp.rect.y;\r
50         pt2.y = min_comp.rect.y + min_comp.rect.height;\r
51     cvRectangle(image1, pt1, pt2, 255, 3);\r
52 */    \r
53 //    bitmap1 = get_image_cv(image1);\r
54     show_iplimage("Segmentation", image1);\r
55 \r
56 \r
57 };\r
58 \r
59 image[0] = load_iplimage("..\\Bitmaps\\parrot.bmp");\r
60 \r
61 named_window("Source", 0);\r
62 show_iplimage("Source", image[0]);\r
63 wait_key(0);\r
64 \r
65 printf("\n i = %d width = %d height = %d", i,size.width, size.height);   \r
66 \r
67 \r
68 named_window("Segmentation", 0);\r
69 \r
70 \r
71 storage = cvCreateMemStorage ( block_size );\r
72 \r
73 image0 = cvCreateImage(cvSize(image[0]->width, image[0]->height), IPL_DEPTH_8U, 3);\r
74 image1 = cvCreateImage(cvSize(image[0]->width, image[0]->height), IPL_DEPTH_8U, 3);\r
75 cvCopy(image[0],image0,0); \r
76 image0->roi = NULL;\r
77 image1->roi = NULL;\r
78 // segmentation of the color image\r
79 l = 1;\r
80 level =4;\r
81 threshold1 =255;\r
82 threshold2 =30;\r
83 \r
84 \r
85 ON_SEGMENT(1);\r
86 \r
87 sthreshold1 = create_slider("Threshold1", "Segmentation", &threshold1, 255, ON_SEGMENT);\r
88 sthreshold2 = create_slider("Threshold2", "Segmentation",  &threshold2, 255, ON_SEGMENT);\r
89 \r
90 show_iplimage("Segmentation", image1);\r
91 wait_key(0);\r
92 \r
93 destroy_window("Segmentation");\r
94 destroy_window("Source");\r
95 \r
96 cvReleaseMemStorage (&storage );\r
97 \r
98 \r
99 cvReleaseImage  (&image[0]);\r
100 cvReleaseImage  (&image0);\r
101 cvReleaseImage  (&image1);\r
102 \r