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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章