转载:approxPolyDP函数
本文转载http://blog.csdn.net/qq_18343569/article/details/47999257
1、approxPolyDP函数
函数的作用:
对图像轮廓点进行多边形拟合
2、函数的调用形式
C++: void approxPolyDP(InputArray curve, OutputArray approxCurve, double epsilon, bool closed)
参数详解;
InputArray curve:一般是由图像的轮廓点组成的点集
OutputArray approxCurve:表示输出的多边形点集
double epsilon:主要表示输出的精度,就是另个轮廓点之间最大距离数,5,6,7,,8,,,,,
bool closed:表示输出的多边形是否封闭
3、OPENCV代码
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h> using namespace cv;
using namespace std; Mat src; Mat src_gray;
int thresh = ;
int max_thresh = ;
RNG rng(); /// Function header
void thresh_callback(int, void*); /** @function main */
int main(int argc, char** argv)
{
/// 加载源图像
src = imread("D:6.jpg", ); /// 转成灰度图并进行模糊降噪
cvtColor(src, src_gray, CV_BGR2GRAY);
blur(src_gray, src_gray, Size(, )); /// 创建窗体
char* source_window = "Source";
namedWindow(source_window, CV_WINDOW_AUTOSIZE);
imshow(source_window, src); createTrackbar(" Threshold:", "Source", &thresh, max_thresh, thresh_callback);
thresh_callback(, ); waitKey();
return();
} /** @function thresh_callback */
void thresh_callback(int, void*)
{
Mat src_copy = src.clone();
Mat threshold_output;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy; /// 对图像进行二值化
threshold(src_gray, threshold_output, thresh, , THRESH_BINARY); /// 寻找轮廓
findContours(threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(, ));
/*Mat drawing = Mat::zeros(threshold_output.size(), CV_8UC3);*/ /* 对每个轮廓计算其凸包*/
vector<vector<Point> >poly(contours.size());
for (int i = ; i < contours.size(); i++)
{
approxPolyDP(Mat(contours[i]), poly[i], ,true);
} /* 绘出轮廓及其凸包*/
Mat drawing = Mat::zeros(threshold_output.size(), CV_8UC3);
for (int i = ; i< contours.size(); i++)
{
Scalar color = Scalar(rng.uniform(, ), rng.uniform(, ), rng.uniform(, ));
drawContours(drawing, contours, i, color, , , vector<Vec4i>(), , Point());
drawContours(drawing, poly, i, color, , , vector<Vec4i>(), , Point());
}
/*vector<Point> poly;
approxPolyDP(Mat(contours[3]), poly, 5, false);
vector<Point>::const_iterator itp = poly.begin();
while (itp != (poly.end() - 2))
{
line(drawing, *itp, *(itp + 1), Scalar(255), 2);
++itp;
}
line(drawing, *itp, *(poly.begin()), Scalar(255), 2);*/
/// 把结果显示在窗体
namedWindow("Hull demo", CV_WINDOW_AUTOSIZE);
imshow("Hull demo", drawing);
}
转载:approxPolyDP函数的更多相关文章
- [转载]findContours函数参数说明及相关函数
原文地址:findContours函数参数说明及相关函数作者:鸳都学童 findContours函数,这个函数的原型为: void findContours(InputOutputArray imag ...
- (转载)函数:mysqli_query和mysql_query有何区别?
(转载)http://wzan315.blog.163.com/blog/static/37192636201241732045299/ Mysqli.dll是一个允许以对象的方式或者过程操作数据库的 ...
- 转载------------C函数之memcpy()函数用法
转载于http://blog.csdn.net/tigerjibo/article/details/6841531 函数原型 void *memcpy(void*dest, const void *s ...
- 转载 js函数声明和函数表达式
在js中函数有两种表达方式.1 函数声明 2 函数表达式 函数声明 function sayname(){ alert("li lei"); } 函数表达式 var sayname ...
- [转载] poll()函数
原地址:http://baike.baidu.com/view/2997591.htm poll()函数:这个函数是某些Unix系统提供的用于执行与select()函数同等功能的函数,下面是这个函 ...
- 转载 --mysql函数大全
控制流函数 IFNULL(expr1,expr2) 如果expr1不是NULL,IFNULL()返回expr1,否则它返回expr2.IFNULL()返回一个数字或字符串值,取决于它被使用的上下文环境 ...
- [转载]oracle函数listagg的使用说明
工作中经常遇到很多需求是这样的,根据条件汇总某些字段,比如我遇到的是,我们公司有三个投资平台,同一个客户拿手机号在三个平台都注册了,但注册过的用户名不一样,显示的时候需要根据手机号显示所有注册过的名称 ...
- [转载]decode()函数简介
今天看别人的SQL时看这里面还有decode()函数,以前从来没接触到,上网查了一下,还挺好用的一个函数,写下来希望对朋友们有帮助哈! decode()函数简介: 主要作用:将查询结果翻译成其他值(即 ...
- [转载]strtok函数和strtok_r函数
1.一个应用实例 网络上一个比较经典的例子是将字符串切分,存入结构体中.如,现有结构体 typedef struct person{ char name[25]; char sex[1 ...
随机推荐
- VS项目平台的x86,x64,Any CPU以及Debug和Release
引用链接:https://blog.csdn.net/zuguangboy/article/details/51509670
- 经典面试题目——找到第n个丑数(参考《剑指offer(第二版)》面试题49)
一.题目大意 给你一个数n,要求返回第n个丑数.其中,丑数的定义如下: 丑数是指只包含因子2.3和5的数.(数字1也是丑数,不过是个特例)引用<剑指offer>上的话来说,对于一个数M,如 ...
- Hadoop 管理工具HUE配置
机器环境 Ubuntu 14.10 64位 || OpenJDK-7 || Scala-2.10.4 机群概况 Hadoop-2.6.0 || HBase-1.0.0 || Spark-1.2.0 | ...
- P1072Hankson的趣味题
传送 这个题一本通上有,但是为了增强我们的创新精神,思维能力balabala,书上的满分程序不全,要优化一下,在此写一下第二种方法 #include<iostream> #include& ...
- eKingCloud 从 OpenStack 到 OpenInfra 演进之路
本内容首发于 2016/06/21 北京 OpenInfra 大会上本人的演讲 发文章要求至少150个字,那就把最后一页说明一下吧. 我前面介绍了我们的5大产品,包括企业的私有云架构和实践,包括企业数 ...
- Android拨打接听电话自动免提
权限: <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-p ...
- Android通过包名启动其他应用,若该应用已启动,则直接将应用切到前台
CommUtil.startActivityForPackage(mContext, "com.autonavi.minimap");//打开高德 CommUtil.java /* ...
- c#day05
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ccc ...
- Zabbix利用orabbix插件监控Oracle数据库
一.jdk的安装(Orabbix Server) 1.软件解压,放到固定位置 1 2 tar zxf jdk-8u51-linux-x64.tar.gz mv jdk1.8.0_51/ /usr/lo ...
- SSH配置文件详解
SSH:是一种安全通道协议,主要用来实现字符界面的远程登录,远程复制等功能. 在RHEL系统中SSH使用的是OpenSSH服务器,由opensh,openssh-server等软件包提供的. sshd ...