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’)
    endif

  • gen_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求取两点距离。

后记

大家有什么问题可以向我提问哈,我看到了第一时间回复,希望在学习的路上多多结交良师益友。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/255121.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

怎样屏蔽微信朋友圈视频?局域网如何禁止员工看朋友圈视频?

上班时间刷刷朋友圈&#xff0c;一眨眼半小时就过去了。不但会影响工作效率&#xff0c;而且朋友圈的视频会占用大量的带宽。所以对企业管理人员来说&#xff0c;很多时候需要禁止员工在工作时段刷朋友圈。但是行政手段要和技术手段配合&#xff0c;才可以发挥真正的作用。本文…

cf414B(dp)

题目链接&#xff1a;http://codeforces.com/problemset/problem/414/B 题意&#xff1a;定义所有元素是其前一个元素的倍数的数列为good sequence&#xff0c;给出 n, 和 k&#xff0c;求1....n组成的长度为k的good sequence 的数目&#xff1b; 思路&#xff1a;dp 用dp[i][j…

安装IIS

安装IIS过程中我们需要很多系统文件,这个时候我们就要下载一个非GHOST版本的系统安装文件就可以了, 雨林木风安装版8.0 http://dx.lwkb.com/setup/YlmF_XPSP3_YS8.0F/YlmF_XPSP3_YS8.0F.iso 这个不错 转载于:https://www.cnblogs.com/toSeeMyDream/p/5574884.html

深入理解C++的动态绑定和静态绑定

为了支持c的多态性&#xff0c;才用了动态绑定和静态绑定。理解他们的区别有助于更好的理解多态性&#xff0c;以及在编程的过程中避免犯错误。需要理解四个名词&#xff1a;1、对象的静态类型&#xff1a;对象在声明时采用的类型。是在编译期确定的。2、对象的动态类型&#x…

增量值编码器、单圈绝对值编码器、多圈绝对值编码器

主流的伺服电机位置反馈元件包括增量值编码器&#xff0c;单圈绝对值编码器&#xff0c;多圈绝对值编码器&#xff0c;旋转变压器等。下面分别介绍&#xff1a; 增量值编码器增量式编码器是将位移转换成周期性的电信号&#xff0c;再把这个电信号转变成计数脉冲&#xff0c;用…

HALCON示例程序inspect_bottle_mouth.hdev玻璃瓶口缺陷检测

HALCON示例程序inspect_bottle_mouth.hdev玻璃瓶口缺陷检测 示例程序源码&#xff08;加注释&#xff09; 定义变量并初始化 SmoothX : 501 ThresholdOffset : 25 MinDefectSize : 50 PolarResolution : 640 RingSize : 70 get_system (‘store_empty_region’, StoreEmptyReg…

静态主席树总结(静态区间的k大)

