halcon-fuse.hdev

来源:互联网 发布:君泽君 知乎 编辑:程序博客网 时间:2024/06/09 21:35
* 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 ROIRow := 297Column := 545Length1 := 90Length2 := 10Angle := rad(90)gen_rectangle2 (ROI, Row, Column, Angle, Length1, Length2)* -> create measure objectgen_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')endfordisp_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内测量边缘对
原创粉丝点击