HALCON-从入门到入门-XLD的使用-拟合圆

1.废话

Halcon XLD(eXtended Line Descriptions)是Halcon机器视觉软件中的一个关键概念,主要用于描述亚像素级别的轮廓或多边形。以下是关于Halcon XLD的详细解释:

  1. 定义与特点
    • XLD是一个轮廓函数,用于表示比像素更精确的亚像素轮廓。它不是基于像素的,而是可以精确到像素内部的一种描述。
    • 在Halcon中,XLD常用于表示亚像素的轮廓和多边形。这些轮廓可以通过亚像素阈值分割或亚像素边缘提取等方法获得。
    • XLD可以表示直线或多边形,它是一组有序的控制点集合,控制点顺序用于说明彼此相连的关系。
  2. 分类
    • 闭轮廓:首尾相交的轮廓。
    • 开轮廓:首尾不相交的轮廓。
  3. 应用
    • XLD具有与region相似的多种特征,包括基础特征(如面积、中心、宽高、坐标等)、形状特征(如圆度、紧密度、长度、矩形度等)、云点特征(如云点面积、中心等)和几何特征(如二阶矩等)。
    • 可以使用特定的函数(如select_shape_xldselect_contours_xld)来选择具有特定特征的XLD轮廓。

2.实现效果

根据边缘 拟合过渡角圆心大小。

3.代码解析

首先还是读取图片

read_image (Image, 'double_circle')

接着快速滤波

fast_threshold (Image, Region, 0, 120, 7)

然后获取区域边缘

boundary (Region, RegionBorder, 'inner')

裁剪靠近图像边缘的区域

clip_region_rel (RegionBorder, RegionClipped, 5, 5, 5, 5)

接着膨胀这个边缘区域,并获取这个边缘区域内原来图像的像素

dilation_circle (RegionClipped, RegionDilation, 2.5)
reduce_domain (Image, RegionDilation, ImageReduced)

针对这个黑白边缘的像素图像,进行XLD提取

edges_sub_pix (ImageReduced, Edges, 'canny', 2, 20, 60)

按照曲率 将XLD分开成几段

segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 3)

对每一段xld进行圆形拟合

第一段的圆形拟合

第二段的圆形拟合

第三段的圆形拟合

接着显示出来就可以了。

这个案例告诉我们,先通过二值化来确定图像上黑白交界的区域,接着在这个区域内提取出XLD轮廓出来,对于这些轮廓就可以实现拟合圆或者拟合直线之类的技巧了。

4.文件

* 
* The edges in the image are segmented into lines and circles.
* For the edges that are part of a circle, the circle parameters
* are estimated and the resulting circle is displayed.
read_image (Image, 'double_circle')
* 
* Init window
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
* 
* Segment a region containing the edges
fast_threshold (Image, Region, 0, 120, 7)
boundary (Region, RegionBorder, 'inner')
clip_region_rel (RegionBorder, RegionClipped, 5, 5, 5, 5)
dilation_circle (RegionClipped, RegionDilation, 2.5)
reduce_domain (Image, RegionDilation, ImageReduced)
* 
* In the subdomain of the image containing the edges,
* extract subpixel precise edges.
edges_sub_pix (ImageReduced, Edges, 'canny', 2, 20, 60)
segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 3)
count_obj (ContoursSplit, Number)
dev_display (Image)
dev_set_draw ('margin')
dev_set_color ('white')
dev_update_window ('off')
for I := 1 to Number by 1
    select_obj (ContoursSplit, ObjectSelected, I)
    get_contour_global_attrib_xld (ObjectSelected, 'cont_approx', Attrib)
    * Fit a circle to the line segment that are arcs of a circle
    if (Attrib > 0)
        fit_circle_contour_xld (ObjectSelected, 'ahuber', -1, 2, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
        gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, rad(360), 'positive', 1.0)
        dev_display (ContCircle)
    endif
endfor
dev_set_colored (12)
dev_set_line_width (3)
dev_display (ContoursSplit)

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黄晓魚

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值