中国机械工程 ›› 2025, Vol. 36 ›› Issue (04): 864-872.DOI: 10.3969/j.issn.1004-132X.2025.04.024

• 机械基础工程 • 上一篇    下一篇

基于YOLOv5s的精密视觉检测系统快速调焦方法

胡新宇;刘锡阳*;张骏巍;严爽;李云翔;叶旭辉   

  1. 湖北工业大学机械工程学院,武汉,430068

  • 出版日期:2025-04-25 发布日期:2025-05-22
  • 作者简介:胡新宇,男,1975年生,教授、博士研究生导师。研究方向为机器视觉检测与智能控制。E-mail:19991012@mail.hbut.edu.cn。
  • 基金资助:
    国家自然科学基金(52075152);湖北省自然科学基金(2022CFB301);湖北省重点研发计划(2022BBA0016)

Fast Focusing Method for Precision Vision Detection System Based on YOLOv5s

HU Xinyu;LIU Xiyang*;ZHANG Junwei;YAN Shuang;LI Yunxiang;YE Xuhui   

  1. School of Mechanical Engineering,Hubei University of Technology,Wuhan,430068

  • Online:2025-04-25 Published:2025-05-22

摘要: 针对视觉检测系统在测量时因受生产精度、装配误差等外界因素影响,图像存在离焦模糊的问题,提出了一种基于YOLOv5s的精密视觉检测系统快速调焦方法,该方法采用粗精结合调焦策略。首先利用训练的YOLOv5s模型搜索清晰成像的景深区间,准确率达到97.6%,900 ms内完成粗调焦过程;然后利用清晰度评价函数及改进搜索算法实现精调焦,在景深区间内快速准确地找到最佳成像平面。实验结果表明,在±4 mm的离焦区间内,调焦精度达到0.04 mm,平均用时不超过1600 ms,较现有基于图像处理的方法缩短了47.6%,具有速度快、精度高、适应性强等优点,可应用于视觉检测系统的在线精密测量。

关键词: 自动调焦, 视觉检测, 区间搜索, 清晰度评价函数

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.04 mm, with an average time not exceeding 1600 ms, 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

中图分类号: