本文转载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函数的更多相关文章

  1. [转载]findContours函数参数说明及相关函数

    原文地址:findContours函数参数说明及相关函数作者:鸳都学童 findContours函数,这个函数的原型为: void findContours(InputOutputArray imag ...

  2. (转载)函数:mysqli_query和mysql_query有何区别?

    (转载)http://wzan315.blog.163.com/blog/static/37192636201241732045299/ Mysqli.dll是一个允许以对象的方式或者过程操作数据库的 ...

  3. 转载------------C函数之memcpy()函数用法

    转载于http://blog.csdn.net/tigerjibo/article/details/6841531 函数原型 void *memcpy(void*dest, const void *s ...

  4. 转载 js函数声明和函数表达式

    在js中函数有两种表达方式.1 函数声明 2 函数表达式 函数声明 function sayname(){ alert("li lei"); } 函数表达式 var sayname ...

  5. [转载] poll()函数

    原地址:http://baike.baidu.com/view/2997591.htm   poll()函数:这个函数是某些Unix系统提供的用于执行与select()函数同等功能的函数,下面是这个函 ...

  6. 转载 --mysql函数大全

    控制流函数 IFNULL(expr1,expr2) 如果expr1不是NULL,IFNULL()返回expr1,否则它返回expr2.IFNULL()返回一个数字或字符串值,取决于它被使用的上下文环境 ...

  7. [转载]oracle函数listagg的使用说明

    工作中经常遇到很多需求是这样的,根据条件汇总某些字段,比如我遇到的是,我们公司有三个投资平台,同一个客户拿手机号在三个平台都注册了,但注册过的用户名不一样,显示的时候需要根据手机号显示所有注册过的名称 ...

  8. [转载]decode()函数简介

    今天看别人的SQL时看这里面还有decode()函数,以前从来没接触到,上网查了一下,还挺好用的一个函数,写下来希望对朋友们有帮助哈! decode()函数简介: 主要作用:将查询结果翻译成其他值(即 ...

  9. [转载]strtok函数和strtok_r函数

    1.一个应用实例 网络上一个比较经典的例子是将字符串切分,存入结构体中.如,现有结构体 typedef struct person{     char name[25];     char sex[1 ...

随机推荐

  1. window7环境MySql5.7 zip安装配置教程

    1.将zip压缩包解压到一个目录下,并改名为mysql5.7 我的是放在D:\web\mysql5.7下 2.修改my-default.ini文件 下面几项是必填的,否则无法启动 basedir = ...

  2. go中的make和new的区别

    适用范围:make 只能创建内建类型(slice map channel), new 则是可以对所有类型进行内存分配 返回值: new 返回指针, make 返回引用 填充值: new 填充零值, m ...

  3. 关于ros里ppp拨号隧道比如pptp,l2tp,sstp等等,造成多条路由,ospf的时候需要汇总为一条宣告的解决方案

    官方解决方案: https://wiki.mikrotik.com/wiki/OSPF_and_PPPoE_Setup 实际解决步骤: So to get rid of /32 routes * on ...

  4. Jmeter(二十六)Jmeter-Question之“集成Jenkins”

    Jenkins,最初被称为Hudson,是一个Java语言编写的开源持续集成工具.Jenkins在持续集成领域的市场份额居于主导地位,其被各种规模的团队用于各种语言和技术的项目中,比如.net.rub ...

  5. asp.net mvc 5 单元测试小例子

    using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTest ...

  6. xdcms_3.0.1 | 代码审计

    这周的审计任务,这次审计 xdcms . 下面就开始审计之旅.                                                                     ...

  7. ubuntu14.04安装telnet

    1.首先查看telnet运行状态 netstat -a | grep telnet 输出为空,表示没有开启该服务 2.安装openbsd-inetd apt-get install openbsd-i ...

  8. 一个windows计划任务的Nginx日志自动截断的批处理命令

    net stop nginx taskkill /im nginx.exe /f cd E:\nginx e: set NO=%Date:~0,4%%Date:~5,2%%Date:~8,2% set ...

  9. c#线程间传递参数

    线程操作主要用到Thread类,他是定义在System.Threading.dll下.使用时需要添加这一个引用.该类提供给我们四个重载的构造函数(以下引自msdn).        Thread (P ...

  10. (转)SQL知识_SqlParameter数组

    原文地址:http://www.cnblogs.com/FredTang/archive/2012/03/29/2423651.html 温故而知新,做做笔记先.        SqlParamete ...