学习OpenCV——金字塔分割(Trackbar)

 运行结果可能会出问题,还是用上一篇的定值效果比较好。

#include"cv.h"
#include"highgui.h"

char wndname[] = "Show";
char tbarname0[] = "Level";
char tbarname1[] = "Threshold1";
char tbarname2[] = "Threshold2";
int edge_thresh0 = 1;
int edge_thresh1 = 50;

IplImage* resize=0;
IplImage* dst=0;

void on_trackbar(int h)
{
	cvNamedWindow( "resize", 1 );      
	// Show the image in the named window       
	cvShowImage( "resize", resize );
	cvWaitKey(0);
	CvMemStorage* storage = cvCreateMemStorage(0);
	CvSeq* comp = NULL;
	cvPyrSegmentation(resize,dst,storage,&comp,edge_thresh0, edge_thresh1, edge_thresh1*3);
	cvReleaseMemStorage(&storage);
        
	// Show the image in the named window       
	cvShowImage( wndname, dst );
	
}

int main()
{
	IplImage* src=cvLoadImage("D:/1.jpg",1);
	//图像大小必须能被2^level整除
	resize=cvCreateImage(cvSize(512,512),8,3);
	dst=cvCreateImage(cvSize(512,512),8,3);
	cvResize(src,resize);
	 cvNamedWindow( wndname, 1 );
	 cvCreateTrackbar(tbarname0, wndname, &edge_thresh0, 8, on_trackbar);
	 cvCreateTrackbar(tbarname1, wndname, &edge_thresh1, 100, on_trackbar);
	  
	on_trackbar(1);
    // Wait for a key stroke; the same function arranges events processing
	// Press any key to exit.         
	// Clean up and don’t be piggies   
    cvWaitKey(0);
	  
	cvReleaseImage( &src );  
    cvReleaseImage( &dst ); 
	cvDestroyWindow(wndname);
	return 0;  
}

你可能感兴趣的:(image,function,UP,DST,events)