Advanced Search

ISSN1001-3806 CN51-1125/TN Map

Volume 44 Issue 3
Jul.  2020
Article Contents
Turn off MathJax

Citation:

Image recognition Mark circle detection scheme based on MFC+HALCON technology

  • Corresponding author: OUYANG Basheng, bsouyang@163.com
  • Received Date: 2019-07-15
    Accepted Date: 2019-10-26
  • In order to solve the problem of low detection accuracy of Mark circle in traditional printed circuit board (PCB), the curve fitting and optimized fitting algorithm were used to improve the Mark circle detection mode, and the theoretical analysis was carried out. The test platform was built by using microsoft foundation classes (MFC) to embed the standard machine vision algorithm package HALCON for experimental verification. The results showes that the success rate of the method was 97%, the detection accuracy was less than 0.3pixel, and the detection time was less than 100ms. It solved the problem of low accuracy of Mark circle in traditional PCB. At the same time, a large number of test data showed that it could still ensure a good detection effect in the environment where the image was panned, rotated, and zoomed. This research has certain reference to the actual PCB production detection.
  • 加载中
  • [1]

    QIAO N Sh, YE Y T, MO Ch H, et al. Method for the detection of concentric circles of photoelectric image of circular hole in printed circuit board[J]. Acta Optica Sninica, 2010, 30(1):75-78(in Chin-ese). doi: 10.3788/AOS20103001.0075
    [2]

    XIE G W, ZHONG Zh Zh, ZHONG Sh K, et al. Research on position-ing method of circular mark in PCB based on machine vision[J]. Computer Knowledge and Technolgy, 2013, 9(32):7340-7344(in Chinese).
    [3]

    DONG M. Object multi-mark recognition algorithm based on machine learning and image processing[J]. Computer & Digital Engineering, 2016, 44(12):2488-2492(in Chinese).
    [4]

    WANG M H, CHEN J B. A fast and robust template matching algorithm[J]. Industrial Control Computer, 2019, 32(3):45-48(in Chin-ese).
    [5]

    DING X Y, WANG T. Image template matching algorithm based on cross-check ORB and MCC[J]. Journal of Electronic Measurement and Instrument, 2019, 33(5):39-45(in Chinese).
    [6]

    BAI C B, QI Ch, SONG F M, et al. Fast detection of circular pcb mark using Hough transform[J]. Opto-Electronic Engineering, 2005, 32(9): 75-78(in Chinese).
    [7]

    XIONG G J, MA Sh Y, LIU R Zh. Fast precise positioning of circular mark in PCB inspection[J]. Computer Engineering, 2012, 38(11):211-216(in Chinese).
    [8]

    XIAO J H, XIANG X J. Design of measurement system for steel ruler end face based on Halcon[J]. Journal of Zhejiang University of Science and Technology, 2018, 30(6):488-495(in Chinese).
    [9]

    GONG P L, LV X Sh. Skills on bar code recognition based on halcon[J]. Computer and Modernization, 2013, 1(4):73-76(in Chinese).
    [10]

    LI X, JIANG M Sh. A comparison of sharpness functions based on microscopes[J]. Optical Instruments, 2018, 40(1):28-38 (in Ch-inese).
    [11]

    GAO Sh Sh, WANG Y J, JIN W Q, et al. Objective image sharpness metric based on perceptual contrast[J]. Optical Techniques, 2015, 41(5):396-399(in Chinese).
    [12]

    BRAGA-NETO U, GOUTSIAS J. Object-based image analysis using multiscale connectivity[J]. IEEE Transactions on Pattern Analysis and Machine Intelligence, 2005, 27(6):892-907. doi: 10.1109/TPAMI.2005.124
    [13]

    MA Y F. Research on image processing technology applied to infrared and lidar compound system[D]. Shanghai: Shanghai Jiao Tong University, 2012: 11-36(in Chinese).
    [14]

    ZENG J Q, WANG J, CHEN Y, et al. Multi-color-image compression and encryption by using discrete wavelet transform in Fresnel transform domain[J]. Laser Technology, 2018, 42(6): 733-738(in Chinese).
    [15]

    ZHOU Y T. Multi-sensor image fusion[C]//Proceedings of IEEE 2001 International Conference on Image Processing. New York, USA: IEEE, 2001: 846-849.
    [16]

    LI Y, QIAO B, LU Y P. Circle fitting algorithm based on clustering[J]. Computer Applications, 2013, 33(22) :206-208(in Chin-ese)
    [17]

    SONKA M, HLAVAC V, CENG R B D M. Image processing, ana-lysis and machine vision[M]. Belmont, USA:Thomson Learning, 2008: 685-686.
    [18]

    FU Z M, WANG J W, ZHANG S H, et al. Workpiece size and defect detection in metal forming based on HALCON[J]. Tool Techno-logy, 2019, 53(2):134-137 (in Chinese).
    [19]

    SHI Y L, MEI L L. Edge detection technologies research based on PCB locating hole[J]. Printed Circuit Information, 2012(11):53-57(in Chinese).
    [20]

    XU Y L, MA Y. An edge detection algorithm based on improved canny operator[J]. Journal of Fujian Computer, 2019, 35(5):5-7(in Chinese).
    [21]

    CHEN M J, FANG Y M, CHEN J. Fitting of circular curve based on least square method and iterative method[J]. Science of Surveying and Mapping, 2016, 41(1):194-197(in Chinese).
  • 加载中
