1 #include "opencv2/imgproc/imgproc_c.h"
2 #include "opencv2/highgui/highgui_c.h"
3 #include "opencv2/legacy.hpp"
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 static void ON_SEGMENT(int a)
37 cvPyrSegmentation(image0, image1, storage, &comp,
38 level, threshold1+1, threshold2+1);
40 cvShowImage("Segmentation", image1);
44 int main( int argc, char** argv )
50 filename = argc == 2 ? argv[1] : (char*)"fruits.jpg";
52 if( (image[0] = cvLoadImage( filename, 1)) == 0 )
55 printf("Cannot load fileimage - %s\n", filename);
59 cvNamedWindow("Source", 0);
60 cvShowImage("Source", image[0]);
62 cvNamedWindow("Segmentation", 0);
64 storage = cvCreateMemStorage ( block_size );
66 image[0]->width &= -(1<<level);
67 image[0]->height &= -(1<<level);
69 image0 = cvCloneImage( image[0] );
70 image1 = cvCloneImage( image[0] );
71 // segmentation of the color image
78 sthreshold1 = cvCreateTrackbar("Threshold1", "Segmentation", &threshold1, 255, ON_SEGMENT);
79 sthreshold2 = cvCreateTrackbar("Threshold2", "Segmentation", &threshold2, 255, ON_SEGMENT);
81 cvShowImage("Segmentation", image1);
84 cvDestroyWindow("Segmentation");
85 cvDestroyWindow("Source");
87 cvReleaseMemStorage(&storage );
89 cvReleaseImage(&image[0]);
90 cvReleaseImage(&image0);
91 cvReleaseImage(&image1);
97 main(1,"pyramid_segmentation.c");