﻿ 基于机器视觉的微型摆轮质量检测系统
 计算机系统应用  2020, Vol. 29 Issue (1): 73-79 PDF

1. 杭州师范大学 杭州国际服务工程学院, 杭州 311121;
2. 杭州手表有限公司, 杭州 310015

Micro Balance Wheel Quality Inspection System Based on Machine Vision
WEI Dong-Liang1, ZHOU Di-Bin1, ZHANG Jia-Yu1, MA Jian-Feng2
1. Hangzhou Institute of Service Engineering, Hangzhou Normal University, Hangzhou 311121, China;
2. Hangzhou Watch Co. Ltd., Hangzhou 310015, China
Foundation item: General Program of National Natural Science Foundation of China (11772301); Natural Science Foundation of Zhejiang Province (LY17F020016); Second Round of Teaching Case Database Construction for Graduate Courses of Hangzhou Normal University
Abstract: Balance wheel is commonly used in precision instruments. Its flatness plays an important role in the precision and accuracy of the whole instrument. Traditionally inspection of balance wheel is done manually. This study raises a flatness inspection system for balance wheel based on machine vision. First, the image of balance wheel is calibrated. Second, its sub-pixel edge information is extracted and boundary information is accurately calculated through projection mapping. The system supports continuous sampling and calculation and takes the dynamic range of the edge of the balance wheel as acceptability criteria of parts. The result of the test shows that this method has a satisfied real-time property and high accuracy, so it can meet industrial inspection needs.
Key words: balance wheel detection     sub-pixel edges     straight line detection

 图 1 摆轮

1 项目总体设计 1.1 光学方案设计

 图 2 摆轮工作台

1.2 算法框架

 图 3 流程框架

2 算法分析 2.1 图像采集和预处理

 图 4 常见阈值方法分割效果

2.2 Canny边缘检测

 图 5 Canny边缘检测效果

Canny算法能够满足项目需要, 且使得后面霍夫直线检测时取得比较好的性能, 所以选择Canny算子.

2.3 图像矫正

 图 6 图像矫正效果

2.3.1 图像矫正流程

1)基于Canny检测后的图像使用霍夫变换方法检测图像中的直线. 霍夫变换本身比较耗时, 但根据摆轮图像的特点只需要检测出2到3条比较长的水平直线, 其余水平直线和垂直直线则全部忽略掉. 当设置直线检测阈值为500像素点时即可达成上述目标. 这样能大大提高霍夫算法的效率.

2)对于每条检测出的直线, 获取其倾角θ, 如图7所示.

$\theta \in \left[ {\dfrac{\pi }{2}, \dfrac{{3\pi }}{4}} \right] \cup \left[ {\dfrac{{5\pi }}{4}, \dfrac{{3\pi }}{2}} \right]$ 时认为是水平直线倾斜后的结果, 属于其他区间时忽略掉. 统计这些直线的倾角并取其平均值作为最终的图像倾角α.

 图 7 图像坐标系

3)旋转图像至水平位置. 设β为图像需要旋转的角度, 则有:

 $\beta = \alpha - \dfrac{\pi }{2}$ (1)

2.4 ROI亚像素计算

2.4.1 一次函数模型

 $S = {S_M} + {S_N}$ (2)
 $F(i,j) = \dfrac{{N \cdot {S_N} + M \cdot {S_M}}}{S}$ (3)
 图 8 一次函数模型

 图 9 5×3模板

 $L2 = \displaystyle\int_{ - \tfrac{{3w}}{2}}^{ - \tfrac{w}{2}} \left(kx + b + \dfrac{5}{2} w\right){\rm d}x = \left(\dfrac{5}{2} - k\right){w^2} + bw$ (4)
 $M2 = \displaystyle\int_{ - \tfrac{w}{2}}^{\tfrac{w}{2}} \left(kx + b + \dfrac{{5w}}{2} \right){\rm d}x = \dfrac{5}{2}{w^2} + bw$ (5)
 ${{R}}2 = \displaystyle\int_{\tfrac{w}{2}}^{\tfrac{{3w}}{2}} \left(kx + b + \dfrac{{5w}}{2}\right){\rm d}x = \left(\dfrac{5}{2} + k\right){w^2} + bw$ (6)

 ${T_l} = \sum\limits_{J = j - 2}^{j + 2} {F(i - 1, J)}$ (7)

 ${T_l} = 5N + \dfrac{{M - N}}{S}\sum\limits_{j - 2}^{j + 2} {{S_M}}$

 ${T_l} = 5N + \dfrac{{M - N}}{S}L2$ (8)

 ${T_m} = \sum\limits_{J = j - 2}^{j + 2} {F(i, J)} = 5N + \dfrac{{M - N}}{S}M2$ (9)
 ${T_r} = \sum\limits_{J = j - 2}^{j + 2} {F(i + 1, J)} = 5N + \dfrac{{M - N}}{S}R2$ (10)
