千家信息网

Halcon案例之药物检测

发表于:2024-11-13 作者:千家信息网编辑
千家信息网最后更新 2024年11月13日,*图片来自Halcon自带,Halcon2012版本for Index := 1 to 6 by 1read_image (Image, 'blister/blister_' + Index$'02'
千家信息网最后更新 2024年11月13日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


0