基于YOLOv5s的精密视觉检测系统快速调焦方法
2025-08-13胡新宇刘锡阳张骏巍严爽李云翔叶旭辉
Fast Focusing Method for Precision Vision Detection System Based on YOLOv5s
HU Xinyu LIU Xiyang*ZHANG Junwei YAN Shuang LI Yunxiang YE Xuhui School of Mechanical Engineering,Hubei University of Technology,Wuhan,430068
Abstract: During measurement,the visual inspection system was influenced by factors such as production accuracy and assembly errors, leading to defocused and blurred images. Consequently,a rapid focusing method for the precision visual inspection system was developed based on YOLOv5s. This method employed a combination of coarse and fine focusing strategies. Initially,the trained YOLOv5s models were utilized to search for clear imaging depth ranges with an accuracy of 97.6% , completed the coarse focusing processes within 900ms . Subsequently,the clarity evaluation function and an improved search algorithm were applied for precise focusing, swiftly identified the optimal imaging plane within the depth range. Experimental results indicate that within a defocus range of ±4 mm ,the focusing accuracy reaches 0.04mm ,with an average time not exceeding 1600ms ,which reaches a 47.6% reduction compared to existing methods. This method offers rapid speed, high accuracy, and strong adaptability,making it ideally suited for online precision measurements in visual inspection systems.
Key words: autofocus; visual inspection; interval search; clarity evaluation function
0 引言
在光学系统中,正焦位置是指物体在图像平面上形成最清晰焦点的位置[1]。当物体与其对应的像满足共轭关系时,成像系统就能够在正焦位置上实现最佳的成像质量。当焦点移动到物体的前侧或后侧时,光线未能在图像平面上正确定位,系统的成像会变得模糊。
视觉检测技术在工业制造、智能交通、医疗诊断等领域获得了广泛应用[3]。图像处理是视觉检测的核心组成部分,高质量的清晰图像能够降低图像处理中特征提取的难度,从而提高系统处理速度4,因此研究视觉系统的自动调焦技术有着重要价值。
自动调焦技术的演进历程经历了多个阶段。从最开始的手动调焦发展到被动式和主动式的自动调焦,随着数字图像处理技术的飞速发展,基于图像处理的自动调焦技术成为研究热点[5]。国内对基于图像处理的自动调焦技术进行了大量研究。潘宏亮等[6提出了改进Sobel算子图像清晰度评价函数与粗细调焦结合的变步长两段式快速搜索自动调焦方法,提高了评价函数的准确度,并加快了搜索策略的速度。罗其俊等提出了一种基于圆边响应曲线的离焦估计新算法,实现了调焦参数的标定和望远物镜的自动调焦。上述研究内容集中在改进图像清晰度评价函数和聚焦策略方面,依赖于手动设计的规则和算法,缺乏对复杂数据和场景的学习能力。
本文提出一种基于YOLOv5s的视觉系统自动调焦方法,分两步实现焦平面位置的高精度快速检测。……