静态主席树总结(静态区间的&#xff4b;大) 首先我们先来看一道题 给定N个正整数构成的序列&#xff0c;将对于指定的闭区间查询其区间内的第K小值。 输入格式&#xff1a; 第一行包含两个正整数N、M&#xff0c;分别表示序列的长度和查询的个数。 第二行包含N个正整数&a…

Java中MySQL事务处理举例

实例&#xff08;以sql语句中的insert语句为例&#xff09; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement;/*** 事务的基本用法**/ …

永磁交流伺服电机的工作原理与更换新编码器后的常规零位校正方法

http://wuhuotun.blog.163.com/blog/static/73085450200910655748516/ 永磁交流伺服电机的编码器相位为何要与转子磁极相位对齐 其唯一目的就是要达成矢量控制的目标&#xff0c;使d轴励磁分量和q轴出力分量解耦&#xff0c;令永磁交流伺服电机定子绕组产生的电磁场始终正交于…

理解Java中字符流与字节流的区别

1. 什么是流 Java中的流是对字节序列的抽象&#xff0c;我们可以想象有一个水管&#xff0c;只不过现在流动在水管中的不再是水&#xff0c;而是字节序列。和水流一样&#xff0c;Java中的流也具有一个“流动的方向”&#xff0c;通常可以从中读入一个字节序列的对象被称为输入…

HALCON示例程序inspect_solar_fingers.hdev太阳能电池板电路缺陷检测

HALCON示例程序inspect_solar_fingers.hdev太阳能电池板电路缺陷检测 示例程序源码&#xff08;加注释&#xff09; 关于显示类函数解释 dev_update_off () dev_close_window () ImageName : ‘solar_cell/solar_cell_’ read_image (Image, ImageName ‘01’) dev_open_win…

C++多线程 例子

C多线程 例子2008-08-21 15:11//这是2个线程模拟卖火车票的小程序#include <windows.h>#include <iostream.h>DWORD WINAPI Fun1Proc(LPVOID lpParameter);//thread dataDWORD WINAPI Fun2Proc(LPVOID lpParameter);//thread dataintindex0;inttickets10;HANDLE hM…

2018/03/25

2019独角兽企业重金招聘Python工程师标准>>> March 25 2018 Sunday Weather&#xff1a;cloudy 1、需求&#xff1a; a0.5 b3 ca*b 求c的值&#xff1a; [rootDasoncheng sbin]# cat a.sh #!/bin/bash a0.5 b3 cecho $a*$b |bc echo $canswer referred&#xff1a;…

统计字符串中每种字符类型的个数demo

/** 统计字符串中每中字符类型的个数&#xff0c;思路&#xff1a;* 1、键盘录入一个字符串* 2、获取到每个字符&#xff0c;遍历字符串* for (int i 0; i < s.length(); i) {char ch s.charAt(i);* 3、判断每个字符属于哪种类型&#xff0c;对应的个数*/package cn.strin…

css3 图片放大缩小闪烁效果

直接把图片替换就可以了&#xff0c;我的图片是透明的&#xff0c;所以body设置为黑色的&#xff0c;不不要可以去掉 <!doctype html><html lang"en"><head> <meta charset"UTF-8"> <title>css3 图片放大缩小闪烁效果</t…

HALCON示例程序max_connection.hdev确定分割区域的最大区域数目

HALCON示例程序max_connection.hdev确定分割区域的最大区域数目 示例程序源码&#xff08;加注释&#xff09; read_image (Image, ‘monkey’) get_system (‘max_connection’, Information) set_system (‘max_connection’, 0) threshold (Image, Region, 128, 255) 区域…

elasticsearch分词聚合查询demo

2019独角兽企业重金招聘Python工程师标准>>> 我们在通过elasticsearch查询text类型的字段时&#xff0c;我们使用aggs进行聚合某个text类型field。这时elasticsearch会自动进行分词将分词后的结果进行聚合。获取每一个分词出现在文档的文档个数。注意&#xff1a;是…

软件工程进度条-第十五周

第十五周 所花时间&#xff08;包括上课&#xff09; 23 代码量&#xff08;行&#xff09; 1200 博客量&#xff08;篇&#xff09; 6 了解到的知识点 1、了解ListView的基本用法&#xff0c;并改变焦点触碰事件&#xff1b; 2、理解团队开发后进行软件项目总结的益处…

Spring实战第七章

一、SpringMVC配置代替方案 1自定DispatcherServlet 按照AbstractAnnotationConfigDispatcherServletInitializer的定义&#xff0c;它会创建DispatcherServlet和ContextLoaderListener。 AbstractAnnotationConfigDispatcherServletInitializer有三个方法是必须要重载的abstra…

EPSON TCP/IP 通信

EPSON SCARA机器人TCP/IP 通信时&#xff0c;涉及到的相关指令说明。 14.3 TCP/IP命令。 OpenNet //打开TCP/IP端口。 ChkNet //返回端口状态&#xff1a;等待读取的字节数或错误条件。 CloseNet //关闭TCP/IP端口。 SetNet //运行时或从命令窗口中设置通信端…