1 #include "opencv2/imgproc/imgproc.hpp"
2 #include "opencv2/highgui/highgui.hpp"
4 IplImage* image[2] = { 0, 0 }, *image0 = 0, *image1 = 0;
8 int threshold1, threshold2;
10 int sthreshold1, sthreshold2;
12 int block_size = 1000;
15 double rezult, min_rezult;
16 int filter = CV_GAUSSIAN_5x5;
17 CvConnectedComp *cur_comp, min_comp;
19 CvMemStorage *storage;
23 void ON_SEGMENT(int a)
25 cvPyrSegmentation(image0, image1, storage, &comp,
26 level, threshold1+1, threshold2+1);
28 /*l_comp = comp->total;
31 min_comp.value = cvScalarAll(0);
34 cur_comp = (CvConnectedComp*)cvGetSeqElem ( comp, i );
35 if(fabs(255- min_comp.value.val[0])>
36 fabs(255- cur_comp->value.val[0]) &&
37 fabs(min_comp.value.val[1])>
38 fabs(cur_comp->value.val[1]) &&
39 fabs(min_comp.value.val[2])>
40 fabs(cur_comp->value.val[2]) )
44 cvShowImage("Segmentation", image1);
47 int main( int argc, char** argv )
49 char* filename = argc == 2 ? argv[1] : (char*)"fruits.jpg";
51 if( (image[0] = cvLoadImage( filename, 1)) == 0 )
54 cvNamedWindow("Source", 0);
55 cvShowImage("Source", image[0]);
57 cvNamedWindow("Segmentation", 0);
59 storage = cvCreateMemStorage ( block_size );
61 image[0]->width &= -(1<<level);
62 image[0]->height &= -(1<<level);
64 image0 = cvCloneImage( image[0] );
65 image1 = cvCloneImage( image[0] );
66 // segmentation of the color image
73 sthreshold1 = cvCreateTrackbar("Threshold1", "Segmentation", &threshold1, 255, ON_SEGMENT);
74 sthreshold2 = cvCreateTrackbar("Threshold2", "Segmentation", &threshold2, 255, ON_SEGMENT);
76 cvShowImage("Segmentation", image1);
79 cvDestroyWindow("Segmentation");
80 cvDestroyWindow("Source");
82 cvReleaseMemStorage(&storage );
84 cvReleaseImage(&image[0]);
85 cvReleaseImage(&image0);
86 cvReleaseImage(&image1);
92 main(1,"pyramid_segmentation.c");