一、相关函数

  public static void cvDrawContours(

      IntPtr img,

      IntPtr contour,

      MCvScalar externalColor,

      MCvScalar holeColor,

      int maxLevel,

      int thickness,

      Emgu.CV.CvEnum.LINE_TYPE lineType,  //EIGHT_CONNECTED、FOUR_CONNECTED、CV_AA

      System.Drawing.Point offset

  )

  cvDrawContours函数在图像上画出轮廓,其中external_color指定外围轮廓的颜色,hole_color指定内部轮廓的颜色(孔),max_level是一个比较关键的参数,也比较难理解,它指定被画的轮廓的最大层数,等于0时只画出第一个轮廓,等于1时画出第一个轮廓以及在它后面的同一层所有的轮廓,等于2时下一层的轮廓也被画出来,以此类推。当max_level为负数时,同一层的轮廓不会被画出来,而是画出contour(当前轮廓)直至|max_level|-1层的子轮廓(特殊情况:当max_level = -1时,只画出当前轮廓)。

  offsetType: 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.

  public static int cvFindContours(

      IntPtr image,  //8位单通道图像,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

      IntPtr storage,   //Container of the retrieved contours

      ref IntPtr firstContour,  //Output parameter, will contain the pointer to the first outer contour

      int headerSize,   //Size of the sequence header, >=sizeof(CvChain) if method=CV_CHAIN_CODE, and >=sizeof(CvContour) otherwise

      RETR_TYPE mode,   //检索模式,可取值:CV_RETR_EXTERNAL、CV_RETR_LIST、CV_RETR_CCOMP、CV_RETR_TREE

      Emgu.CV.CvEnum.CHAIN_APPROX_METHOD method,   //优化方法,可取值:CV_CHAIN_CODE、CV_CHAIN_APPROX_NONE、CV_CHAIN_APPROX_SIMPLE、CV_CHAIN_APPROX_TC89_L1、CV_CHAIN_APPROX_TC89_KCOS、CV_LINE_RUNS

      System.Drawing.Point offset   //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.

  )

二、一个例子

   private void test(Image<Gray, byte> src)

{

CvInvoke.cvThreshold(src, src, 50, 250, Emgu.CV.CvEnum.THRESH.CV_THRESH_OTSU);

Image<Gray, byte> dst = new Image<Gray, byte>(src.Size);//存储最终结果图像

IntPtr Dyncontour = new IntPtr();//存放检测到的图像块的首地址

    IntPtr Dynstorage = CvInvoke.cvCreateMemStorage(0);//开辟内存区域

    int m = 88;//在不安全处理下获取的数据

int n = CvInvoke.cvFindContours(src, Dynstorage, ref Dyncontour, m, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST, Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE, new Point(1, 1));

    Seq<Point> DyncontourTemp1 = new Seq<Point>(Dyncontour, null);//方便对IntPtr类型进行操作

    Seq<Point> DyncontourTemp = DyncontourTemp1;

for (; DyncontourTemp1 != null && DyncontourTemp1.Ptr.ToInt32() != 0; DyncontourTemp1 = DyncontourTemp1.HNext)

     {

       CvInvoke.cvDrawContours(dst, DyncontourTemp1, new MCvScalar(128, 128, 128), new MCvScalar(255, 255, 255), 0, 1, Emgu.CV.CvEnum.LINE_TYPE.CV_AA, new Point(0, 0));

    }

    pictureBox2.Image = dst.ToBitmap();  //显示出来

  }

