本文转载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. elasticsearch 口水篇(7) Eclipse中部署ES源码、运行

    ES源码可以直接从svn下载 https://github.com/elasticsearch/elasticsearch 下载后,用Maven导入(import——>Existing Mave ...

  2. 【ApplicationListener】Springboot各类事件监听器

    Springboot中SpringApplicationEvent的种类 如下图: 主要包括6种: ApplicationEnvironmentPreparedListener Application ...

  3. OpenSSH多路复用Multiplexing配置

    设置 Session Multiplexing 在客户端节点如下配置/etc/ssh/ssh_config 或~/.ssh/config 就可以直接开启 Session Multiplexing 功能 ...

  4. C语言中sizeof与strlen的区别

    1.sizeof sizeof为编译时期被替换,不会等到程序运行再来判断,所以sizeof返回的是数组的总字节数 #include<stdio.h> int main() { ]={'a' ...

  5. PAT 乙级 1048 数字加密(20) C++版

    1048. 数字加密(20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 本题要求实现一种数字加密方法.首先固 ...

  6. 学习笔记之pandas

    Python Data Analysis Library — pandas: Python Data Analysis Library https://pandas.pydata.org/ panda ...

  7. JVM底层又是如何实现synchronized的【转载】

    目前在Java中存在两种锁机制:synchronized和Lock,Lock接口及其实现类是JDK5增加的内容,其作者是大名鼎鼎的并发专家Doug Lea.本文并不比较synchronized与Loc ...

  8. LeetCode 搜索二维矩阵 II

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  9. [UE4]让机器人开枪射击

  10. Go语言 数据类型,流程控制

    Go语言 数据类型,流程控制 人生苦短,Let's Go ! package main // 必须要有一个main包 import "fmt" func main() { fmt. ...