double threshold2 );
使用注意:
1.头文件要加入:#include
2.图像的宽和高必须至少被2整除,而且level决定要被2整除的次数
测试用图:
程序代码:
#include
#include
#include
int t;
int level=1;
int threshold1=10;
int threshold2=10;
IplImage *img_in;
IplImage *img_out;
IplImage *img2;
CvMemStorage *stoage ;
CvSeq* comp=NULL;
using namespace std;
void on_trackbar_1(int level_pos)
{
level=level_pos;
cvPyrSegmentation(img_in,img_out,stoage,&comp,level,threshold1,threshold2);
cvNamedWindow("img_out",CV_WINDOW_AUTOSIZE);
cvShowImage("img_out",img_out);
}
void on_trackbar_2(int threshold1_pos)
{
threshold1=threshold1_pos;
cvPyrSegmentation(img_in,img_out,stoage,&comp,level,threshold1,threshold2);
cvNamedWindow("img_out",CV_WINDOW_AUTOSIZE);
cvShowImage("img_out",img_out);
}
void on_trackbar_3(int threshold2_pos)
{
threshold2=threshold2_pos;
cvPyrSegmentation(img_in,img_out,stoage,&comp,level,threshold1,threshold2);
cvNamedWindow("img_out",CV_WINDOW_AUTOSIZE);
cvShowImage("img_out",img_out);
}
int main()
{
stoage = cvCreateMemStorage();
img_in = cvLoadImage("test.jpg");
img_out = cvCreateImage(cvSize(img_in->width,img_in->height),IPL_DEPTH_8U,3);
img2 = cvCreateImage(cvSize(500,500),IPL_DEPTH_8U,3);
cvNamedWindow("img_in",CV_WINDOW_AUTOSIZE);
cvShowImage("img_in",img_in);
cvNamedWindow("img2",CV_WINDOW_AUTOSIZE);
cvCreateTrackbar("Level","img2",&t,4,on_trackbar_1);
cvCreateTrackbar("threshold1","img2",&t,200,on_trackbar_2);
cvCreateTrackbar("threshold2","img2",&t,100,on_trackbar_3);
cvWaitKey(0);
cvDestroyAllWindows();
cvReleaseImage(&img_in);
//cvReleaseImage(&img2);
return 0;
}