1 #include "opencv2/imgproc/imgproc.hpp"
2 #include "opencv2/highgui/highgui.hpp"
3 #include "opencv2/imgproc/imgproc_c.h"
8 printf("\nThis program demonstrated color pyramid segmentation cvcvPyrSegmentation() which is controlled\n"
9 "by two trhesholds which can be manipulated by a trackbar. It can take an image file name or defaults to 'fruits.jpg'\n"
11 "./pyaramid_segmentation [image_path_filename -- Defaults to fruits.jpg]\n\n"
15 IplImage* image[2] = { 0, 0 }, *image0 = 0, *image1 = 0;
19 int threshold1, threshold2;
21 int sthreshold1, sthreshold2;
23 int block_size = 1000;
26 double rezult, min_rezult;
27 int filter = CV_GAUSSIAN_5x5;
28 CvConnectedComp *cur_comp, min_comp;
30 CvMemStorage *storage;
34 void ON_SEGMENT(int a)
36 cvPyrSegmentation(image0, image1, storage, &comp,
37 level, threshold1+1, threshold2+1);
39 /*l_comp = comp->total;
42 min_comp.value = cvScalarAll(0);
45 cur_comp = (CvConnectedComp*)cvGetSeqElem ( comp, i );
46 if(fabs(255- min_comp.value.val[0])>
47 fabs(255- cur_comp->value.val[0]) &&
48 fabs(min_comp.value.val[1])>
49 fabs(cur_comp->value.val[1]) &&
50 fabs(min_comp.value.val[2])>
51 fabs(cur_comp->value.val[2]) )
55 cvShowImage("Segmentation", image1);
59 int main( int argc, char** argv )
61 char* filename = argc == 2 ? argv[1] : (char*)"fruits.jpg";
63 if( (image[0] = cvLoadImage( filename, 1)) == 0 )
66 cvNamedWindow("Source", 0);
67 cvShowImage("Source", image[0]);
69 cvNamedWindow("Segmentation", 0);
71 storage = cvCreateMemStorage ( block_size );
73 image[0]->width &= -(1<<level);
74 image[0]->height &= -(1<<level);
76 image0 = cvCloneImage( image[0] );
77 image1 = cvCloneImage( image[0] );
78 // segmentation of the color image
85 sthreshold1 = cvCreateTrackbar("Threshold1", "Segmentation", &threshold1, 255, ON_SEGMENT);
86 sthreshold2 = cvCreateTrackbar("Threshold2", "Segmentation", &threshold2, 255, ON_SEGMENT);
88 cvShowImage("Segmentation", image1);
91 cvDestroyWindow("Segmentation");
92 cvDestroyWindow("Source");
94 cvReleaseMemStorage(&storage );
96 cvReleaseImage(&image[0]);
97 cvReleaseImage(&image0);
98 cvReleaseImage(&image1);
104 main(1,"pyramid_segmentation.c");