halcon案例distance_pc.hdev

C:\Users\Public\Documents\MVTec\HALCON-23.05-Progress\examples\hdevelop\Tools\Geometry\distance_pc.hdev
例程相对简单

一直没关注过这个算子:最近总在找一个合适的矩形计算的东西。可能有用,记录
点到contour的距离
distance_pc (Hole, Row[i - 1], Column[i - 1], DistanceMin, DistanceMax)
点和contour可以是包含,可以是点在contour上,也可以是点在外。
读图并筛选到类圆形,且直接用外界椭圆的方式取得圆心。
1
计算得到圆心位置到待拟合轮廓的最大最小距离。

2

* 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, 500, 500, 'black', WindowID)
dev_display (Rim)
set_display_font (WindowID, 14, 'mono', 'false', 'false')
* Segment the circular holes
* The alpha parameter was chosen different than the default value
* to ensure stronger smoothing and thus more 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)
gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, 6.28318, 'positive', 1)
    dev_display (Rim)
    dev_display (ContCircle)
    stop ()

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
    gen_circle (Circle, Row[i - 1], Column[i - 1], 2)
    
    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 ()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值