【Halcon边界轮廓提取与圆弧段拟合】

文章目录


返回拟合的圆起始角度 位置 半径

在这里插入图片描述

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')
*在原区域的基础上做一个最小外接矩形得到区域1,然后让刚才那个矩形上下左右都以5的像素内缩,得到矩形2,
*现在形成了一个矩形环,用区域1减去这个矩形环,得到剩下的区域就是目标区域
clip_region_rel (RegionBorder, RegionClipped, 5, 5, 5, 5)
*使用半径为2.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)
*分割XLD轮廓为线段和圆弧或椭圆弧
*segment_contours_xld(Contours : ContoursSplit :
*Mode, SmoothCont, MaxLineDist1, MaxLineDist2 : )
*Contours :输入轮廓;ContoursSplit:分割后的轮廓;Mode:轮廓分割模式;
*SmoothCont:用于平滑轮廓的点数;MaxLineDist1:轮廓与近似线之间的最大距离(第一次迭代);
*MaxLineDist2 :轮廓与近似线之间的最大距离(第二次迭代)
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)
    *返回XLD轮廓的全局属性值’cont_approx’表示:对于’cont_approx’=-1,轮廓近似线段;
    *‘cont_approx’=0,曲线近似椭圆;‘cont_approx’=1,曲线近似圆弧。
    get_contour_global_attrib_xld (ObjectSelected, 'cont_approx', Attrib)
    * Fit a circle to the line segment that are arcs of a circle
    *大于0表示为圆弧段,用圆弧拟合
    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)

猜你喜欢

转载自blog.csdn.net/weixin_42483745/article/details/126953415