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 cvShowImage("Segmentation", image1);
43 int main( int argc, char** argv )
49 filename = argc == 2 ? argv[1] : (char*)"fruits.jpg";
51 if( (image[0] = cvLoadImage( filename, 1)) == 0 )
54 printf("Cannot load fileimage - %s\n", filename);
58 cvNamedWindow("Source", 0);
59 cvShowImage("Source", image[0]);
61 cvNamedWindow("Segmentation", 0);
63 storage = cvCreateMemStorage ( block_size );
65 image[0]->width &= -(1<<level);
66 image[0]->height &= -(1<<level);
68 image0 = cvCloneImage( image[0] );
69 image1 = cvCloneImage( image[0] );
70 // segmentation of the color image
77 sthreshold1 = cvCreateTrackbar("Threshold1", "Segmentation", &threshold1, 255, ON_SEGMENT);
78 sthreshold2 = cvCreateTrackbar("Threshold2", "Segmentation", &threshold2, 255, ON_SEGMENT);
80 cvShowImage("Segmentation", image1);
83 cvDestroyWindow("Segmentation");
84 cvDestroyWindow("Source");
86 cvReleaseMemStorage(&storage );
88 cvReleaseImage(&image[0]);
89 cvReleaseImage(&image0);
90 cvReleaseImage(&image1);
96 main(1,"pyramid_segmentation.c");