-
WANG[4]和DING[5]等人分别提出了基于特征点匹配的模板匹配方法。这两种方法主要适用于图像整体特征的准确匹配,如人脸识别等领域,区别是采用了不同的统计方式剔除错误的特征点,具有较好的鲁棒性,识别成功率较高; 但是运用在精度较高的PCB中静态Mark圆识别,由此产生的Mark圆精度问题无法得到有效保证。其次Hough变换方式受计算机本身配置影响较高,且即使不断优化也无法达到或超越曲线拟合的计算速度[6],本身不适用于大批量工业化生产PCB中Mark圆检测。本文中的曲线拟合检测方法是通过寻找图像Mark圆的边缘,通过一系列的边缘像素点和圆拟合方程计算得到最接近实际的Mark圆,基本不受图像缩放、平移、旋转的影响,同时计算速度较快、精度较高,且对电脑配置要求不高,适用于大批量工业化生产。
-
圆是一种特殊的二元二次方程,故可用数学形式表现,其方程一般形式为:
$ {x^2} - 2{a_1}x + {y^2} - 2{a_2}y + {a_3} = 0 $
(1) 式中, (a1,a2)为圆心,r为半径,$ r = \sqrt {a_1^2 + a_2^2 - {a_3}} $。
确定了圆的圆心(a1,a2)和半径r,就可以得到唯一确定圆,在圆曲线拟合中,已知圆曲线上一系列测点zi(xi,yi)(i=1, 2, 3…m),该点对应的圆曲线拟合点为z*i(xi*,yi*),存在以下拟合准则:
$ \begin{array}{l} \rho = \min \sum\limits_{i = 1}^m {[{{(x_i^* - {x_i})}^2} + } \\ {(y_i^* - {y_i})^2}], (i = 1, 2, 3, \cdots m) \end{array} $
(2) 理想情况下,当距离总和ρ=0时,圆曲线拟合点与圆上测点重合,即曲线拟合圆与真实圆完全重合,故实际拟合过程中当ρ取值越小,拟合圆越接近真实圆。该方法对于图像检测圆拟合同样适用。
-
该方法对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]只是单一的检测像素点的灰度等级,对边缘的识别方式是逐一跟踪可能存在的边缘像素点,其检测结果从微观上看是一个不规则的近似圆或者圆弧的像素点集合,因此该集合的中心,难以准确确定,需要进一步对检测信息进行拟合,再进行圆孔中心检测。文中检测圆的拟合算法是依据圆曲线拟合的思想,将轮廓上点到拟合圆心的距离的平方进行求和,根据最小二乘准则,当ρ最小时,得到的对应点集合即为需要的圆孔轮廓区域。拟合函数见下式:
$ \rho = \sum\limits_{i = 0}^n {{{[\sqrt {{{({x_i} - a)}^2} + {{({y_i} - b)}^2}} - r]}^2}} $
(3) 式中,ρ为距离总和(单位: pixel); (a,b)为圆心点的坐标; r为圆的半径(单位: pixel); (xi,yi)为圆孔轮廓上点的坐标; n为轮廓上像素点的总数量。
-
在实际情况中,由于自身及环境各种因素的综合影响,利用HALCON算法生成的拟合圆信息不唯一,则产生的拟合圆心坐标也不唯一,因此会对Mark圆的位置识别精度造成一定的影响,不能满足实际需要,根据最小二乘法和迭代法圆曲线拟合的原则[21]。本文中在HALCON拟合圆算法的基础上,添加了优化拟合圆坐标的算法,达到了较高的识别精度。
其优化拟合过程是:设平面圆的标准方程式如下:
$ {(x - a)^2} + {(y - b)^2} = {r^2} $
(4) 式中, a和b分别为圆心坐标,r为圆半径。首先记录原始拟合圆产生的a, b, r数据,根据平均值法分别求出均值a0, b0, r0,以该值生成标准圆,然后利用间接平差的原理,令:
$ \left\{ \begin{array}{l} \hat a = {a^0} + \delta \times a\\ \hat b = {b^0} + \delta \times b\\ \hat r = {r^0} + \delta \times r \end{array} \right. $
(5) 式中, $ {\hat a} $为待求参量,a0为待求参量近似值,δ为待求参量的改正补偿系数。
设优化拟合前(原始拟合生成了n个拟合半径)和拟合后(总会有且只有1个)半径差值为di,则:
$ d_i^2 = {[\sqrt {{{({x_i} - a)}^2} + {{({y_i} - b)}^2}} - r]^2} $
(6) 依据最小二乘准则,应使得$ \sum {{{({d_i} - r)}^2}} $取最小,即: $ \min [\sum {{{({d_i} - r)}^2}} ]$。设检测生成的原始拟合圆个数为n(n≥1),并将di作为观测对象,则$ {{\hat d}_i} $的平差值方程为:
$ {{\hat d}_i} = {d_i} + {\varepsilon _i} = \sqrt {{{({x_i} - \hat a)}^2} + {{({y_i} - \hat b)}^2}} - \hat r $
(7) 将上式按照泰勒公式展开得:
$ {\varepsilon _i} = - \frac{{\Delta x_i^0}}{{s_i^0}} \times \delta \times a - \frac{{\Delta y_i^0}}{{s_i^0}} \times \delta \times b - \delta \times r - {l_i} $
(8) 式中, $ s_i^0 = \sqrt {{{({x_i} - {a^0})}^2} + {{({y_i} - {b^0})}^2}} $,Δxi0=xi-a0,Δyi0=yi-b0,li=r0-si0。
虽然原始拟合圆心坐标(a,b)不精确,但误差较小。这样便可以将圆心计算范围限制在(a,b)附近,大大减少了无效计算,为了避免拟合过程出现精度不高的问题,引入迭代法,迭代时,为了提高收敛速度,设置迭代终止条件为:
$ \delta = \left| {\frac{{{X_n} - {X_{n - 1}}}}{{{X_n}}}} \right| \le 1 \times {10^{ - 5}} $
(9) 式中, X代表a,b,r。
采用该优化算法后,得到一个以a,b,r数据重绘的拟合圆,同时输出重绘后的坐标,该优化拟合圆更接近实际圆,从而提高检测精度。
-
为验证优化算法与原始拟合算法的位置精度,特制作一张带有标准圆及圆心的计算机辅助设计(computer aided design, CAD)样板图,并转化为图片格式,画图软件显示圆心坐标为(586, 372),如图 3所示。为方便分析对比,将图像检测程序写入到同一个程序界面,其检测结果如图 4所示。图中左侧显示区域表示直接利用HALCON算法拟合的圆,用“红色圆”显示,输出圆心信息显示为“检测圆信息”; 右侧显示区域表示优化拟合计算之后拟合的圆,用“绿色圆”显示,输出圆心信息为“拟合圆信息”。
表 1为优化前后圆心检测数据对比。可以发现,优化处理前拟合出来的圆心坐标与标准坐标位置偏差较大,最小偏差0.255pixel,最大偏差3.143pixel; 经过优化拟合之后输出的圆心坐标与标准坐标偏差较小,精度不大于0.3pixel,表明检测的精度得到提高。一方面,通过限制ROI区域的检测范围,另一方面,重新拟合迭代数据计算量增加不多,且和图片显示分属不同的线程,因此在软件界面显示优化前后处理时间没有明显变化。
Table 1. Data comparison of circle center detection before and after optimization
detection
circle 1detection
circle 2detection
circle 3detection
circle 4detection
circle 5detection
circle 6fitting
circlestandard
coordinatescoordinate 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 -
为了验证本方法的实用性,特选用两种常见的铝基板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圆,并适时输出坐标信息,完全能满足实际加工需要。
Table 2. Statistics of batch detection
model test
number
(group)succeed
(group)fail
(group)success
rate/
%range of
deviation/
pixelaluminum substrate
PCB of XCZ-86101815100 97 3 97 0.08~0.24 FR-4 glass fiber PCB 50 49 1 98 0.18~0.30 aluminum substrate
PCB of LED80 79 1 98.75 0.12~0.26 Table 3. Statistics of detection time
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-
86101815100 4 35 44 17 0 FR-4 glass
fiber PCB50 3 11 23 13 0 aluminum
substrate
PCB of LED80 3 18 37 22 0 实际检测结果也有少量失败,产生误检的原因主要有:(1)光源强度不匹配,不同产品表面对光敏感程度不同,相机采集图像过程中需要适时调整,如图 6表示, 因光源亮度过低导致检测失败; (2)平台运动不到位,导致检测视野中缺少有效的检测部位,造成软件无法识别而误检。后期解决方法可考虑添加检测失败判定,当检测失败或产生误检时,软件报警提醒并提示进入人工检测界面,实现人工辅助检测。
基于MFC+HALCON图像识别Mark圆的检测方法
Image recognition Mark circle detection scheme based on MFC+HALCON technology
-
摘要: 为了解决传统印刷电路板(PCB)中定位标识圆(Mark圆)的检测精度和准确率不高的问题,采用曲线拟合及优化拟合算法改善Mark圆检测方式并进行了理论分析,通过使用微软基础类库嵌入标准的机器视觉算法包HALCON的方法搭建检测平台并进行了实验验证。结果表明,该方法检测成功率可达97%,检测精度在0.3pixel以下,检测时间小于100ms,解决了传统PCB中Mark圆检测精度不高的问题,同时大量测试数据显示,在图像发生平移、旋转、缩放的环境下,仍能保证较好的检测效果。该研究对实际PCB生产检测具有一定借鉴意义。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.
-
Figure 5. Comparison of the detection effects of two common aluminum substrate PCBs under different light sources
a—aluminum substrate of XCZ-86101815 (dark light source) b—aluminum substrate of XCZ-86101815 (light source) c—aluminum substrate of LED(dark light source) d—aluminum substrate of LED(light source)
Table 1. Data comparison of circle center detection before and after optimization
detection
circle 1detection
circle 2detection
circle 3detection
circle 4detection
circle 5detection
circle 6fitting
circlestandard
coordinatescoordinate 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 2. Statistics of batch detection
model test
number
(group)succeed
(group)fail
(group)success
rate/
%range of
deviation/
pixelaluminum substrate
PCB of XCZ-86101815100 97 3 97 0.08~0.24 FR-4 glass fiber PCB 50 49 1 98 0.18~0.30 aluminum substrate
PCB of LED80 79 1 98.75 0.12~0.26 Table 3. Statistics of detection time
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-
86101815100 4 35 44 17 0 FR-4 glass
fiber PCB50 3 11 23 13 0 aluminum
substrate
PCB of LED80 3 18 37 22 0 -
[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).