3 from opencv.cv import *
4 from opencv.highgui import *
12 filter = CV_GAUSSIAN_5x5;
14 min_comp = CvConnectedComp()
16 def set_thresh1( val ):
21 def set_thresh2( val ):
29 comp = cvPyrSegmentation(image0, image1, storage, level, threshold1+1, threshold2+1);
30 cvShowImage("Segmentation", image1);
32 if __name__ == "__main__":
33 filename = "../c/fruits.jpg";
34 if len(sys.argv) == 2:
35 filename = sys.argv[1]
36 image[0] = cvLoadImage( filename, 1)
38 print "Error opening %s" % filename
41 cvNamedWindow("Source", 0);
42 cvShowImage("Source", image[0]);
43 cvNamedWindow("Segmentation", 0);
44 storage = cvCreateMemStorage ( block_size );
45 image[0].width &= -(1<<level);
46 image[0].height &= -(1<<level);
47 image0 = cvCloneImage( image[0] );
48 image1 = cvCloneImage( image[0] );
49 # segmentation of the color image
54 sthreshold1 = cvCreateTrackbar("Threshold1", "Segmentation", threshold1, 255, set_thresh1);
55 sthreshold2 = cvCreateTrackbar("Threshold2", "Segmentation", threshold2, 255, set_thresh2);
56 cvShowImage("Segmentation", image1);
58 cvDestroyWindow("Segmentation");
59 cvDestroyWindow("Source");