halcon-fuse.hdev

* fuse.hdev: measuring the width of a fuse wire
* 
dev_update_window ('off')
dev_close_window ()
* ****
* step: acquire image
* ****
read_image (Fuse, 'fuse')
get_image_size (Fuse, Width, Height)
dev_open_window_fit_image (Fuse, 0, 0, Width, Height, WindowID)
set_display_font (WindowID, 12, 'Courier', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
dev_display (Fuse)
set_display_font (WindowID, 12, 'courier', 'true', 'false')
disp_continue_message (WindowID, 'black', 'true')
stop ()
* ****
* step: create measure object
* ****
* -> specify ROI
Row := 297
Column := 545
Length1 := 90
Length2 := 10
Angle := rad(90)
gen_rectangle2 (ROI, Row, Column, Angle, Length1, Length2)
* -> create measure object
gen_measure_rectangle2 (Row, Column, Angle, Length1, Length2, Width, Height, 'bilinear', MeasureHandle)
dev_display (ROI)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* ****
* step: measure
* ****
measure_pairs (Fuse, MeasureHandle, 1, 1, 'negative_strongest', 'all', RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, IntraDistance, InterDistance)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* ****
* step: visualize results
* ****



for i := 0 to |RowEdgeFirst|-1 by 1
    
    row1:= [-sin(Angle+rad(90))*Length2+RowEdgeFirst[i], -sin(Angle-rad(90))*Length2+RowEdgeFirst[i]]
    column1:=[cos(Angle+rad(90))*Length2+ColumnEdgeFirst[i], cos(Angle-rad(90))*Length2+ColumnEdgeFirst[i]]
    
    row2:=[-sin(Angle+rad(90))*Length2+RowEdgeSecond[i], -sin(Angle-rad(90))*Length2+RowEdgeSecond[i]]
    column2:=[cos(Angle+rad(90))*Length2+ColumnEdgeSecond[i], cos(Angle-rad(90))*Length2+ColumnEdgeSecond[i]]
    
    gen_contour_polygon_xld (EdgeFirst, row1, column1)
    gen_contour_polygon_xld (EdgeSecond, row2, column2)
    
    dev_set_color ('cyan')
    dev_display (EdgeFirst)
    dev_set_color ('magenta')
    dev_display (EdgeSecond)
    dev_set_color ('blue')
    if (i = 0)
        set_tposition (WindowID, RowEdgeFirst[i] + 5, ColumnEdgeFirst[i]+20)
    else
        set_tposition (WindowID, RowEdgeFirst[i] - 40, ColumnEdgeFirst[i]+20)
    endif
    write_string (WindowID, 'width: '+IntraDistance[i]+' pix')
endfor
disp_continue_message (WindowID, 'black', 'true')
stop ()
* ****
* step: destroy measure object
* ****
close_measure (MeasureHandle)
dev_update_window ('on')
dev_clear_window ()

重要函数解析:
gen_rectangle2 (ROI, Row, Column, Angle, Length1, Length2)
产生一个矩形,以便用于显示gen_measure_rectangle2的处理范围

gen_measure_rectangle2 (Row, Column, Angle, Length1, Length2, Width, Height, 'bilinear', MeasureHandle)
产生的这个矩形框将作为感兴趣区域
Prepare the extraction of straight edges perpendicular to a rectangle.

measure_pairs (Fuse, MeasureHandle, 1, 1, 'negative_strongest', 'all', RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, IntraDistance, InterDistance)
第4个参数阈值比较重要
|

其中各点坐标
A:RowEdgeFirst[0],ColumnEdgeFirst[0]
A':RowEdgeSecond[0],ColumnEdgeSecond[0]

B:RowEdgeFirst[1],ColumnEdgeFirst[1]
B':RowEdgeSecon[1],ColumnEdgeSecond[1]

C:RowEdgeFirst[2],ColumnEdgeFirst[2]
C':RowEdgeSecond[2],ColumnEdgeSecond[2]




本例需要的是保险丝的宽度,即IntraDistance


gen_contour_polygon_xld (EdgeFirst, row1, column1)
本例是根据两点坐标产生一个轮廓EdgeFirst,比如row1=[1,2],column=[11,12],则产生的直线的首尾坐标是(1,11)和(2,12)


本例基本步骤:
1.输入灰度图像
2.gen_measure_rectangle2,划定ROI
3.measure_pairs.在ROI内测量边缘对
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值