HALCON示例程序inspect_bga.hdev测量bga焊点缺陷
HALCON示例程序inspect_bga.hdev测量bga焊点缺陷
示例程序源码(加注释)
关于显示类函数解释
read_image (Image, ‘bga_14x14_model’)
get_image_pointer1 (Image, Pointer, Type, Width, Height)
dev_update_off ()
dev_close_window ()
dev_open_window (0, 0, Width, Height, ‘light gray’, WindowHandle)
set_display_font (WindowHandle, 16, ‘mono’, ‘true’, ‘false’)
dev_set_part (0, 0, Height - 1, Width - 1)
dev_display (Image)
dev_set_line_width (1)
dev_set_color (‘green’)
VisualizeIntermediate := true快速二值化
fast_threshold (Image, Region, 95, 255, 3)分割定义域
connection (Region, ConnectedRegions)通过面积与长短轴比筛选区域
select_shape (ConnectedRegions, SelectedRegions, [‘area’,‘anisometry’], ‘and’, [20,1.0], [100,1.7])使用矩形元素膨胀区域
dilation_rectangle1 (SelectedRegions, RegionDilation, 3, 3)求取灰度重心
area_center_gray (RegionDilation, Image, Volume, Row, Column)创建像素点表示的区域
gen_region_points (RegionBGACenters, Row, Column)求取可旋转最小外接矩形
smallest_rectangle2 (RegionBGACenters, RowBGARect, ColumnBGARect, PhiBGARect, Length1BGARect, Length2BGARect)
if (VisualizeIntermediate)
dev_display (Image)
dev_set_color (‘red’)
dev_display (RegionBGACenters)
dev_set_color (‘green’)
dev_set_draw (‘margin’)
gen_rectangle2 (BGARect, RowBGARect, ColumnBGARect, PhiBGARect, Length1BGARect, Length2BGARect)
dev_display (BGARect)
dev_set_draw (‘fill’)
endif
disp_message (WindowHandle, ‘Reference BGA’, ‘window’, 10, 10, ‘black’, ‘false’)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()定义变量并初始化
BallsPerRow := 14
BallsPerCol := 14二维仿射变换
BallDistCol := 2 * Length1BGARect / (BallsPerCol - 1)
BallDistRow := 2 * Length2BGARect / (BallsPerRow - 1)
hom_mat2d_identity (HomMat2DIdentity)旋转
hom_mat2d_rotate (HomMat2DIdentity, -PhiBGARect, RowBGARect, ColumnBGARect, HomMat2DRotate)移动
hom_mat2d_translate (HomMat2DRotate, -RowBGARect + Length2BGARect, -ColumnBGARect + Length1BGARect, HomMat2DTranslate)缩放
hom_mat2d_scale (HomMat2DTranslate, 1 / BallDistRow, 1 / BallDistCol, 0, 0, HomMat2DScale)对点进行仿射变换
affine_trans_point_2d (HomMat2DScale, Row, Column, RowNormalized, ColNormalized)round转换为整数
BGARowIndex := round(RowNormalized)
BGAColIndex := round(ColNormalized)
NumBalls := |Row|
dev_set_color (‘black’)
if (VisualizeIntermediate)
dev_clear_window ()
dev_set_draw (‘margin’)
for i := 0 to NumBalls - 1 by 1绘十字线disp_cross (WindowHandle, 10 + BGARowIndex[i] * 10, 10 + BGAColIndex[i] * 10, 6, 0)
endfor
dev_set_draw (‘fill’)
endifgen_tuple_const生成常量数组
BallMatrix := gen_tuple_const(BallsPerRow * BallsPerCol,-1)
for i := 0 to NumBalls - 1 by 1
BallMatrix[BGARowIndex[i] * BallsPerCol + BGAColIndex[i]] := i
endfor
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()
read_image (Image, ‘bga_14x14_defects’)
dev_display (Image)
disp_message (WindowHandle, ‘BGA to be checked’, ‘window’, 10, 10, ‘black’, ‘false’)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()线面一段代码和上边创建模板时一样
fast_threshold (Image, Region, 95, 255, 3)
connection (Region, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, [‘area’,‘anisometry’], ‘and’, [20,1.0], [100,1.7])
dilation_rectangle1 (SelectedRegions, RegionDilation, 3, 3)
area_center_gray (RegionDilation, Image, VolumeCheck, RowCheck, ColumnCheck)
elliptic_axis_gray (RegionDilation, Image, RaCheck, RbCheck, PhiCheck)
AnisometryCheck := RaCheck / RbCheck
gen_region_points (RegionBGACenters, RowCheck, ColumnCheck)
smallest_rectangle2 (RegionBGACenters, RowBGACheck, ColumnBGACheck, PhiBGACheck, Length1BGACheck, Length2BGACheck)
if (VisualizeIntermediate)
dev_display (Image)
dev_set_color (‘red’)
dev_display (RegionBGACenters)
dev_set_color (‘green’)
dev_set_draw (‘margin’)
gen_rectangle2 (BGARect, RowBGACheck, ColumnBGACheck, PhiBGACheck, Length1BGACheck, Length2BGACheck)
dev_display (BGARect)
dev_set_draw (‘fill’)
endif
BallDistCol := 2 * Length1BGACheck / (BallsPerCol - 1)
BallDistRow := 2 * Length2BGACheck / (BallsPerRow - 1)
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_rotate (HomMat2DIdentity, -PhiBGACheck, RowBGACheck, ColumnBGACheck, HomMat2DRotate)
hom_mat2d_translate (HomMat2DRotate, -RowBGACheck + Length2BGACheck, -ColumnBGACheck + Length1BGACheck, HomMat2DTranslate)
hom_mat2d_scale (HomMat2DTranslate, 1 / BallDistRow, 1 / BallDistCol, 0, 0, HomMat2DScale)
affine_trans_point_2d (HomMat2DScale, RowCheck, ColumnCheck, RowNormalized, ColNormalized)
BGARowIndex := round(RowNormalized)
BGAColIndex := round(ColNormalized)
NumBalls := |RowCheck|
dev_set_color (‘black’)
if (VisualizeIntermediate)
dev_clear_window ()
dev_set_draw (‘margin’)
for i := 0 to NumBalls - 1 by 1
disp_cross (WindowHandle, 10 + BGARowIndex[i] * 10, 10 + BGAColIndex[i] * 10, 6, 0)
endfor
dev_set_draw (‘fill’)
endif
BallMatrixCheck := gen_tuple_const(BallsPerRow * BallsPerCol,-1)
for i := 0 to NumBalls - 1 by 1
BallMatrixCheck[BGARowIndex[i] * BallsPerCol + BGAColIndex[i]] := i
endfor
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()
Rows1 := gen_tuple_const(NumBalls,0)
Cols1 := gen_tuple_const(NumBalls,0)
Rows2 := gen_tuple_const(NumBalls,0)
Cols2 := gen_tuple_const(NumBalls,0)
Phi2 := gen_tuple_const(NumBalls,0)
Ra2 := gen_tuple_const(NumBalls,0)
Rb2 := gen_tuple_const(NumBalls,0)
Anisometry2 := gen_tuple_const(NumBalls,0)
Volume2 := gen_tuple_const(NumBalls,0)
j := 0
for i := 0 to BallsPerRow * BallsPerCol - 1 by 1
if (BallMatrix[i] >= 0 and BallMatrixCheck[i] >= 0)
Rows1[j] := Row[BallMatrix[i]]
Cols1[j] := Column[BallMatrix[i]]
Rows2[j] := RowCheck[BallMatrixCheck[i]]
Cols2[j] := ColumnCheck[BallMatrixCheck[i]]
Phi2[j] := PhiCheck[BallMatrixCheck[i]]
Ra2[j] := RaCheck[BallMatrixCheck[i]]
Rb2[j] := RbCheck[BallMatrixCheck[i]]
Anisometry2[j] := AnisometryCheck[BallMatrixCheck[i]]
Volume2[j] := VolumeCheck[BallMatrixCheck[i]]
j := j + 1
endif
endfor从至少两个点对应关系近似刚性仿射变换,即由旋转和平移组成的变换
vector_to_rigid (Rows1, Cols1, Rows2, Cols2, HomMat2D)
affine_trans_point_2d (HomMat2D, Rows1, Cols1, RowTrans, ColumnTrans)
affine_trans_point_2d (HomMat2D, Row, Column, RowTransFull, ColumnTransFull)
if (VisualizeIntermediate)
dev_clear_window ()
for i := 0 to |Rows2| - 1 by 1
* 通过元组元素生成XLD边缘轮廓
gen_contour_polygon_xld (Lines, [Rows2[i],RowTrans[i]], [Cols2[i],ColumnTrans[i]])
dev_display (Lines)endfor
endif两个点之间的距离
distance_pp (Rows2, Cols2, RowTrans, ColumnTrans, Distance)求取最大距离
MaxDistance := max(Distance)
dev_display (Image)
dev_set_draw (‘margin’)
gen_empty_obj (EllipseCorrect)
gen_empty_obj (EllipseDeviation)
gen_empty_obj (EllipseDeformation)
gen_empty_obj (EllipseVolume)
gen_empty_obj (Missing)
dev_set_color (‘white’)
VolumeMean := mean(Volume)
VolumeMin := min(Volume)
VolumeMax := max(Volume)
VolumecheckMean := mean(VolumeCheck)
VolumeCheckMin := min(VolumeCheck)
VolumeCheckMax := max(VolumeCheck)
j := 0
for i := 0 to BallsPerRow * BallsPerCol - 1 by 1
if (BallMatrix[i] >= 0 and BallMatrixCheck[i] >= 0)
gen_ellipse (Ellipse, Rows2[j], Cols2[j], Phi2[j], Ra2[j], Rb2[j])
if (Distance[j] > 0.05)
concat_obj (EllipseDeviation, Ellipse, EllipseDeviation)
else
if (Anisometry2[j] > 1.2)
concat_obj (EllipseDeformation, Ellipse, EllipseDeformation)
else
if (Volume2[j] < 5500 or Volume2[j] > 10000)
concat_obj (EllipseVolume, Ellipse, EllipseVolume)
else
concat_obj (EllipseCorrect, Ellipse, EllipseCorrect)
endif
endif
endif
j := j + 1
else
if (BallMatrix[i] >= 0)生成XLD十字线gen_cross_contour_xld (Cross, RowTransFull[BallMatrix[i]], ColumnTransFull[BallMatrix[i]], 10, 0.785398)concat_obj (Missing, Cross, Missing)endif
endif
endfor
dev_set_line_width (2)
dev_display (Image)
disp_message (WindowHandle, ‘White cross: segmentation of ball failed’, ‘window’, 10, 10, ‘black’, ‘false’)
dev_set_color (‘white’)
dev_display (Missing)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()
dev_display (Image)
disp_message (WindowHandle, ‘Ellipse: center positions deviate’, ‘window’, 10, 10, ‘black’, ‘false’)
dev_set_color (‘white’)
dev_display (EllipseDeviation)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()
dev_display (Image)
disp_message (WindowHandle, ‘Ellipse: deformed balls’, ‘window’, 10, 10, ‘black’, ‘false’)
dev_set_color (‘white’)
dev_display (EllipseDeformation)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()
dev_display (Image)
disp_message (WindowHandle, ‘Ellipse: gray value volume out of range’, ‘window’, 10, 10, ‘black’, ‘false’)
dev_set_color (‘white’)
dev_display (EllipseVolume)
处理思路
这个例子是主要讲解了焊点完整性检测。gen_region_points生成点区域;hom_mat2d_identity、hom_mat2d_rotate、hom_mat2d_translate、hom_mat2d_scale、affine_trans_point_2d、vector_to_rigid仿射变换; gen_contour_polygon_xld;绘制十字线distance_pp求取两点距离。
后记
大家有什么问题可以向我提问哈,我看到了第一时间回复,希望在学习的路上多多结交良师益友。
HALCON示例程序inspect_bga.hdev测量bga焊点缺陷相关推荐
- HALCON示例程序particle.hdev测量小圆部分
HALCON示例程序particle.hdev测量小圆部分 示例程序源码(加注释) 关于显示类函数解释 dev_update_off () dev_close_window () dev_open_w ...
- HALCON示例程序measure_circles.hdev测量圆的半径
HALCON示例程序measure_circles.hdev测量圆的半径 示例程序源码(加注释) 关于显示类函数解释 dev_update_off () read_image (Image, 'cir ...
- HALCON示例程序pcb_inspection.hdev检测pcb印刷缺陷
HALCON示例程序pcb_inspection.hdev检测pcb印刷缺陷 示例程序源码(加注释) 关于显示类函数解释 read_image (Image, 'pcb') dev_close_win ...
- HALCON示例程序inspect_solar_fingers.hdev太阳能电池板电路缺陷检测
HALCON示例程序inspect_solar_fingers.hdev太阳能电池板电路缺陷检测 示例程序源码(加注释) 关于显示类函数解释 dev_update_off () dev_close_w ...
- HALCON示例程序fin.hdev通过形态学检测缺陷
HALCON示例程序fin.hdev通过形态学检测缺陷 示例程序源码(加注释) 关于显示类函数解释 dev_update_window ('off') read_image (Fins, 'fin' ...
- HALCON示例程序measure_ball_bond.hdev电路板焊点位置测量
HALCON示例程序measure_ball_bond.hdev电路板焊点位置测量 示例程序源码(加注释) 关于显示类函数解释 dev_update_off () dev_close_window ( ...
- HALCON示例程序vessel.hdev血管的分割与测量
小哥哥小姐姐觉得有用点个赞呗! HALCON示例程序vessel.hdev血管的分割与测量 示例程序源码(加注释) 关于显示类函数解释 dev_update_window ('off') dev_cl ...
- HALCON示例程序measure_screw.hdev螺纹尺寸测量
HALCON示例程序measure_screw.hdev螺纹尺寸测量 示例程序源码(加注释) 关于显示类函数解释 dev_update_off () read_image (Image, 'screw ...
- HALCON示例程序measure_ring.hdev齿轮齿宽度测量
HALCON示例程序measure_ring.hdev齿轮齿宽度测量 示例程序源码(加注释) 关于显示类函数解释 read_image (Image, 'rings_and_nuts') dev_cl ...
最新文章
- python3:利用SMTP协议发送QQ邮件+附件
- 全局声明宏定义_Rust语言:元编程,强大的宏系统,菜鸟到高手进阶的必经之路...
- centos7修改系统语言为简体中文
- 三次样条插值 cubic spline interpolation
- C# 按钮美化技巧
- 格鲁吉亚理工学院计算机全美排名,乔治亚理工大学环境工程排名2019年
- Java 算法 一元多项式求导
- Linux 下 Shell 命令的分类及用法
- 【已解决】手机“此设备已安装证书授权中心,您的安全网络流量可能被监控”怎么办?
- GoogleTest测试框架介绍(一)
- 象棋名手手机版2019最新版_象棋名手超强版下载
- 3D数学 学习笔记(4) 几何图元
- eclipse优化记录
- 武汉理工大学 计算机学院院长,熊盛武:武汉理工大学计算机科学与技术学院院长、教授...
- 物联网终端安全系列(之一) -- 物联网终端安全风险简析
- 【开源分享】自制STC15W408AS开发板
- 如何从外网穿透到内网
- ubantu查看设备序列号
- 产品品牌想正向刷屏 就需做好精致化内容
- ArcMap 镶嵌数据集基本使用方法
热门文章
- 牛腩新闻发布系统(一):SQLHelper重构(一)
- [tomcat] 配置数据源介绍
- 删除android系统自带的第三方软件
- 微软ASP.NET站点部署指南(3):使用Web.Config文件的Transformations
- Angular自学笔记(?)结构型指令
- vue图片懒加载插件vue-lazyload
- d3.js 入门指南 - 仪表盘
- 转 ABAP_ALV_Function方式与OO方式(较为简单、普通的ALV)
- C#中往数据库插入/更新时候关于NUll空值的处理
- linux --- 进阶指令