2 #pragma package <opencv>
5 #define CV_NO_BACKWARD_COMPATIBILITY
13 IplImage* image[2] = { 0, 0 }, *image0 = 0, *image1 = 0;
17 int threshold1, threshold2;
19 int sthreshold1, sthreshold2;
21 int block_size = 1000;
24 double rezult, min_rezult;
25 int filter = CV_GAUSSIAN_5x5;
26 CvConnectedComp *cur_comp, min_comp;
28 CvMemStorage *storage;
32 void ON_SEGMENT(int a)
34 cvPyrSegmentation(image0, image1, storage, &comp,
35 level, threshold1+1, threshold2+1);
37 /*l_comp = comp->total;
40 min_comp.value = cvScalarAll(0);
43 cur_comp = (CvConnectedComp*)cvGetSeqElem ( comp, i );
44 if(fabs(255- min_comp.value.val[0])>
45 fabs(255- cur_comp->value.val[0]) &&
46 fabs(min_comp.value.val[1])>
47 fabs(cur_comp->value.val[1]) &&
48 fabs(min_comp.value.val[2])>
49 fabs(cur_comp->value.val[2]) )
53 cvShowImage("Segmentation", image1);
56 int main( int argc, char** argv )
58 char* filename = argc == 2 ? argv[1] : (char*)"fruits.jpg";
60 if( (image[0] = cvLoadImage( filename, 1)) == 0 )
63 cvNamedWindow("Source", 0);
64 cvShowImage("Source", image[0]);
66 cvNamedWindow("Segmentation", 0);
68 storage = cvCreateMemStorage ( block_size );
70 image[0]->width &= -(1<<level);
71 image[0]->height &= -(1<<level);
73 image0 = cvCloneImage( image[0] );
74 image1 = cvCloneImage( image[0] );
75 // segmentation of the color image
82 sthreshold1 = cvCreateTrackbar("Threshold1", "Segmentation", &threshold1, 255, ON_SEGMENT);
83 sthreshold2 = cvCreateTrackbar("Threshold2", "Segmentation", &threshold2, 255, ON_SEGMENT);
85 cvShowImage("Segmentation", image1);
88 cvDestroyWindow("Segmentation");
89 cvDestroyWindow("Source");
91 cvReleaseMemStorage(&storage );
93 cvReleaseImage(&image[0]);
94 cvReleaseImage(&image0);
95 cvReleaseImage(&image1);
101 main(1,"pyramid_segmentation.c");