本文需要了解的库函数有:
void cvPyrSegmentation( IplImage* src, IplImage* dst, CvMemStorage* storage, CvSeq** comp, int level, double threshold1, double threshold2 ); //利用金字塔模型实现图像分割参考网址:http://www.opencv.org.cn/index.php/Cv%E5%9B%BE%E5%83%8F%E5%A4%84%E7%90%86
实例代码:
#pragma comment(lib,"cv.lib")
#pragma comment(lib,"cvaux.lib")
#pragma comment(lib,"highgui.lib")
#pragma comment(lib,"cxcore.lib")
#include<cv.h>
#include<highgui.h>
#include<stdio.h>
IplImage* image = NULL;//原始图像
IplImage* dist = NULL;//显示图像
CvMemStorage * storage=NULL;
CvSeq *comp;
const char* name = "金字塔分割图像";
int threshold1 =10;
int threshold2 =10;
void OnTrack(int pos)
{
cvPyrSegmentation(image,dist,storage,&comp,4,threshold1,threshold2);
cvShowImage(name,dist);
}
int main()
{
image = cvLoadImage("fruits.jpg",1);
dist = cvCloneImage(image);
storage = cvCreateMemStorage(0);
cvNamedWindow(name,1);
cvCreateTrackbar("阈值1",name,&threshold1,255,OnTrack);
cvCreateTrackbar("阈值2",name,&threshold2,255,OnTrack);
OnTrack(0);
cvWaitKey(0);
cvReleaseImage(&image);
cvReleaseImage(&image);
cvDestroyWindow(name);
cvReleaseMemStorage(&storage);
}