通讯作者: 陈斌, bchen63@163.com
  • 1. 

    沈阳化工大学材料科学与工程学院 沈阳 110142

  1. 本站搜索
  2. 百度学术搜索
  3. 万方数据库搜索
  4. CNKI搜索

Figures(6) / Tables(3)

Article views(6520) PDF downloads(22) Cited by()

Proportional views

Image recognition Mark circle detection scheme based on MFC+HALCON technology

    Corresponding author: OUYANG Basheng, bsouyang@163.com
  • College of Mechanical Engineering, University of South China, Hengyang 421000, China

Abstract: In order to solve the problem of low detection accuracy of Mark circle in traditional printed circuit board (PCB), the curve fitting and optimized fitting algorithm were used to improve the Mark circle detection mode, and the theoretical analysis was carried out. The test platform was built by using microsoft foundation classes (MFC) to embed the standard machine vision algorithm package HALCON for experimental verification. The results showes that the success rate of the method was 97%, the detection accuracy was less than 0.3pixel, and the detection time was less than 100ms. It solved the problem of low accuracy of Mark circle in traditional PCB. At the same time, a large number of test data showed that it could still ensure a good detection effect in the environment where the image was panned, rotated, and zoomed. This research has certain reference to the actual PCB production detection.

引言
  • 随着中国制造2025的提出,各行业不断蓬勃发展,电子行业印刷电路板(printed circuit board,PCB)上的元器件同样朝着小型化、精密化、集成化方向发展,对PCB的加工精度要求也越来越高。PCB上的定位标识圆(以下简称Mark圆)及圆心坐标是其加工的定位标识,又称为基准点,在加工前需要精确识别PCB上的Mark圆及圆心坐标,以进行准确的加工定位[1-3]。目前圆的常见检测方法包括:模板匹配、霍夫(Hough)变换和曲线拟合等。

    对模板匹配法的研究中,WANG[4]和DING[5]等人提出基于特征点匹配的模板匹配方法。前者是采用oriented fast and rotated brief(ORB)算法、暴风(brute force, BF)算法结合运动统计模型(grid-based motion statistics, GMS)算法,后者利用ORB算法和最大相关熵准则(maximum comentropy criterion, MCC)交叉检验的方式进行模板匹配。虽然这两种方法相对于传统模板匹配方式有了较大优化改进,但是当PCB中的Mark圆变化明显或者背景干扰大时,检测精度有限。此外,采用Hough变换方法进行Mark圆检测,精度高、抗噪能力强,但由于采用3维累加器,且每维数据长度很大,存在计算量大、占用内存多等缺陷。同时此方法若要继续提高精度,则累加器每维数据长度成倍增加,运算量呈指数三次方上升[6-7],难以满足PCB快速生产加工的需要。

    作者旨在改善传统的PCB中Mark圆识别精度不高的问题,使用计算机计算速度较快的曲线拟合方式进行Mark圆检测,同时改进标准的机器视觉算法包HALCON中圆拟合算子,提高Mark圆拟合精度。且能在检测图像发生旋转、平移、缩放等情况下使用,鲁棒性好。使用微软基础类库(microsoft foundation classes,MFC)嵌入HALCON的方式搭建检测平台,该平台可继承HALCON的检测功能,同时可根据不同种类Mark圆保存或加载与之匹配的检测配置,方便、快捷,可满足实际PCB加工中多样的检测需求。

