[OpenCV] Samples 05: convexhull
得到了复杂轮廓往往不适合特征的检测,这里再介绍一个点集凸包络的提取函数convexHull,输入参数就可以是contours组中的一个轮廓,返回外凸包络的点集 ---- 如此就能去掉凹进去的边。
对于凸包算法,其中最有名的莫过于Graham扫描算法,它的复杂度为nlog(n)
参考:计算几何之凸包(Algorithm show), 寻找轮廓
高级:Snake模型在轮廓提取中的应用 cvSnakeImage()

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <fstream>
#include <iostream> using namespace cv;
using namespace std; static void help()
{
cout << "\nThis sample program demonstrates the use of the convexHull() function\n"
<< "Call:\n"
<< "./convexhull\n" << endl;
} int main( int argc, char** argv )
{
CommandLineParser parser(argc, argv, "{help h||}");
if (parser.has("help"))
{
help();
return 0;
}
Mat img(500, 500, CV_8UC3);
RNG& rng = theRNG(); for(;;)
{
char key;
int i, count = (unsigned)rng%100 + 1; vector<Point> points; for( i = 0; i < count; i++ )
{
Point pt;
pt.x = rng.uniform(img.cols/4, img.cols*3/4);
pt.y = rng.uniform(img.rows/4, img.rows*3/4); points.push_back(pt);
} // Jeff --> hull is the indice of corner points
vector<int> hull;
convexHull(Mat(points), hull, true); /******************************************************************************/ // Jeff --> draw the effect.
img = Scalar::all(0);
for( i = 0; i < count; i++ )
circle(img, points[i], 3, Scalar(0, 0, 255), FILLED, LINE_AA); int hullcount = (int)hull.size();
cout << hullcount << endl;
Point pt0 = points[hull[hullcount-1]]; for( i = 0; i < hullcount; i++ )
{
// Jeff --> extract corners.
Point pt = points[hull[i]];
line(img, pt0, pt, Scalar(0, 255, 0), 1,LINE_AA);
pt0 = pt;
} imshow("hull", img); key = (char)waitKey();
if( key == 27 || key == 'q' || key == 'Q' ) // 'ESC'
break;
} return 0;
}
轮廓的进一步描述

进一步参见:OpenCV成长之路:直线、轮廓的提取与描述
[OpenCV] Samples 05: convexhull的更多相关文章
- [OpenCV] Samples 16: Decompose and Analyse RGB channels
物体的颜色特征决定了灰度处理不是万能,对RGB分别处理具有相当的意义. #include <iostream> #include <stdio.h> #include &quo ...
- [OpenCV] Samples 10: imagelist_creator
yaml写法的简单例子.将 $ ./ 1 2 3 4 5 命令的参数(代表图片地址)写入yaml中. 写yaml文件. 参考:[OpenCV] Samples 06: [ML] logistic re ...
- [OpenCV] Samples 06: [ML] logistic regression
logistic regression,这个算法只能解决简单的线性二分类,在众多的机器学习分类算法中并不出众,但它能被改进为多分类,并换了另外一个名字softmax, 这可是深度学习中响当当的分类算法 ...
- [OpenCV] Samples 03: cout_mat
操作Mat元素时:I.at<double>(1,1) = CV_PI; /* * * cvout_sample just demonstrates the serial out capab ...
- [OpenCV] Samples 01: drawing
基本的几何图形,标注功能. commondLineParser的使用参见:http://blog.csdn.net/u010305560/article/details/8941365 #includ ...
- [OpenCV] Samples 01: Geometry - 几何图形
前言 基本的几何图形,标注功能. commondLineParser的使用参见:http://blog.csdn.net/u010305560/article/details/8941365 #inc ...
- [OpenCV] Samples 03: kmeans
注意Mat作为kmeans的参数的含义. 扩展:高维向量的聚类. 一.像素聚类 #include "opencv2/highgui.hpp" #include "open ...
- [OpenCV] Samples 06: logistic regression
logistic regression,这个算法只能解决简单的线性二分类,在众多的机器学习分类算法中并不出众,但它能被改进为多分类,并换了另外一个名字softmax, 这可是深度学习中响当当的分类算法 ...
- [OpenCV] Samples 13: opencv_version
cv::CommandLineParser的使用. I suppose CommandLineParser::has("something") should be true whe ...
随机推荐
- explode,split,preg_split性能比较
explode,split,preg_split性能比较 分类: php2012-07-12 09:46 1109人阅读 评论(1) 收藏 举报 三个函数都是用来对字符串进行分割,下面分几个实验来 ...
- DLL和LIB的一些知识点(网上搜集)
关于lib和dll的区别如下:(1)lib是编译时用到的,dll是运行时用到的.如果要完成源代码的编译,只需要lib:如果要使动态链接的程序运行起来,只需要dll.(2)如果有dll文件,那么lib一 ...
- Oracle基本数据字典:v$database、v$instance、v$version、dba_objects
v$database: 视图结构: SQL> desc v$database; Name Null? Type - ...
- Xamarin跨平台移动开发解决方案
Xamarin始创于2011年,旨在使移动开发变得难以置信地迅捷和简单.Xamarin的产品简化了针对多种平台的应用开发,包括iOS.Android.Windows Phone和Mac App.Xam ...
- phoenix 开发API系列(一)创建简单的http api
安装 phoenix framework 安装 phoenix 很简单: mix archive.install https://github.com/phoenixframework/archive ...
- sql server 写性能优化
潜在的方案是: (1)2014版本的内存表 (2)表分区,将表数据存放在多个硬盘上. (3)采用SSD磁盘阵列. (4)不重要的表关闭事务日志.??
- GitHub详解(GitHub for Windows)
GitHub详解 GitHub 是一个共享虚拟主机服务,用于存放使用Git版本控制的软件代码和内容项目.它由GitHub公司(曾称Logical Awesome)的开发者Chris Wanstrath ...
- 在Linux上用自己编译出来的coreclr与donet cli运行asp.net core程序
先在 github 上签出 coreclr 的源代码,运行 ./build.sh 命令进行编译,编译结果在 coreclr/bin/Product/Linux.x64.Debug/ 文件夹中. 接着签 ...
- 【Bugly 技术干货】Android开发必备知识:为什么说Kotlin值得一试
1.Hello, Kotlin Bugly 技术干货系列内容主要涉及移动开发方向,是由 Bugly邀请腾讯内部各位技术大咖,通过日常工作经验的总结以及感悟撰写而成,内容均属原创,转载请标明出处. 1. ...
- javascript 设计模式-----策略模式
在<javascript设计模式>中,作者并没有向我们介绍策略模式,然而它却是一种在开发中十分常见的设计模式.最常见的就是当我们遇到一个复杂的表单验证的时候,常常需要编写一大段的if和el ...