Example program for distance_pc

* 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')

* 提取边缘
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)
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)
    
    * 通过计算中点到轮廓的距离来计算孔的最小和最大半径
    distance_pc (Hole, Row[i - 1], Column[i - 1], DistanceMin, DistanceMax)

    * 显示结果
    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 ()

 

发布了20 篇原创文章 · 获赞 3 · 访问量 5338
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章