Halcon 10.0 Sample:完整性检查(圆形)

 * ball.hdev: Inspection of Ball Bonding
* 球接合检查 Comment Time://
*核心思想:.白色区域用作自动ROI,黑色区域是目标
* .Opening_circle:圆形开算子是关键
*关闭窗口刷新,关闭窗口,打开窗口[,]
dev_update_window ('off')
dev_close_window ()
dev_open_window (, , , , 'black', WindowID)
*读取图像并显示
read_image (Bond, 'die/die_03')
dev_display (Bond)
set_display_font (WindowID, , 'mono', 'true', 'false')
*显示F5提示信息并暂停
disp_continue_message (WindowID, 'black', 'true')
stop ()
*固定二值化,取白色区域部分
threshold (Bond, Bright, , )
*将所有区域变换成最小的外接矩形,相当于做ROI
shape_trans (Bright, Die, 'rectangle2')
*设置显示方式:绿色,边缘模式,线条宽度3
dev_set_color ('green')
dev_set_line_width ()
dev_set_draw ('margin')
dev_display (Die)
disp_continue_message (WindowID, 'black', 'true')
stop ()
*利用生成的外接矩形做ROI
reduce_domain (Bond, Die, DieGrey)
*在ROI中二值化取黑色区域,并按面积标准填充
threshold (DieGrey, Wires, , )
fill_up_shape (Wires, WiresFilled, 'area', , )
*设置显示模式:填充模式,红色
dev_display (Bond)
dev_set_draw ('fill')
dev_set_color ('red')
dev_display (WiresFilled)
disp_continue_message (WindowID, 'black', 'true')
stop ()
*圆形式的开运算:先腐蚀后膨胀,消除颗粒(精髓算子)
opening_circle (WiresFilled, Balls, 15.5)
dev_set_color ('green')
dev_display (Balls)
disp_continue_message (WindowID, 'black', 'true')
stop ()
*单个区域连接成区域数组
connection (Balls, SingleBalls)
*按圆度来进行区域的筛选,完成定位功能
select_shape (SingleBalls, IntermediateBalls, 'circularity', 'and', 0.85, 1.0)
*已OK的区域进行从左至右排序
sort_region (IntermediateBalls, FinalBalls, 'first_point', 'true', 'column')
dev_display (Bond)
dev_set_colored ()
dev_display (FinalBalls)
disp_continue_message (WindowID, 'black', 'true')
stop ()
*求区域的最小外接圆
smallest_circle (FinalBalls, Row, Column, Radius)
NumBalls := |Radius|
Diameter := *Radius
meanDiameter := sum(Diameter)/NumBalls
mimDiameter := min(Diameter)
dev_display (Bond)
*显示最小外接圆
disp_circle (WindowID, Row, Column, Radius)
*书写文字标识
dev_set_color ('white')
for i := to NumBalls by
if (fmod(i,)=)
disp_message (WindowID, 'D: '+Diameter[i-], 'image', Row[i-]-2.7*Radius[i-], max([Column[i-]-,]), 'white', 'false')
else
disp_message (WindowID, 'D: '+Diameter[i-], 'image', Row[i-]+1.2*Radius[i-], max([Column[i-]-,]), 'white', 'false')
endif
endfor
*关闭窗口
* dump_window (WindowID, 'tiff_rgb', './ball')
dev_set_color ('green')
dev_update_window ('on')
disp_continue_message (WindowID, 'black', 'true')
stop ()
dev_close_window ()

Halcon 10.0 Sample:完整性检查(圆形)

上一篇:GO_order


下一篇:苹果手机制作gif图片