opencv 图像的轮廓查找 滚动条函数设置查找轮廓

来源:互联网 发布:手机淘宝浏览单软件 编辑:程序博客网 时间:2024/06/01 22:35

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

#include "opencv2\core\core.hpp"

IplImage *src=cvLoadImage("D:\\pic\\3.jpg",0);
IplImage *gray;
int thresh=100;
//轮廓storage必须初始化
CvMemStorage *storage=cvCreateMemStorage(0);
void  on_trackbar(int)
{
gray=cvCreateImage(cvGetSize(src),8,1);
CvMemStorage *storage=cvCreateMemStorage(0);
//Cvseq初始化为 NULL
CvSeq  *firstcontours=NULL;
//灰度图
//cvCvtColor(src,gray,CV_BGR2GRAY);
//二值化
cvThreshold(src,gray,thresh,255,CV_THRESH_BINARY);
//寻找轮廓
cvFindContours(gray,storage,&firstcontours,sizeof(CvContour),CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE);

//画轮廓

for(; firstcontours != 0; firstcontours = firstcontours->h_next)
{
cvDrawContours(gray,firstcontours,cvScalarAll(255),cvScalarAll(255),100);
}
cvShowImage("contours",gray);


}


int main()
{

cvNamedWindow("contours",1);
cvCreateTrackbar("threshold","contours",&thresh,150,on_trackbar);
on_trackbar(0);
cvWaitKey();
return 0;
}


0 0
原创粉丝点击