测试效果
处理步骤
读取图片,获取图片宽度高度
read_image (Rim, 'rim')
get_image_size (Rim, Width, Height)
通过图像计算出XLD轮廓,通过条件筛选出对应的XLD
edges_sub_pix (Rim, Edges, 'canny', 4, 20, 40)
select_shape_xld (Edges, Holes, 'circularity', 'and', 0.7, 1.0)
sort_contours_xld (Holes, Holes, 'upper_left', 'true', 'row')
获取这个轮廓的最小外接圆参数
smallest_circle_xld (Holes, Row, Column, Radius)
count_obj (Holes, Number)
循环每个圆形XLD,计算最小外接圆的中心到这个轮廓的最小最大距离(通过这两个参数来判定这个圆形是否标准还是说有形变)
for i := 1 to Number by 1
select_obj (Holes, Hole, i)
dev_display (Rim)
dev_display (Hole)
distance_pc (Hole, Row[i - 1], Column[i - 1], DistanceMin, DistanceMax)
disp_cross (WindowID, Row[i - 1], Column[i - 1], 6, 0)
测试代码
* Example program for distance_pc
* Determine the minimal and maximal radius of drill holes
*
dev_close_window ()
read_image (Rim, 'rim')
get_image_size (Rim, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowID)
dev_display (Rim)
set_display_font (WindowID, 14, 'mono', 'false', 'false')
* Segment the circular holes
* The alpha parameter was choosen different than the default value
* to ensure stronger smoothing and thusmore connected edge components
edges_sub_pix (Rim, Edges, 'canny', 4, 20, 40)
select_shape_xld (Edges, Holes, 'circularity', 'and', 0.7, 1.0)
sort_contours_xld (Holes, Holes, 'upper_left', 'true', 'row')
* Determine the midpoints
smallest_circle_xld (Holes, Row, Column, Radius)
count_obj (Holes, Number)
dev_set_color ('yellow')
* For all boles ...
for i := 1 to Number by 1
select_obj (Holes, Hole, i)
dev_display (Rim)
dev_display (Hole)
* Compute the minimal and maximal radius of the holes by computing the
* distance of the midpoint to the contour
distance_pc (Hole, Row[i - 1], Column[i - 1], DistanceMin, DistanceMax)
* And visualize the results (minimal and maximal radius)
disp_cross (WindowID, Row[i - 1], Column[i - 1], 6, 0)
tuple_string (DistanceMin, '.3f', SVal)
get_string_extents (WindowID, 'min: ' + SVal, Ascent, Descent, Width1, Height1)
disp_message (WindowID, 'min: ' + SVal, 'image', Row[i - 1] - 2 * Ascent, Column[i - 1] - Radius[i - 1] - Width1 - 10, 'black', 'true')
disp_message (WindowID, 'max: ' + DistanceMax$'.3f', 'image', Row[i - 1], Column[i - 1] - Radius[i - 1] - Width1 - 10, 'black', 'true')
disp_continue_message (WindowID, 'black', 'true')
stop ()
endfor
dev_close_window ()