EmguCV 轮廓的更多相关文章

  1. EmguCV 轮廓匹配

    一.相关类 MCvMoments inv_sqrt_m00 m00!=0?1/sqrt(m00):0 m00  spatial moments m01, m02, m03, m10, m11 m12, ...

  2. EmguCV 轮廓分析函数汇总

    一.cvApproxPoly 使用多边形逼近一个轮廓,使得顶点数目变少.算法先从轮廓选择2个最远的点,然后将2个连成一个线段,然后再查找轮廓上到线段距离最远的点,添加到逼近后的新轮廓.算法反复迭代,不 ...

  3. Emgucv使用中常用函数总结

    Emgucv常用函数总结: 读取图片 Mat SCr = new Mat(Form1.Path, Emgu.CV.CvEnum.LoadImageType.AnyColor); //根据路径创建指定的 ...

  4. 轮廓的查找、表达、绘制、特性及匹配(How to Use Contour? Find, Component, Construct, Features & Match)

    http://www.cnblogs.com/xrwang/archive/2010/02/09/HowToUseContour.html 作者:王先荣 前言    轮廓是构成任何一个形状的边界或外形 ...

  5. 机械手相机9点坐标标定-基于C#+EmguCV

    很多初学者,都对标定概念模糊不清,分不清坐标系之间的关系,搞不清相机标定和机械手相机标定有什么关系,想当初自己也是一个人摸索了很久,本文将尽量给大家解释. 我们通常所说的相机标定分为两种,一种是相机参 ...

  6. EmguCV常用函数总结

    Emgucv常用函数总结: 读取图片 Mat SCr = new Mat(Form1.Path, Emgu.CV.CvEnum.LoadImageType.AnyColor); //根据路径创建指定的 ...

  7. opecv获取图像轮廓

    获取轮廓 #import <opencv2/opencv.hpp> #import <opencv2/imgcodecs/ios.h> #import <opencv2/ ...

  8. W3School-CSS 轮廓(Outline)实例

    CSS 轮廓(Outline)实例 CSS 实例 CSS 背景实例 CSS 文本实例 CSS 字体(font)实例 CSS 边框(border)实例 CSS 外边距 (margin) 实例 CSS 内 ...

  9. 简易的轮廓边生成(N和V dot点乘方式)(surface方式和vs ps 方式的分别实现)

    一.前面心情 1.公司我的架构发生变动,从技术中心到项目组了,但不管怎么样,该看的还要看,总会用到 二.实现 三.参考: http://blog.csdn.net/cubesky/article/de ...

随机推荐

  1. 记一次mybatis的classpath踩坑记录

    http://blog.csdn.net/jinzhencs/article/details/50595476

  2. java中new关键字和newInstance()方法有什么区别?

    1.new可以调用带参数的构造函数,newInstance不可以. 2.new 是 java 的关键字,用来构造一个类的实例.而 newInstance 是 Class 的一个方法,不过两个写法的效果 ...

  3. 贪心 Codeforces Round #287 (Div. 2) A. Amr and Music

    题目传送门 /* 贪心水题 */ #include <cstdio> #include <algorithm> #include <iostream> #inclu ...

  4. PHP、Java输出json格式数据

      PHP 输出json. $result = mysql_query($sql); //查询结果 $users=array(); $i=0; while($row=mysql_fetch_array ...

  5. HBase 分布式环境搭建

    一.前期环境 安装概览 IP Host Name Software Node 192.168.23.128 ae01 JDK 1.7, Zookeeper-3.4.5 HMaster 192.168. ...

  6. .net平台下C#socket通信(中)

    上篇.net平台下C#socket通信(上)介绍了socket通信的基本原理及最基本的通信方式.本文在此基础上就socket通信时经常遇到的问题做一个简单总结,都是项目中的一些小问题,拿来此处便于下次 ...

  7. 【原】iOS学习之SQLite和CoreData数据库的比较

    1. SQLite数据库 sqlite数据库操作的基本流程是, 创建数据库, 再通过定义一些字段来定义表格结构, 可以利用sql语句向表格中插入记录, 删除记录, 修改记录, 表格之间也可以建立联系. ...

  8. HDU5823 : color II

    每种颜色的点集肯定是独立集,因此可以通过$O(2^n)$枚举每个集合判断出每个集合是否只需要一种颜色即可染色. 设$f[i][S]$表示$i$种颜色覆盖$S$这个集合的方案数,假定两个集合可以相交,那 ...

  9. HDU 2586 (LCA模板题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2586 题目大意:在一个无向树上,求一条链权和. 解题思路: 0 | 1 /   \ 2      3 ...

  10. 再探CSS 中 class 命名规范

    一直以来我的CSS 的 class命名都是比较随意,有时采用驼峰式.有时采用下划线,好像没有什么统一的标准,想到什么英文单词就拿过来用,这对于自己瞎写的小项目无伤大雅,遇到冲突的问题可稍加调整改变即可 ...