欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Example program for distance_pc

程序员文章站 2022-07-04 16:00:32
...

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 ()

 

相关标签: halcon