1.   曲线拟合检测Mark圆
  • WANG[4]和DING[5]等人分别提出了基于特征点匹配的模板匹配方法。这两种方法主要适用于图像整体特征的准确匹配,如人脸识别等领域,区别是采用了不同的统计方式剔除错误的特征点,具有较好的鲁棒性,识别成功率较高; 但是运用在精度较高的PCB中静态Mark圆识别,由此产生的Mark圆精度问题无法得到有效保证。其次Hough变换方式受计算机本身配置影响较高,且即使不断优化也无法达到或超越曲线拟合的计算速度[6],本身不适用于大批量工业化生产PCB中Mark圆检测。本文中的曲线拟合检测方法是通过寻找图像Mark圆的边缘,通过一系列的边缘像素点和圆拟合方程计算得到最接近实际的Mark圆,基本不受图像缩放、平移、旋转的影响,同时计算速度较快、精度较高,且对电脑配置要求不高,适用于大批量工业化生产。

  • 圆是一种特殊的二元二次方程,故可用数学形式表现,其方程一般形式为:

    式中, (a1a2)为圆心,r为半径,$ r = \sqrt {a_1^2 + a_2^2 - {a_3}} $。

    确定了圆的圆心(a1a2)和半径r,就可以得到唯一确定圆,在圆曲线拟合中,已知圆曲线上一系列测点zi(xiyi)(i=1, 2, 3…m),该点对应的圆曲线拟合点为z*i(xi*yi*),存在以下拟合准则:

    理想情况下,当距离总和ρ=0时,圆曲线拟合点与圆上测点重合,即曲线拟合圆与真实圆完全重合,故实际拟合过程中当ρ取值越小,拟合圆越接近真实圆。该方法对于图像检测圆拟合同样适用。

2.   检测方案设计及图像预处理
  • HALCON是德国MVtec公司研发的一套完善的标准机器视觉算法包,包含一千多个图像处理算子,能适用于各种操作系统,同时具有百余种工业相机和图像采集卡的接口,拥有广泛的机器视觉集成开发环境,但是HALCON单独作为检测软件使用局限性较大,一般需要把HALCON中的视觉算法库嵌入到实际检测软件中使用,才能满足多样的检测功能。本文中将HALCON嵌入MFC中,进行Mark圆识别检测和优化拟合,以满足PCB的高精度加工要求。

  • 首先制作一个包含HALCON[8-9]函数库信息的属性项目表,该属性表中添加包含HALCON算子的库目录、包含目录、附加依赖项等信息,然后在MFC的开发环境(操作系统:Windows 7×86,内存4g)中导入该属性表,即可正常调用HALCON函数库的算子, 然后通过激光加工平台上的电荷耦合器件(charge coupled device,CCD)相机拍摄图像信息,再传递给本文中设计的含HALCON函数库的MFC模块对图像进行检测和处理,得到所需的Mark圆相关信息后再和激光控制平台实时通讯,从而实现激光加工前的基准精确定位。检测流程图如图 1所示。

    Figure 1.  Flow chart of detection

  • 图像处理与检测首先要求图像清晰,图像模糊对检测的效果和精度影响很大。通过查阅清晰度评价相关文献得知,本方法中Mark圆的检测属于灰度图像边缘检测,其主要影响图像清晰度[10-12]的噪声是椒盐噪声,故文中MFC模块直接调用HALCON的Brenner函数对图像清晰度进行评价。当采集到清晰图像后,文中MFC模块调用HALCON算子来完成图像采集和预处理[13-15],如read-image算子和get-image-size算子组合获取图像及其尺寸信息,rgb1-to-gray算子将RGB图像转化为灰度图像,draw-rectangle1算子和gen-rectangle1算子组合可人机交互选择合适的感兴趣区域(region of interest,ROI)。

