cvPyrSegmentation() 图像金字塔分割

CVAPI(void) cvPyrSegmentation( IplImage* src, IplImage* dst,
                              CvMemStorage* storage, CvSeq** comp,
                              int level, double threshold1,

                              double threshold2 );


使用注意:

1.头文件要加入:#include <opencv2/legacy/legacy.hpp>

2.图像的宽和高必须至少被2整除,而且level决定要被2整除的次数


测试用图:



程序代码:

#include <highgui.h>
#include<cv.h> 
#include <opencv2/legacy/legacy.hpp>

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; 
}

运行结果:






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值