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;
}
#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;
}
相关文章推荐
- 修改tomcat的conf/server.xml解决网页乱码
- Linux 文件压缩工具指南
- 简单的邮件发送封装库(1) -- 使用Apache Commons Email
- Tomcat启动分析(我们为什么要配置CATALINA_HOME环境变量)
- Linux进程描述符——task_struct(初学者的简单学习)
- 我是Itera石油和天然气公司驻华代表处的网站开发工程师
- open流程分析
- 网站页面热点点击图 -- 网站监管后台是否需要实现它呢??
- 玩转Docker之安装篇(二)
- 动手制做自己的一张软盘大小的Linux 选项
- 从IDC到云端架构迁移之路
- 重构 css 布局 -- 重构公司网站,面向web2.0规范前端项目开发
- 欢迎登陆我司官网了解产品最新资讯www.natshell.com
- Linux进程及作业管理
- 标准Web系统的架构分层
- 每天一个linux命令(8):cp 命令
- User Defined Hadoop DataType
- OpenStack Mitaka for Ubuntu 16.04 LTS 部署指南
- POSIT算法的原理--opencv 3D姿态估计
- 每天一个linux命令(7):mv命令