您的位置:首页 > 运维架构

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

2016-08-25 16:11 218 查看
#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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: