轮廓检测

对于查找轮廓我们一般要对图像Canny检测。但是对于很特殊的场合其实我们还可以直接对二值化的图像进行轮廓的提取。

关键函数

1、 cvFindContours

Retrieves contours from the binary image and returns the number of retrieved contours. The pointer firstContour is filled by the function. It will contain pointer to the first most outer contour or IntPtr.Zero if no contours is detected (if the image is completely black). Other contours may be reached from firstContour using h_next and v_next links. The sample in cvDrawContours discussion shows how to use contours for connected component detection. Contours can be also used for shape analysis and object recognition - see squares.c in OpenCV sample directory The function modifies the source image? content

函数功能:对图像进行轮廓检测,这个函数将生成一条链表以保存检测出的各个轮廓信息,并传出指向这条链表表头的指针。

函数原型:

Namespace: Emgu.CV
Assembly: Emgu.CV (in Emgu.CV.dll) Version: 2.4.2.1777 (2.4.2.1777)

C#
public static int cvFindContours(
IntPtr image,
IntPtr storage,
ref IntPtr firstContour,
int headerSize,
RETR_TYPE mode,
CHAIN_APPROX_METHOD method,
Point offset
)

Parameters

image
Type: System.IntPtr

The source 8-bit single channel image. Non-zero pixels are treated as 1s, zero pixels remain 0s - that is image treated as binary. To get such a binary image from grayscale, one may use cvThreshold, cvAdaptiveThreshold or cvCanny. The function modifies the source image content

第一个参数表示输入图像,必须为一个8位的二值图像。

storage
Type: System.IntPtr
Container of the retrieved contours
第二参数表示存储轮廓的容器。为CvMemStorage类型,定义在OpenCV的\core\types_c.h中。
firstContour
Type: System.IntPtr
Output parameter, will contain the pointer to the first outer contour
第三个参数为输出参数,这个参数将指向用来存储轮廓信息的链表表头。
headerSize
Type: System.Int32
Size of the sequence header, >=sizeof(CvChain) if method=CV_CHAIN_CODE, and >=sizeof(CvContour) otherwise
第四个参数表示存储轮廓链表的表头大小,当第六个参数传入CV_CHAIN_CODE时,要设置成izeof(CvChain),其它情况统一设置成sizeof(CvContour)。
mode
Type: Emgu.CV.CvEnum.RETR_TYPE
Retrieval mode
第五个参数为轮廓检测的模式,有如下取值:CV_RETR_EXTERNAL:只检索最外面的轮廓;  CV_RETR_LIST:检索所有的轮廓,并将其保存到一条链表当中;  CV_RETR_CCOMP:检索所有的轮廓,并将他们组织为两层:顶层是各部分的外部边界,第二层是空洞的边界;CV_RETR_TREE:检索所有的轮廓,并重构嵌套轮廓的整个层次,可以参见下图。 
method
Type: Emgu.CV.CvEnum.CHAIN_APPROX_METHOD
Approximation method (for all the modes, except CV_RETR_RUNS, which uses built-in approximation).

第六个参数用来表示轮廓边缘的近似方法的,常用值如下所示:

CV_CHAIN_CODE:以Freeman链码的方式输出轮廓,所有其他方法输出多边形(顶点的序列)。

    CV_CHAIN_APPROX_SIMPLE:压缩水平的、垂直的和斜的部分,也就是,函数只保留他们的终点部分。

offset
Type: System.Drawing.Point
Offset, by which every contour point is shifted. This is useful if the contours are extracted from the image ROI and then they should be analyzed in the whole image context
第七个参数表示偏移量,比如你要从图像的(100, 0)开始进行轮廓检测,那么就传入(100, 0)。

Return Value

The number of countours

轮廓线的数量 
2、cvDrawContours
使用cvFindContours函数能检测出图像的轮廓,将轮廓绘制出来则需要另一函数——cvDrawContours来配合了。下面介绍cvDrawContours函数。
Draws contour outlines in the image if thickness >=0 or fills area bounded by the contours if thickness<0.

Namespace: Emgu.CV
Assembly: Emgu.CV (in Emgu.CV.dll) Version: 2.4.2.1777 (2.4.2.1777)

函数功能:在图像上绘制外部和内部轮廓

void cvDrawContours(

CvArr *img,

CvSeq* contour,

CvScalar external_color,

CvScalar hole_color,

int max_level,

int thickness=1,

int line_type=8,

CvPoint offset=cvPoint(0,0)

);

Parameters

img
Type: System.IntPtr
Image where the contours are to be drawn. Like in any other drawing function, the contours are clipped with the ROI
第一个参数表示输入图像,函数将在这张图像上绘制轮廓。
contour
Type: System.IntPtr
Pointer to the first contour
第二个参数表示指向轮廓链表的指针。
externalColor
Type: Emgu.CV.Structure.MCvScalar
Color of the external contours
holeColor
Type: Emgu.CV.Structure.MCvScalar
Color of internal contours
第三个参数和第四个参数表示颜色,绘制时会根据轮廓的层次来交替使用这二种颜色。
maxLevel
Type: System.Int32
Maximal level for drawn contours. If 0, only contour is drawn. If 1, the contour and all contours after it on the same level are drawn. If 2, all contours after and all contours one level below the contours are drawn, etc. If the value is negative, the function does not draw the contours following after contour but draws child contours of contour up to abs(maxLevel)-1 level.
第五个参数表示绘制轮廓的最大层数,如果是0,只绘制contour;如果是1,追加绘制和contour同层的所有轮廓;如果是2,追加绘制比contour低一层的轮廓,以此类推;如果值是负值,则函数并不绘制contour后的轮廓,但是将画出其子轮廓,一直到abs(max_level) - 1层。
thickness
Type: System.Int32
Thickness of lines the contours are drawn with. If it is negative the contour interiors are drawn
第六个参数表示轮廓线的宽度,如果为CV_FILLED则会填充轮廓内部。
lineType
Type: Emgu.CV.CvEnum.LINE_TYPE
Type of the contour segments
第七个参数表示轮廓线的类型。
offset
Type: System.Drawing.Point
Shift all the point coordinates by the specified value. It is useful in case if the contours retrived in some image ROI and then the ROI offset needs to be taken into account during the rendering.
第八个参数表示偏移量,如果传入(10,20),那绘制将从图像的(10,20)处开始。
 

[转载+原创]Emgu CV on C# (七) —— Emgu CV on 轮廓检测的更多相关文章

  1. [转载+原创]Emgu CV on C# (三) —— Emgu CV on 均衡化

    本文简要描述了均衡化原理及数学实现等理论问题,最终利用emgucv实现图像的灰度均衡. 直方图的均衡化,这是图像增强的常用方法. 一.均衡化原理及数学实现(转载) 均衡化原理及数学实现可重点参看——& ...

  2. [转载+原创]Emgu CV on C# (五) —— Emgu CV on 局部自适应阈值二值化

    局部自适应阈值二值化 相对全局阈值二值化,自然就有局部自适应阈值二值化,本文利用Emgu CV实现局部自适应阈值二值化算法,并通过调节block大小,实现图像的边缘检测. 一.理论概述(转载自< ...

  3. [转载+原创]Emgu CV on C# (二) —— Emgu CV on 灰度化

    本文主要对彩色图片灰度化的方法及其实现过程进行总结,最终给出Emgu CV实现的代码. 一.灰度化原理及数学实现(转载自——<图像灰度化方法总结及其VC实现> 该篇文章使用opencv实现 ...

  4. [转载+原创]Emgu CV on C# (一) —— Emgu CV on Visual C# 2010

    2014-08-16 最近要进行图像识别,准备利用几天的时间研究一下Emgu CV,花了一晚上功夫进行调试环境安装,期间遇到了不少问题,现梳理一下安装过程和调试过程中出现的问题. 中间有转载别人的部分 ...

  5. [转载+原创]Emgu CV on C# (六) —— Emgu CV on Canny边缘检测

    Canny边缘检测也是一种边缘检测方法,本文介绍了Canny边缘检测的函数及其使用方法,并利用emgucv方法将轮廓检测解算的结果与原文进行比较. 图像的边缘检测的原理是检测出图像中所有灰度值变化较大 ...

  6. 【OpenCV学习笔记】三十、轮廓特征属性及应用(七)—位置关系及轮廓匹配

    http://blog.csdn.net/abc8730866/article/details/69219992 轮廓特征属性及应用(七)—位置关系及轮廓匹配 1.计算点与轮廓的距离及位置关系——po ...

  7. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数003·contour,轮廓处理

    <zw版·Halcon-delphi系列原创教程> Halcon分类函数003·contour,轮廓处理 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替 ...

  8. 【opencv】cv::Mat转std::vector<cv::Point2d> (注意两容器中数据类型的一致性)

    获取cv::Mat大小: mymat.size() 获取cv::Mat指定位置的值:需指定数据类型,且注意数据类型应与存入时的数据类型一致,否则会导致不抛出异常的数据错误 mymat.at<,i ...

  9. [转载+原创]Emgu CV on C# (四) —— Emgu CV on 全局固定阈值二值化

    重点介绍了全局二值化原理及数学实现,并利用emgucv方法编程实现. 一.理论概述(转载,如果懂图像处理,可以略过,仅用作科普,或者写文章凑字数)  1.概述 图像二值化是图像处理中的一项基本技术,也 ...

随机推荐

  1. SlickOne -- 基于Dapper, Mvc和WebAPI 的快速开发框架

    前言:在两年前,项目组推出了基于Dapper,Mvc和WebApi的快速开发框架,随着后续Slickflow产品的实践和应用,今再次对SlickOne项目做以回顾和总结.其目的是精简,持续改进,保持重 ...

  2. 【转载】TalkingData首席金融行业专家鲍忠铁:18亿数据解读移动互联网

    http://www.36dsj.com/archives/33417 鲍忠铁:大家下午好! 今天我会讲三个议题,一是用18亿数据解读现在移动互联网的生态圈.二是看看数据有什么样的应用.三是大数据的隐 ...

  3. android app性能优化大汇总(内存性能优化)

    转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 写在最前: 本文的思路主要借鉴了2014年AnDevCon开发者大会的一个演讲PPT,加上 ...

  4. JavaScript之动画3

    给一个div添加颜色,使其产生渐变效果,我们设置index为变量,使用setInterval函数方法改变rgb颜色值. window.onload = function(){ var boxDom = ...

  5. Centos6的VSFTP服务器配置使用教程

    Centos 6 的VSFTP 关闭SELinux,在终端机输入 vi /etc/selinux/config SELINUX=enforcing 改成 SELINUX=disabled 关闭seli ...

  6. Oracle数据库对象_同义词

    同义词是一种数据库对象,它是为一个数据库对象定义的别名,使用同义词的主要目的是为了简化SQL语句的书写. 同义词的概念和类型 利用同义词可以为用户的一个对象,或者其他用户的一个对象定义别名,从而简化命 ...

  7. OC9_代理正向传值

    // // ProtectedDeleagate.h // OC9_代理正向传值 // // Created by zhangxueming on 15/6/24. // Copyright (c) ...

  8. DFS入门之二---DFS求连通块

    用DFS求连通块也是比较典型的问题, 求多维数组连通块的过程也称为--“种子填充”. 我们给每次遍历过的连通块加上编号, 这样就可以避免一个格子访问多次.比较典型的问题是”八连块问题“.即任意两格子所 ...

  9. android ListView_Tiger

    xml设计 <?xml version="1.0"?> -<LinearLayout tools:context=".MainActivity" ...

  10. java利用反射绕过私有检查机制实行对private、protected成员变量或方法的访问

    在java中,如果类里面的变量是声明了private的,那么只能在被类中访问,外界不能调用,如果是protected类型的,只能在子类或本包中调用,俗话说没有不透风的墙.但是可以利用java中的反射从 ...