3.   工件Mark圆的检测及优化拟合
  • 该方法对Mark圆的检测包括两个步骤:Mark圆的检测及原始曲线拟合、优化拟合。详细步骤如下。

  • 首先使用Robert算子进行图像边缘过滤,去除无关的噪声,使图像边缘变得更加容易识别。Robert算子过滤前后图片效果见图 2。然后利用edges_sub_pix和canny算子进行边缘检测,筛选出所有的边缘。接着利用轮廓分割算子segment_contours_xld将轮廓分割为直线或者圆。再利用分割后轮廓的全局属性cont-approx识别出所有的圆弧,利用fit_circle_contour_xld算子拟合圆弧轮廓,同时添加筛选条件。最后通过gen_circle_contour_xld算子重绘生成符合条件的拟合圆,并展示在图像中[16-18]

    Figure 2.  Comparison of images of a Mark in the ROI region before and after the filtering process with a Robert's operator

    上述边缘检测中选用的canny算子[19-20]只是单一的检测像素点的灰度等级,对边缘的识别方式是逐一跟踪可能存在的边缘像素点,其检测结果从微观上看是一个不规则的近似圆或者圆弧的像素点集合,因此该集合的中心,难以准确确定,需要进一步对检测信息进行拟合,再进行圆孔中心检测。文中检测圆的拟合算法是依据圆曲线拟合的思想,将轮廓上点到拟合圆心的距离的平方进行求和,根据最小二乘准则,当ρ最小时,得到的对应点集合即为需要的圆孔轮廓区域。拟合函数见下式:

    式中,ρ为距离总和(单位: pixel); (ab)为圆心点的坐标; r为圆的半径(单位: pixel); (xiyi)为圆孔轮廓上点的坐标; n为轮廓上像素点的总数量。

  • 在实际情况中,由于自身及环境各种因素的综合影响,利用HALCON算法生成的拟合圆信息不唯一,则产生的拟合圆心坐标也不唯一,因此会对Mark圆的位置识别精度造成一定的影响,不能满足实际需要,根据最小二乘法和迭代法圆曲线拟合的原则[21]。本文中在HALCON拟合圆算法的基础上,添加了优化拟合圆坐标的算法,达到了较高的识别精度。

    其优化拟合过程是:设平面圆的标准方程式如下:

    式中, ab分别为圆心坐标,r为圆半径。首先记录原始拟合圆产生的a, b, r数据,根据平均值法分别求出均值a0, b0, r0,以该值生成标准圆,然后利用间接平差的原理,令:

    式中, $ {\hat a} $为待求参量,a0为待求参量近似值,δ为待求参量的改正补偿系数。

    设优化拟合前(原始拟合生成了n个拟合半径)和拟合后(总会有且只有1个)半径差值为di,则:

    依据最小二乘准则,应使得$ \sum {{{({d_i} - r)}^2}} $取最小,即: $ \min [\sum {{{({d_i} - r)}^2}} ]$。设检测生成的原始拟合圆个数为n(n≥1),并将di作为观测对象,则$ {{\hat d}_i} $的平差值方程为:

    将上式按照泰勒公式展开得:

    式中, $ s_i^0 = \sqrt {{{({x_i} - {a^0})}^2} + {{({y_i} - {b^0})}^2}} $,Δxi0=xia0,Δyi0=yib0li=r0si0

    虽然原始拟合圆心坐标(ab)不精确,但误差较小。这样便可以将圆心计算范围限制在(ab)附近,大大减少了无效计算,为了避免拟合过程出现精度不高的问题,引入迭代法,迭代时,为了提高收敛速度,设置迭代终止条件为:

    式中, X代表abr

    采用该优化算法后,得到一个以abr数据重绘的拟合圆,同时输出重绘后的坐标,该优化拟合圆更接近实际圆,从而提高检测精度。

