With the rapid development of the electronic industry,the demand for printed circuit boards by electronic manufacturers has also increased.The PCB manufacturing process is complex,and abnormal factors in each process can easily lead to various defects on the PCB surface.The manual visual inspection method for PCB defects is not suitable for standardization promotion due to its strong subjectivity.In-circuit tester for detecting PCB defects carries the risk of damaging the surface structure of the PCB.Although automatic optical inspection equipment has high defect detection accuracy,the traditional image processing algorithms carried by the equipment have certain limitations in terms of usage conditions.In recent years,deep learning object detection algorithms have shown strong defect detection performance in the field of industrial defect detection.Therefore,conducting research on PCB surface defect detection algorithms based on deep learning has great practical application value.In this thesis,the PCB surface defect detection algorithm is studied on the basis of YOLOv5 s deep learning single-stage object detection network,and the main research content is as follows:(1)The PCB image is preprocessed by camera calibration,image denoising,image stitching and image foreground extraction.The PCB distorted image is corrected by Zhang Zhengyou calibration method;image noise reduction using a variety of spatial filtering algorithms to remove PCB image salt and pepper noise;RANSAC,perspective transform and pixel weighted fusion in overlapping area are used to meet the requirements of PCB panoramic image mosaic;in image foreground extraction,Otsu method and perspective transform are used to correct the skewed PCB image,the problems of distortion,noise,stitching and redundant background of PCB original image are solved by the above steps.(2)A YOLOv5 s defect detection algorithm based on multi-scale feature fusion is constructed.In order to solve the problem of low defect detection accuracy of conventional resolution PCB images,firstly,the C3 False of YOLOv5 s backbone network and the nearest neighbor difference upsampling of the head are replaced by C3 HB and CARAFE structures,so as to enhance the feature extraction ability of the backbone and the head.Then,the H2 small object detection layer and CBAM attention mechanism are added to the head of YOLOv5 s to enhance the recognition ability of small objects in the head.The defect detection m AP of the improved algorithm on the conventional resolution PCB defect image dataset is 98.7%,which is 2.2% higher than that of the original YOLOv5 s defect detection m AP.Experimental results show that the YOLOv5 s defect detection algorithm based on multi-scale feature fusion can improve the accuracy of PCB defect detection.(3)A YOLOv5 s defect detection algorithm based on slice inference is designed.In order to meet the high-resolution PCB master image defect detection requirements,the YOLOv5 s network model using slice inference cuts a single high-resolution PCB image into multiple sub-graphs for batch detection,and single input image single inference is changed to single input image slice inference,and then the NMS algorithm is used to remove the subgraph duplicate detection information and stitch out the original image defect detection results,and then GSConv convolution and two scale detection structure are used to reduce the total inference time of the algorithm by using a lightweight YOLOv5 s network.The improved algorithm has a defect detection m AP of 92.9% on the high-resolution PCB defect image dataset,and the algorithm can detect defects in PCB master images with a resolution of up to 12224 pixels x 9856 pixels.Experimental results show that the slice inference strategy can improve the algorithm to complete the highresolution PCB image defect detection without increasing the spatial complexity of the network model.Finally,a simple PCB defect detection application is developed with the help of QT Designer and Py QT5 tools,which verifies the feasibility of the actual deployment of two improved YOLOv5 s defect detection algorithms,and provides an idea for using deep learning to detect PCB surface defect. |