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

上述代码是用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]′.2f′+′score:′+FuzzyScore1[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]′.2f′+′score:′+FuzzyScore2[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函数结束程序并关闭测量区域。

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

### 芯片引脚缺陷检测方法概述 芯片引脚缺陷检测可以通过图像处理技术实现,主要涉及以下几个方面:图像采集、预处理、特征提取以及分类判断。具体来说,可以利用Python中的OpenCV库完成图像的读取与处理[^1],结合形态学操作和边缘检测算法识别芯片引脚是否存在弯曲、缺失或其他形式的缺陷。 以下是基于Python的一个典型实现流程: #### 图像预处理 在实际应用中,通常需要对原始图像进行灰度化、二值化等预处理操作,以便后续更高效地提取特征。如果芯片表面存在反射现象,则可采用同轴光源照明方式减少干扰[^3]。 ```python import cv2 import numpy as np def preprocess_image(image_path): # 加载图片 image = cv2.imread(image_path) # 将彩色图转换成灰度图 gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # 使用高斯模糊去除噪声 blurred = cv2.GaussianBlur(gray, (5, 5), 0) # 阈值分割得到二值图像 _, binary = cv2.threshold(blurred, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU) return binary ``` #### 形态学操作与轮廓分析 为了突出引脚区域,在此阶段会运用到开闭运算消除小型噪点或者填补断裂线条等问题;接着通过查找外部边界来定位各个单独部件的位置信息,进一步测量其几何属性比如长度宽度比例关系等等作为判别依据之一。 ```python def detect_defects(binary_img): kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3)) # 开运算去噪 opening = cv2.morphologyEx(binary_img, cv2.MORPH_OPEN, kernel, iterations=2) # 寻找轮廓 contours, _ = cv2.findContours(opening, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) defects_count = 0 for contour in contours: area = cv2.contourArea(contour) if area < 10: # 过滤掉过小的对象 continue rect = cv2.minAreaRect(contour) box = cv2.boxPoints(rect) box = np.intp(box) aspect_ratio = max(rect[1]) / min(rect[1]) if not (1.5 <= aspect_ratio <= 4): # 判断是否为正常引脚形状 defects_count += 1 return defects_count ``` 以上代码片段展示了如何使用Python配合OpenCV执行简单的芯片引脚缺陷检测任务。当然这只是一个基础框架,针对特定应用场景可能还需要做更多优化调整工作。 ### 注意事项 - 实际项目开发过程中建议引入深度学习模型提升精度。 - 数据标注质量直接影响最终效果,请务必重视训练样本准备环节。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Happy Monkey

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

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

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

打赏作者

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

抵扣说明:

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

余额充值