2.4.2 二次函数模型

 图 10 二次函数模型

 $L2 \!=\! \int_{ - \tfrac{{3w}}{2}}^{ - \tfrac{w}{2}} \left(a{x^2} \!+\! bx\! +\! c\! +\! \dfrac{{5w}}{2} \right){\rm d}x\!=\! \dfrac{{13}}{{12}}a{w^3} + \left(\dfrac{5}{2} - b\right){w^2} + cw$ (11)
 $M2 = \displaystyle\int_{ - \tfrac{w}{2}}^{\tfrac{w}{2}} \left(a{x^2} + bx + c + \dfrac{{5w}}{2} \right){\rm d}x = \dfrac{1}{{12}}a{w^3} + \dfrac{5}{2}{w^2} + cw$ (12)
 ${{R}}2 \!= \! \displaystyle\int_{\tfrac{w}{2}}^{\tfrac{{3w}}{2}} \left(a{x^2} \!+\! bx \!+\! c \!+ \!\dfrac{{5w}}{2} \right){\rm d}x \!=\! \dfrac{{13}}{{12}}a{w^3} + \left(b + \dfrac{5}{2}\right){w^2} + cw$ (13)

 $a = \dfrac{{{T_l} + {T_r} - 2T{}_m}}{{2(M - N)}}$ (14)
 $b = \dfrac{{{T_r} - T_l}}{{2(M - N)}}$ (15)
 $c = \dfrac{{2{T_m} - 5(M + N)}}{{2(M - N)}} - \dfrac{1}{{12}}a$ (16)

 图 11 图像强度

 $M = \dfrac{1}{2}\left[ {F(i,j + 2) + F(i + \Delta x,j + 2)} \right]$ (17)
 $N = \dfrac{1}{2}\left[ {F(i - \Delta x,j - 2) + F(i,j - 2)} \right]$ (18)

2.5 计算边缘直线

 图 12 ROI摆轮边缘直线

 $Hi = \sum\limits_{j = 0}^{\Delta x} {f(i,j)}$ (19)

 图 13 边缘直线

 $Vi = \sum\limits_{i = 0}^{\Delta y} {f(i, j)}$ (20)

2.6 计算极差

3 结果分析

 $1{\text{像素}} = 0.5{\text{丝}}$ (21)
 图 14 摆轮厚度计算

 $x = \left\{ \begin{array}{l} \left[ x \right],x < \left[ x \right] + 0.5\\ \left[ x \right] + 0.5,x \ge \left[ x \right] + 0.5 \end{array} \right.$ (22)

 图 15 系统工作实况

 $\left\{ \begin{array}{l} 4{\text{像素}} \le 2{\text{丝}} \Rightarrow 0.5{\text{像素}} \le 0.25{\text{丝}}\\ 4.5{\text{像素}} > 2{\text{丝}} \Rightarrow 0.5{\text{像素}} > 0.22{\text{丝}} \end{array} \right.$ (23)

4 结语

 [1] 吴鹏, 徐洪玲, 宋文龙, 等. 基于非线性四阶图像插值的亚像素边缘检测算法. 哈尔滨工程大学学报, 2015, 36(2): 243-247. DOI:10.3969/j.issn.1006-7043.201312057 [2] Trujillo-Pino A, Krissian K, Alemán-Flores M, et al. Accurate subpixel edge location based on partial area effect. Image and Vision Computing, 2013, 31(1): 72-90. DOI:10.1016/j.imavis.2012.10.005 [3] 凌程, 耿修瑞, 杨炜暾, 等. 一种改进的基于奇异值分解的亚像素级图像配准算法. 中国科学院大学学报, 2019, 36(1): 101-108. DOI:10.7523/j.issn.2095-6134.2019.01.014 [4] 贺忠海, 王宝光, 廖怡白, 等. 利用曲线拟合方法的亚像素提取算法. 仪器仪表学报, 2003, 24(2): 195-197. DOI:10.3321/j.issn:0254-3087.2003.02.023 [5] 赵爱明. 基于二次曲线拟合的图像亚像素边缘定位算法. 哈尔滨理工大学学报, 2006, 11(3): 68-70. DOI:10.3969/j.issn.1007-2683.2006.03.022 [6] 史成淼. 基于数字图像的亚像素边缘定位的研究[硕士学位论文]. 长春: 吉林大学, 2008. [7] Devernay F. A non-maxima suppression method for edge detection with sub-pixel accuracy. INRIA, 1995, 1-25. [8] 何东健. 数字图像处理. 3版. 西安: 西安电子科技大学出版社, 2015. 160–174. [9] 吴爽, 祝进, 王丙文, 等. 一种非直线倾斜的打印体汉字串图像矫正方法. 信息技术, 2017(10): 146-149, 159. DOI:10.13274/j.cnki.hdzj.2017.10.035 [10] 但斌斌, 梅文浩, 伍世虔, 等. 畸变车牌定位与矫正方法研究. 制造业自动化, 2019, 41(3): 7-11. DOI:10.3969/j.issn.1009-0134.2019.03.003 [11] 袁冬冬, 应俊, 解利军, 等. 基于机器视觉的轴承防尘盖检测算法. 计算机系统应用, 2019, 28(1): 212-215. DOI:10.15888/j.cnki.csa.006708