4.   实验方法及结果分析
  • 为验证优化算法与原始拟合算法的位置精度,特制作一张带有标准圆及圆心的计算机辅助设计(computer aided design, CAD)样板图,并转化为图片格式,画图软件显示圆心坐标为(586, 372),如图 3所示。为方便分析对比,将图像检测程序写入到同一个程序界面,其检测结果如图 4所示。图中左侧显示区域表示直接利用HALCON算法拟合的圆,用“红色圆”显示,输出圆心信息显示为“检测圆信息”; 右侧显示区域表示优化拟合计算之后拟合的圆,用“绿色圆”显示,输出圆心信息为“拟合圆信息”。

    Figure 3.  Standard CAD drawing

    Figure 4.  Standard inspection chart

    表 1为优化前后圆心检测数据对比。可以发现,优化处理前拟合出来的圆心坐标与标准坐标位置偏差较大,最小偏差0.255pixel,最大偏差3.143pixel; 经过优化拟合之后输出的圆心坐标与标准坐标偏差较小,精度不大于0.3pixel,表明检测的精度得到提高。一方面,通过限制ROI区域的检测范围,另一方面,重新拟合迭代数据计算量增加不多,且和图片显示分属不同的线程,因此在软件界面显示优化前后处理时间没有明显变化。

    detection
    circle 1
    detection
    circle 2
    detection
    circle 3
    detection
    circle 4
    detection
    circle 5
    detection
    circle 6
    fitting
    circle
    standard
    coordinates
    coordinate x/pixel 585.475 585.473 588.909 586.186 585.536 585.903 586.247 586
    coordinate y/pixel 373.049 371.764 370.909 373.160 370.668 372.236 371.964 372
    center offset/pixel 1.173 0.577 3.143 1.175 1.411 0.255 0.250 0

    Table 1.  Data comparison of circle center detection before and after optimization

  • 为了验证本方法的实用性,特选用两种常见的铝基板PCB,在不同光源条件下进行测试,其产品测试效果如图 5所示。

    Figure 5.  Comparison of the detection effects of two common aluminum substrate PCBs under different light sources

    图 5可以发现,XCZ-86101815铝基板PCB拟合圆心坐标偏差范围为:暗光源下为0.23pixel~0.29pixel,亮光源下为0.11pixel~0.24pixel。LED铝基板PCB拟合圆心坐标偏差范围为:暗光源下为0.22pixel~0.27pixel,亮光源下为0.13pixel~0.22pixel。结果表明:两种铝基板拟合圆心坐标总体检测精度不大于0.3pixel,且在亮光源条件下测试效果更好。

    4.3批量实际检测统计分析

    选取100组XCZ-86101815型号铝基板PCB、50组FR-4玻纤PCB和80组LED铝基板PCB, 利用文中的MFC模块在不同环境下测试,统计检测结果情况如表 2表 3所示。结果表明:检测成功率可达97%,检测精度不大于0.3pixel,检测时间小于100ms。实际检测说明本文中开发的MFC程序模块能有效地检测并识别铝基板PCB上的Mark圆,并适时输出坐标信息,完全能满足实际加工需要。

    model test
    number
    (group)
    succeed
    (group)
    fail
    (group)
    success
    rate/
    %
    range of
    deviation/
    pixel
    aluminum substrate
    PCB of XCZ-86101815
    100 97 3 97 0.08~0.24
    FR-4 glass fiber PCB 50 49 1 98 0.18~0.30
    aluminum substrate
    PCB of LED
    80 79 1 98.75 0.12~0.26

    Table 2.  Statistics of batch detection

    model test
    number
    (group)
    number of groups in the test time range
    <25ms
    (group)
    25ms~
    50ms
    (group)
    50ms~
    75ms
    (group)
    75ms~
    100ms
    (group)
    >100ms
    (group)
    aluminum
    substrate
    PCB of XCZ-
    86101815
    100 4 35 44 17 0
    FR-4 glass
    fiber PCB
    50 3 11 23 13 0
    aluminum
    substrate
    PCB of LED
    80 3 18 37 22 0

    Table 3.  Statistics of detection time

    实际检测结果也有少量失败,产生误检的原因主要有:(1)光源强度不匹配,不同产品表面对光敏感程度不同,相机采集图像过程中需要适时调整,如图 6表示, 因光源亮度过低导致检测失败; (2)平台运动不到位,导致检测视野中缺少有效的检测部位,造成软件无法识别而误检。后期解决方法可考虑添加检测失败判定,当检测失败或产生误检时,软件报警提醒并提示进入人工检测界面,实现人工辅助检测。

    Figure 6.  Example of mistaken image

5.   结论
  • 文中通过在MFC中嵌入HALCON函数库方式搭建检测平台,开发了新型图像识别和检测工具模块,既继承了HALCON的图像检测功能,能在图像发生平移、旋转、缩放的环境下使用,同时实验测试表明, 该研究检测成功率可达97%,检测精度不大于0.3pixel,检测时间小于100ms, 能满足目前PCB生产加工行业的功能需要。其次,平台可根据不同种类Mark圆保存或加载与之匹配的检测配置,方便、快捷,对实际PCB生产或检测具有一定借鉴意义。

Reference (21)

Catalog

    /

    DownLoad:  Full-Size Img  PowerPoint
    Return
    Return