• halconconvexity获取凸度


    凸性区域:包含整个原区域,原区域中任意两点连线都在该区域内,这样的区域就称为原区域的凸性区域
    区域的凸度:原区域面积与凸性区域面积的比值,称为区域的凸度,其范围是0-1.

    视频:https://www.bilibili.com/video/BV1ka411b7ko/

    在HDevelop中

    read_image (Image, 'D:/bb/tu/5.jpg')
    rgb1_to_gray(Image,Image1)
    threshold (Image1, Region,[75] , [90])
    
    shape_trans (Region, RegionTrans, 'convex')
    *区域转换为凸性区域(凸包)
    *参数1:输入区域
    *参数2:输出区域
    *参数3:类型
    *       'convex'     凸包性--默认
    *        'ellipse'   与输入区域有相同的矩和区域的椭圆
    *        'inner_center'     输入区域骨架上距离输入区域重心最小的点
    *        'inner_circle'     最大内接圆
    *        'inner_rectangle1'   平行于坐标轴的最大内接矩形
    *        'outer_circle'      最小外接圆
    *        'rectangle1'        平行于坐标轴的最小外接矩形
    *        'rectangle2'        最小外接矩形
    
    convexity (Region, Convexity)
    *获取凸度
    *参数1:输入区域或区域集
    *参数2:输出凸度,凸度<=1
    
    get_image_size (Image1, Width, Height)
    dev_open_window(10,10,Width, Height,'black',WindowHandle)
    dev_display(Region)
    dev_open_window(10,100,Width, Height,'black',WindowHandle1)
    dev_display(RegionTrans)

     

     凸度:

    如果凸包的面积是Fc,该区域的原始面积是Fo,则定义凸度C为:

    如果区域是凸的,形状因子C为1(例如:矩形、圆形等)。如果有压痕或孔洞,则C小于1,请参考如下图: 


    在QtCreator中

      HObject  ho_Image, ho_Image1, ho_Region, ho_RegionTrans;
      HTuple  hv_Convexity, hv_Width, hv_Height, hv_WindowHandle;
      HTuple  hv_WindowHandle1;
      ReadImage(&ho_Image, "D:/bb/tu/5.jpg");
      Rgb1ToGray(ho_Image, &ho_Image1);
      Threshold(ho_Image1, &ho_Region, 75, 90);
    
      ShapeTrans(ho_Region, &ho_RegionTrans, "convex");
      //区域转换为凸性区域(凸包)
      //参数1:输入区域
      //参数2:输出区域
      //参数3:类型
      //      'convex'     凸包性--默认
      //       'ellipse'   与输入区域有相同的矩和区域的椭圆
      //       'inner_center'     输入区域骨架上距离输入区域重心最小的点
      //       'inner_circle'     最大内接圆
      //       'inner_rectangle1'   平行于坐标轴的最大内接矩形
      //       'outer_circle'      最小外接圆
      //       'rectangle1'        平行于坐标轴的最小外接矩形
      //       'rectangle2'        最小外接矩形
    
      Convexity(ho_Region, &hv_Convexity);
      //获取凸度
      //参数1:输入区域或区域集
      //参数2:输出凸度,凸度<=1
    
      GetImageSize(ho_Image1, &hv_Width, &hv_Height);
      SetWindowAttr("background_color","black");
      OpenWindow(10,10,hv_Width,hv_Height,0,"visible","",&hv_WindowHandle);
      HDevWindowStack::Push(hv_WindowHandle);
      if (HDevWindowStack::IsOpen())
        DispObj(ho_Region, HDevWindowStack::GetActive());
      SetWindowAttr("background_color","black");
      OpenWindow(10,100,hv_Width,hv_Height,0,"visible","",&hv_WindowHandle1);
      HDevWindowStack::Push(hv_WindowHandle1);
      if (HDevWindowStack::IsOpen())
        DispObj(ho_RegionTrans, HDevWindowStack::GetActive());

  • 相关阅读:
    有符号数与无符号数的转换
    二进制的反码
    c 位运算
    安装和使用PhantomJS
    SecureCRT图形界面
    php curl模拟登陆抓取数据
    sublime text 3 配置方法
    chrome不支持12px,解决办法
    对下拉的一些操作记录
    Vue tree自定义事件注意点
  • 原文地址:https://www.cnblogs.com/liming19680104/p/15990979.html
Copyright © 2020-2023  润新知