Halcon 10.0:Sample 分割边缘拟合圆Circles.hdev

时间:2022-03-21 15:31:31

处理流程:快速二值化(区域)->获取区域边缘->截取边缘->膨胀边缘区域(定位)->定位区域进行边缘检测->边缘分割:线和圆->选择属性为圆的弧->拟合圆

*读取图像
read_image (Image, 'double_circle')
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window (, , Width, Height, 'black', WindowHandle)
*快速二值化
fast_threshold (Image, Region, , , )
*取region的边界
boundary (Region, RegionBorder, 'inner')
*剪切、膨胀定位弧形区域
clip_region_rel (RegionBorder, RegionClipped, , , , )
dilation_circle (RegionClipped, RegionDilation, 2.5)
reduce_domain (Image, RegionDilation, ImageReduced)
*在弧形区域进行边缘检测
edges_sub_pix (ImageReduced, Edges, 'lanser2', 0.5, , )
*分割边缘:线和圆
segment_contours_xld (Edges, ContoursSplit, 'lines_circles', , , )
count_obj (ContoursSplit, Number)
dev_display (Image)
dev_set_draw ('margin')
dev_set_color ('white')
dev_update_window ('off')
for i := to Number by
*选择轮廓并根据特性确定是否拟合圆:* Attrib = - 线段 椭圆 1圆
select_obj (ContoursSplit, ObjectSelected, i)
get_contour_global_attrib_xld (ObjectSelected, 'cont_approx', Attrib)
if (Attrib > )
*逼近结果生成一个圆轮廓
fit_circle_contour_xld (ObjectSelected, 'ahuber', -, , , , , Row, Column, Radius, StartPhi, EndPhi, PointOrder)
gen_circle_contour_xld (ContCircle, Row, Column, Radius, , rad(), 'positive', 1.0)
dev_display (ContCircle)
endif
endfor
dev_set_colored ()
dev_set_line_width ()
dev_display (ContoursSplit)

Halcon 10.0:Sample 分割边缘拟合圆Circles.hdevHalcon 10.0:Sample 分割边缘拟合圆Circles.hdev