Example program for measure fill level

dev_close_window ()
dev_update_off ()
read_image (Image, 'ampoules/ampoules_01')
get_image_size (Image, Width, Height)
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_set_line_width (2)
dev_set_draw ('margin')
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')

* 1-1创建模板
gen_rectangle1 (Rectangle, 230, 280, 317, 330)
reduce_domain (Image, Rectangle, ImageModel)
create_shape_model (ImageModel, 'auto', 0, 0, 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID)

* 2-1创建测量矩形
gen_measure_rectangle2 (0, 0, rad(90), 75, 20, Width, Height, 'bilinear', MeasureHandle)
Tolerance := 15

NumImages := 8
for Index := 1 to NumImages by 1
    read_image (Image, 'ampoules/ampoules_' + Index$'.2d')
    ColumnEdges := []
    FillLevelHeight := []

    * 1-2找寻模板
    find_shape_model (Image, ModelID, 0, 0, 0.7, 0, 0.1, 'least_squares', 0, 0.9, Row, Column, Angle, Score)

    MeanRow := mean(Row)
    RefLevel := MeanRow - 160

    * 显示液位区域
    dev_display (Image)
    dev_set_line_width (1)
    dev_set_color ('white')
    gen_rectangle2 (AcceptLevel, RefLevel, mean(Column), 0, 30 + (max(Column) - min(Column)) / 2, Tolerance)
    dev_display (AcceptLevel)
    dev_set_line_width (2)
 
    * 匹配后循环
    Errors := 0
    for Idx := 0 to |Score| - 1 by 1
        * 2-2测量(先变换一下测量)
        translate_measure (MeasureHandle, MeanRow - 135, Column[Idx])
        measure_pos (Image, MeasureHandle, 2, 7, 'all', 'first', RowEdge, ColumnEdge, Amplitude, Distance)

        FillLevelHeight := [FillLevelHeight,RowEdge]
        ColumnEdges := [ColumnEdges,ColumnEdge]
        gen_cross_contour_xld (Cross, RowEdge, ColumnEdge, 15, 0)
        gen_rectangle2 (FillLevel, RowEdge, ColumnEdge, 0, 28, 20)
        if (abs(FillLevelHeight[Idx] - RefLevel) >= Tolerance)
            gen_rectangle2 (ChamberSingle, MeanRow - 133, Column[Idx], 0, 35, 90)
            gen_cross_contour_xld (Cross, FillLevelHeight[Idx], ColumnEdges[Idx], 15, 0)
            gen_rectangle2 (FillLevel, FillLevelHeight[Idx], ColumnEdges[Idx], 0, 28, 20)
            Errors := Errors + 1
            dev_set_color ('red')
            dev_display (ChamberSingle)
            disp_message (WindowHandle, 'NG', 'image', FillLevelHeight[Idx] - 50, ColumnEdges[Idx] - 10, 'red', 'false')
        else
            disp_message (WindowHandle, 'OK', 'image', FillLevelHeight[Idx] - 50, ColumnEdges[Idx] - 10, 'green', 'false')
            dev_set_color ('green')
        endif
        dev_display (FillLevel)
        dev_display (Cross)
    endfor
    * 
    * Check, whether the fill level is within the allowed range - does not deviate too much
    * from average fill level
    * 
    * Display statistics
    if (Errors > 0)
        disp_message (WindowHandle, Errors + ' BAD', 'window', 10, 12, 'red', 'true')
    else
        disp_message (WindowHandle, 'All OK', 'window', 10, 12, 'forest green', 'true')
    endif
    if (Index < NumImages)
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor
* 
close_measure (MeasureHandle)
clear_shape_model (ModelID)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值