资源文件
链接:https://pan.baidu.com/s/1nZVOwVZGqd8VeJPg70BCEg
提取码:spzv
处理图片
#
代码
* 1.读取图片 ***********************************************
read_image (Image, './double_circle.png')
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
* 2.分割出边缘区域 **********************************************
* 快速二值化
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)
* 3.边缘检测与分割 **********************************************
* 边缘检测
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')
* 4.边缘分析 **********************************************
for I := 1 to Number by 1
* 选择其中一个边缘
select_obj (ContoursSplit, ObjectSelected, I)
* 判定边缘性质 (Attrib = 1 是圆形)
get_contour_global_attrib_xld (ObjectSelected, 'cont_approx', Attrib)
if (Attrib > 0)
* 边缘拟合圆形
fit_circle_contour_xld (ObjectSelected, 'ahuber', -1, 2, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
* 绘制圆形XLD
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)