zoukankan      html  css  js  c++  java
  • EmguCV 轮廓

    一、相关函数

      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();  //显示出来

        }  

  • 相关阅读:
    Ubuntu 16.04 安装 Wireshark分析tcpdump的pcap包——sudo apt install wireshark-qt
    tcpdump dns流量监控
    ubuntu dig timeout解决方法,dnscat执行失败也是这个原因
    dns tunnel C&C
    “借贷宝”到底是不是坑?——“借贷宝”注册送现金营销模式分析?【已亲测可以无条件提现成功】
    借贷宝注册提现详细攻略:注册送20元,邀请好友再各送20元,亲测可无条件提现(附提现、到账截图)
    滴滴专车司机苹果手机ios客户端可以下载了
    优步UBER司机全国各地奖励政策汇总:北京、上海、广州、深圳、佛山、天津、南京、武汉、成都、重庆、济南、西安、宁波、青岛、长沙、苏州
    北京优步UBER司机B组最新奖励政策、高峰翻倍奖励、行程奖励、金牌司机奖励【每周更新】
    优步UBER司机奖励政策:含高峰、翻倍、行程、金牌司机、保底奖励(持续更新...)
  • 原文地址:https://www.cnblogs.com/alsofly/p/3524352.html
Copyright © 2011-2022 走看看