With the development of integrated circuit packaging technology, the layout of printed circuit boards has become complicated. Moreover, the traditional defect detection methods have been difficult to meet the requirements of high precision. Therefore, in order to solve the problem of low efficiency in defect detection of printed circuit boards, a defect detection method based on pseudo-inverse transform and improved YOLOv5 is proposed. Firstly, a defect image restoration model is constructed to improve image clarity. Secondly, Transformer is introduced to improve YOLOv5, and the batch normalization and network loss function are optimized. These methods improve the speed and accuracy of PCB defect detection. Experimental verification showed that the restoration speed of the image restoration model was 37.60%-42.38% higher than other methods. Compared with other models, the proposed PCB defect detection model had an average increase of 10.90% in recall and 12.87% in average detection accuracy. The average detection accuracy of six types of defects in the self-made PCB data set was over 98.52%, and the average detection accuracy was as high as 99.1%. The results demonstrate that the proposed method can enhance the quality of image processing and optimize YOLOv5 to improve the accuracy of detecting defects in printed circuit boards. This method is demonstrably more effective than existing technology, offering significant value and potential for application in industrial contexts. Its promotion could facilitate the advancement of industrial automation manufacturing.