Halcon案例之药物检测

*图片来自Halcon自带,Halcon2012版本

for Index := 1 to 6 by 1

    read_image (Image, 'blister/blister_' + Index$'02')

    decompose3 (Image, ImageR, ImageG, ImageB)

    threshold (ImageR, Region1, 128, 255)

    shape_trans (Region1, RegionTrans, 'convex')

    reduce_domain (ImageB, RegionTrans, ImageReduced)

    var_threshold ( ImageReduced, Region, 7, 7, 0.2, 2, 'dark')

    connection (Region, ConnectedRegions0)

    closing_rectangle1 (ConnectedRegions0, ConnectedRegions, 3, 3)

    fill_up (ConnectedRegions, RegionFillUp)

    select_shape (RegionFillUp, SelectedRegions, 'area', 'and', 1000, 99999)

    opening_circle (SelectedRegions, RegionOpening, 4.5)

    connection (RegionOpening, ConnectedRegions)

    select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 1000, 99999)

    shape_trans (SelectedRegions, Pills, 'convex')

    area_center (Pills, Area, Row, Column)

    Mes:=0

    *少药丸

    Miss:=15-|Area|

    min_max_gray (Pills, ImageG, 0, Min, Max, Range)

    *错药丸

    for i:=0 to |Min|-1 by 1

        if(Area[i]<3800)

            Mes:=Mes+1

        endif 

        if(Min[i]<80)

            Mes:=Mes+1

        endif

    endfor

    *OK药丸

    Res:=15-Miss-Mes

    dev_display (Image)

    disp_message (3600, '缺少药丸个数:'+Miss, 'window', 12, 12, 'black', 'true')

    disp_message (3600, '错误药丸个数:'+Mes, 'window', 42, 12, 'black', 'true')

    disp_message (3600, '正确药丸个数:'+Res, 'window', 72, 12, 'black', 'true')

    stop ()

endfor

原创文章,作者:kepupublish,如若转载,请注明出处:https://blog.ytso.com/191829.html

(0)
上一篇 2021年11月14日
下一篇 2021年11月14日

相关推荐

发表回复

登录后才能评论