在图像中识别并测量芯片引脚的边缘对

上述代码是用HALCON软件编写的,HALCON是一款德国MVTec公司开发的机器视觉软件,广泛应用于图像处理、机器视觉、图像识别等领域

dev_close_window ()
read_image (Image, ‘board/board-06’)
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, ‘black’, WindowHandle)
*

  • — Fuzzy Measure:
    Row1 := 305.5
    Col1 := 375.5
    Phi1 := 0.982
    Length1 := 167
    Length2 := 8
    gen_measure_rectangle2 (Row1, Col1, Phi1, Length1, Length2, Width, Height, ‘nearest_neighbor’, MeasureHandle1)
    Row2 := 188.5
    Col2 := 202.5
    Phi2 := Phi1 - rad(180)
    gen_measure_rectangle2 (Row2, Col2, Phi2, Length1, Length2, Width, Height, ‘nearest_neighbor’, MeasureHandle2)
  • Create a fuzzy member function to select edge pairs of size of the chip pins (about 11 Pixels)
    create_funct_1d_pairs ([0.0,0.3], [1.0,0.0], FuzzyAbsSizeDiffFunction)
    set_fuzzy_measure_norm_pair (MeasureHandle1, 11.0, ‘size_abs_diff’, FuzzyAbsSizeDiffFunction)
    set_fuzzy_measure_norm_pair (MeasureHandle2, 11.0, ‘size_abs_diff’, FuzzyAbsSizeDiffFunction)
    fuzzy_measure_pairs (Image, MeasureHandle1, 1, 30, 0.5, ‘positive’, RowEdgeFirst1, ColumnEdgeFirst1, AmplitudeFirst1, RowEdgeSecond1, ColumnEdgeSecond1, AmplitudeSecond1, RowEdgeMiddle1, ColumnEdgeMiddle1, FuzzyScore1, IntraDistance1, InterDistance1)
    fuzzy_measure_pairs (Image, MeasureHandle2, 1, 30, 0.5, ‘positive’, RowEdgeFirst2, ColumnEdgeFirst2, AmplitudeFirst2, RowEdgeSecond2, ColumnEdgeSecond2, AmplitudeSecond2, RowEdgeMiddle2, ColumnEdgeMiddle2, FuzzyScore2, IntraDistance2, InterDistance2)
  • — Visualization:
    dev_display (Image)
  • Measuring area
    dev_display_measure_object (Row1, Col1, Phi1, Length1, Length2)
    dev_display_measure_object (Row2, Col2, Phi2, Length1, Length2)
  • Edge pairs
    dev_set_draw (‘fill’)
    Pin := 1
    dev_display_profile_points ([RowEdgeFirst1,RowEdgeSecond1], [ColumnEdgeFirst1,ColumnEdgeSecond1], Row1, Col1, Phi1, Length1, Length2)
    for I := 0 to |ColumnEdgeFirst1| - 1 by 1
    disp_message (WindowHandle, ‘size:’ + IntraDistance1[I] ′ . 2 f ′ + ′ s c o r e : ′ + F u z z y S c o r e 1 [ I ] '.2f' + ' score:' + FuzzyScore1[I] .2f+score:+FuzzyScore1[I]‘.2f’, ‘image’, RowEdgeSecond1[I], ColumnEdgeSecond1[I] + 10, ‘yellow’, ‘false’)
    MRow := RowEdgeSecond1[I] - 5
    MCol := ColumnEdgeSecond1[I] - 20
    dev_set_color (‘white’)
    gen_circle (Circle, MRow, MCol, 10)
    dev_display (Circle)
    get_string_extents (WindowHandle, Pin, Ascent, Descent, SWidth, SHeight)
    disp_message (WindowHandle, Pin, ‘window’, MRow - SHeight / 2, MCol - SWidth / 2, ‘black’, ‘false’)
    Pin := Pin + 1
    endfor
    dev_display_profile_points ([RowEdgeFirst2,RowEdgeSecond2], [ColumnEdgeFirst2,ColumnEdgeSecond2], Row2, Col2, Phi2, Length1, Length2)
    for I := 0 to |ColumnEdgeFirst2| - 1 by 1
    dev_set_color (‘yellow’)
    disp_message (WindowHandle, ‘size:’ + IntraDistance2[I] ′ . 2 f ′ + ′ s c o r e : ′ + F u z z y S c o r e 2 [ I ] '.2f' + ' score:' + FuzzyScore2[I] .2f+score:+FuzzyScore2[I]‘.2f’, ‘image’, RowEdgeFirst2[I], ColumnEdgeFirst2[I] + 10, ‘yellow’, ‘false’)
    MRow := RowEdgeFirst2[I] - 5
    MCol := ColumnEdgeFirst2[I] - 20
    dev_set_color (‘white’)
    gen_circle (Circle, MRow, MCol, 10)
    dev_display (Circle)
    get_string_extents (WindowHandle, Pin, Ascent, Descent, SWidth, SHeight)
    disp_message (WindowHandle, Pin, ‘window’, MRow - SHeight / 2, MCol - SWidth / 2, ‘black’, ‘false’)
    Pin := Pin + 1
    endfor
    stop ()
    close_measure (MeasureHandle1)
    close_measure (MeasureHandle2)

在这里插入图片描述

程序运行结果如下

在这里插入图片描述
这段代码主要实现以下功能:

图像读取:使用read_image函数读取名为“board-6”的图像文件。

窗口创建:使用dev_open_window函数打开一个窗口,用于显示图像和后续的测量结果。

模糊测量:定义了两个测量区域,每个区域都使用gen_measure_rectangle2函数生成,并且设置了测量区域的旋转角度、长度和宽度。

模糊函数定义:使用create_funct_1d_pairs创建一个模糊函数,用于选择芯片引脚边缘对的大小,大小大约为11像素。

设置模糊测量规范:使用set_fuzzy_measure_norm_pair函数为两个测量区域设置模糊测量规范,使用之前定义的模糊函数。

执行模糊测量:使用fuzzy_measure_pairs函数对图像进行模糊测量,寻找符合模糊函数定义的边缘对。

可视化:使用dev_display和dev_display_measure_object函数显示图像和测量区域,使用dev_display_profile_points显示边缘对。

信息显示:使用disp_message函数在图像上显示每个边缘对的大小和模糊分数,使用gen_circle和dev_display显示圆圈标记,并显示引脚编号。

程序结束:使用stop和close_measure函数结束程序并关闭测量区域。

这段代码主要解决的问题是:在图像中识别并测量芯片引脚的边缘对,通过模糊逻辑来处理可能存在的不确定性和变化,从而提高测量的准确性和鲁棒性。这在机器视觉领域中,特别是在半导体或电子行业,对于自动化检测和质量控制非常重要。

  • 16
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_z3405211980

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值