lot's of changes; nonfree & photo modules added; SIFT & SURF -> nonfree module; Inpai...
[profile/ivi/opencv.git] / samples / c / pyramid_segmentation.c
1 #include "opencv2/imgproc/imgproc.hpp"
2 #include "opencv2/highgui/highgui.hpp"
3 #include "opencv2/imgproc/imgproc_c.h"
4 #include <stdio.h>
5
6 void help()
7 {
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"
10             "Usage :\n"
11                         "./pyaramid_segmentation [image_path_filename -- Defaults to fruits.jpg]\n\n"
12                         );
13 }
14
15 IplImage*  image[2] = { 0, 0 }, *image0 = 0, *image1 = 0;
16 CvSize size;
17
18 int  w0, h0,i;
19 int  threshold1, threshold2;
20 int  l,level = 4;
21 int sthreshold1, sthreshold2;
22 int  l_comp;
23 int block_size = 1000;
24 float  parameter;
25 double threshold;
26 double rezult, min_rezult;
27 int filter = CV_GAUSSIAN_5x5;
28 CvConnectedComp *cur_comp, min_comp;
29 CvSeq *comp;
30 CvMemStorage *storage;
31
32 CvPoint pt1, pt2;
33
34 void ON_SEGMENT(int a)
35 {
36     cvPyrSegmentation(image0, image1, storage, &comp,
37                       level, threshold1+1, threshold2+1);
38
39     cvShowImage("Segmentation", image1);
40 }
41
42
43 int main( int argc, char** argv )
44 {
45     char* filename;
46
47     help();
48
49     filename = argc == 2 ? argv[1] : (char*)"fruits.jpg";
50
51     if( (image[0] = cvLoadImage( filename, 1)) == 0 )
52     {
53         help();
54         printf("Cannot load fileimage - %s\n", filename);
55         return -1;
56     }
57
58     cvNamedWindow("Source", 0);
59     cvShowImage("Source", image[0]);
60
61     cvNamedWindow("Segmentation", 0);
62
63     storage = cvCreateMemStorage ( block_size );
64
65     image[0]->width &= -(1<<level);
66     image[0]->height &= -(1<<level);
67
68     image0 = cvCloneImage( image[0] );
69     image1 = cvCloneImage( image[0] );
70     // segmentation of the color image
71     l = 1;
72     threshold1 =255;
73     threshold2 =30;
74
75     ON_SEGMENT(1);
76
77     sthreshold1 = cvCreateTrackbar("Threshold1", "Segmentation", &threshold1, 255, ON_SEGMENT);
78     sthreshold2 = cvCreateTrackbar("Threshold2", "Segmentation",  &threshold2, 255, ON_SEGMENT);
79
80     cvShowImage("Segmentation", image1);
81     cvWaitKey(0);
82
83     cvDestroyWindow("Segmentation");
84     cvDestroyWindow("Source");
85
86     cvReleaseMemStorage(&storage );
87
88     cvReleaseImage(&image[0]);
89     cvReleaseImage(&image0);
90     cvReleaseImage(&image1);
91
92     return 0;
93 }
94
95 #ifdef _EiC
96 main(1,"pyramid_segmentation.c");
97 #endif