【issue-halcon例程学习】fuse.hdev

例程功能

 测量保险丝线的宽度。

代码如下

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, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
dev_display (Fuse)
set_display_font (WindowID, 12, 'mono', 'true', 'false')
disp_continue_message (WindowID, 'black', 'true')
stop ()
* ****
* step: create measure object
* ****
* -> specify ROI
Row := 297
Column := 545
Length1 := 80
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', '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
    gen_contour_polygon_xld (EdgeFirst, [-sin(Angle + rad(90)) * Length2 + RowEdgeFirst[i],-sin(Angle - rad(90)) * Length2 + RowEdgeFirst[i]], [cos(Angle + rad(90)) * Length2 + ColumnEdgeFirst[i],cos(Angle - rad(90)) * Length2 + ColumnEdgeFirst[i]])
    gen_contour_polygon_xld (EdgeSecond, [-sin(Angle + rad(90)) * Length2 + RowEdgeSecond[i],-sin(Angle - rad(90)) * Length2 + RowEdgeSecond[i]], [cos(Angle + rad(90)) * Length2 + ColumnEdgeSecond[i],cos(Angle - rad(90)) * Length2 + ColumnEdgeSecond[i]])
    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 ()

要点

  1. 作为Measure篇章的第一份代码,需要从中明确测量流程:获取图片 ~> 仿射变换 ~> 调整图片和ROI ~> 创建测量对象 ~> 执行测量操作 ~> 转换结果至世界坐标系 ~> 可视化。
  2. gen_measure_rectangle2
    Row:入参,中心纵坐标;
    Column:入参,中心横坐标;
    Phi :入参,偏转角(弧度制);
    Length1:入参,矩形宽度一半;
    Length2:入参,矩形长度一半;
    Width :入参,待处理图片宽;
    Height:入参,待处理图片高;
    Interpolation :入参,插值方式;
    MeasureHandle :出参,测量句柄;
  3. measure_pairs
    Image :入参,待处理图像;
    MeasureHandle :入参,测量句柄;
    Sigma :入参,高斯平滑参数;
    Threshold :入参,最小边沿振幅;
    Transition :入参,灰度值转换的类型,用于确定如何将边分组;
    Select :入参,选择边缘的方式;
    RowEdgeFirst :出参,第一条边中心的行坐标;
    ColumnEdgeFirst :出参,第一条边中心的纵坐标;
    AmplitudeFirst :出参,第一边沿的边沿幅度;
    RowEdgeSecond :出参,第二条边中心的行坐标;
    ColumnEdgeSecond :出参,第二条边中心的纵坐标;
    AmplitudeSecond :出参,第二边沿的边沿幅度;
    IntraDistance :出参,一组边缘对内的距离;
    InterDistance :出参,相邻边缘对间的距离;

你可能感兴趣的:(学习,视觉检测)