* 图像中的边缘被分割成线和圆。
* 对于属于圆的边,估计圆的参数并显示得到的圆。
*
* 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
* 分割包含边缘的区域
* 在支持SSE2指令集的多核计算机上,threshold很可能比fast_threshold快。
* Fast_threshold可能只在那些特性不可用的情况下被优先使用,例如在嵌入式平台上。
fast_threshold (Image, Region, 0, 120, 7)
boundary (Region, RegionBorder, 'inner')
* 在现有区域基础上,减去一个现有区域的最小外接矩形的每一条边
* 这样就可以去掉外围水平或垂直的区域,只留下弯曲的部分
clip_region_rel (RegionBorder, RegionClipped, 5, 5, 5, 5)
*
* 这个操作相当于:
* shape_trans (Region, RegionTrans, 'rectangle1')
* erosion_rectangle1 (RegionTrans, RegionErosion, 5, 5)
* intersection (RegionErosion, RegionBorder, RegionClipped)
*
dilation_circle (RegionClipped, RegionDilation, 2.5)
reduce_domain (Image, RegionDilation, ImageReduced)
*
* In the subdomain of the image containing the edges,extract subpixel precise edges.
* 在包含边缘的图像的子域中,提取亚像素级的精确边缘。
* 使用Deriche, Lanser, Shen或Canny滤波器提取亚像素精确边缘
* Canny算子:使用累计直方图计算两个阀值。凡是大于高阀值的一定是边缘; 凡是小于低阀值的一定不是边缘;如果检测结果大于低阀值但又小于高阀值,那就要看这个像素的邻接像素中有没有超过高阀值的边缘像素:如果有的话那么它就是边缘了,否则他就不是边缘;
edges_sub_pix (ImageReduced, Edges, 'canny', 2, 20, 60)
* 分割XLD轮廓线,可以选择'lines'(使用直线段分割), 'lines_circles'(使用直线段和圆(弧)分割), 'lines_ellipses'(使用直线段和椭圆弧分割)。
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’参数的值来确定(参考get_contour_global_attrib_xld)。
* 如果'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
* 将圆与圆弧的线段拟合
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)