Method and device for detecting and positioning surface defects of PCB (Printed Circuit Board)
By uniformizing the light of the reference image and sample image of the PCB board and correcting the pixel difference, and calculating defect detection indexes in different regions, the problems of low detection reliability and difficult to detect small defects in the prior art are solved, and high accuracy and efficient defect detection and positioning are achieved.
Patent Information
- Application Number
- CN202411590959.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-08
- Publication Date
- 2025-03-04
AI Technical Summary
The existing PCB board defect detection method based on machine vision has low detection reliability under the influence of factors such as uneven light and shift error, and it is difficult to achieve accurate detection and positioning of small defects.
By acquiring the reference image and sample images of the PCB board, performing illumination uniformization and pixel difference correction, so that the reference image and the sample image can be aligned at the pixel level, and their defect detection indicators are calculated in different areas to realize defect detection and positioning.
It significantly improves the accuracy of the detection results, reduces the risk of false alarms and missed alarms, realizes accurate positioning and efficient detection of surface defects of PCB boards, and improves detection efficiency and accuracy.
Smart Images

Figure CN119559128A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of circuit board detection, and in particular to a method and device for detecting and locating surface defects of a PCB board. Background Art
[0002] A printed circuit board (PCB) is a printed circuit board (PCB) that supports various electronic components and provides electrical connections on a specific insulating substrate. PCBs are the foundation and core component of various electronic devices, and their quality directly impacts and determines the reliability and service life of these products. During the actual PCB manufacturing process, defects are unavoidable. Defects such as short circuits, open circuits, and burrs not only affect the performance of the PCB itself but can also cause malfunctions and damage to electronic products. Therefore, accurately detecting potential PCB defects has long been a critical issue and challenge in the electronics manufacturing industry.
[0003] Traditional PCB defect detection relies primarily on manual visual inspection. While this method is straightforward and simple, it places high demands on both the professional skills and physical strength of the inspector. Furthermore, as PCBs assume increasingly complex functional requirements, the layout of their electronic components and circuits is becoming increasingly smaller and more complex, making human visual inspection increasingly inadequate to meet the demands of modern industrial production.
[0004] In recent years, with the rapid development of image processing technology and deep learning theory, machine vision-based PCB defect detection methods have emerged. These methods acquire images of PCBs and analyze and process them using image processing algorithms and deep learning models, enabling automatic defect detection and identification. However, existing machine vision-based detection methods still have some shortcomings. For example, interference factors such as uneven lighting and shift errors can severely affect imaging results, reducing the reliability of defect detection. Deep learning-based detection methods require a large amount of sample data for training, and the computational overhead of the training process is significant. This not only increases the difficulty of deployment in actual manufacturing scenarios but also limits the real-time and flexibility of the detection methods. Furthermore, existing detection methods often rely on global features for defect identification, making it difficult to accurately detect and locate even small defects on PCBs. Summary of the Invention
[0005] In view of the above-mentioned deficiencies in the prior art, the technical problem to be solved by the present invention is to provide a highly automated and highly reliable method and device for detecting and locating surface defects of PCB boards.
[0006] To solve the above technical problems, the present invention adopts a technical solution: providing a method for detecting and locating surface defects of a PCB board, comprising the following steps:
[0007] Obtain reference images and sample images of PCB boards;
[0008] Processing the light and dark distribution of the sample image to obtain a sample image with uniform illumination;
[0009] Correct the pixel difference between the sample image and the reference image so that the reference image and the sample image are aligned at the pixel level;
[0010] The reference image and the sample image are divided into regions to calculate defect detection indicators, detect and locate defects.
[0011] Furthermore, the step of obtaining a reference image and a sample image of the PCB board specifically includes: obtaining an image of a defect-free PCB board as a reference image, and obtaining an image of the PCB board to be tested as a sample image, wherein the reference image and the sample image are both planar images.
[0012] Furthermore, the step of processing the light and dark distribution of the sample image to make the illumination of the sample image uniform specifically includes the following sub-steps:
[0013] Perform two-dimensional Gaussian filtering on the original sample image to form a brightness distribution matrix;
[0014] The original sample image is processed for illumination uniformity using the brightness distribution matrix to obtain a sample image with uniform illumination.
[0015] Furthermore, the step of correcting the pixel difference between the sample image and the reference image so as to align the reference image and the sample image at the pixel level specifically includes the following sub-steps:
[0016] Slide the reference image on the sample image, calculate the corresponding cross-correlation value at each position, and obtain the normalized cross-correlation matrix;
[0017] In the cross-correlation matrix, find the position with the maximum cross-correlation value, and record it as the best matching position between the reference image and the sample image;
[0018] Calculating pixel offsets of the sample image relative to the reference image in both horizontal and vertical directions using the best matching position;
[0019] The sample image is translated based on the pixel offset so that the sample image and the reference image are aligned at the pixel level.
[0020] Furthermore, the step of calculating defect detection indicators by dividing the reference image and the sample image into regions, and detecting and locating defects specifically includes the following sub-steps:
[0021] Perform the same region division on the reference image and the sample image respectively;
[0022] Calculate the structural similarity between each region of the sample image and the corresponding region in the reference image as the defect detection index of the region;
[0023] Determine whether there is a defect in the current area based on the calculated defect detection index.
[0024] Furthermore, the step of determining whether there is a defect in the current area based on the calculated defect detection index specifically includes: setting a defect threshold, comparing the defect detection index with the defect threshold, and if the defect detection index is less than the defect threshold, determining that there is a defect in the current area; otherwise, determining that there is no defect in the current area.
[0025] Furthermore, after the step of determining whether a defect exists in the current area according to the calculated defect detection index, the following steps are further included:
[0026] The area where defects are detected is divided again, the defect detection index is calculated for each area, and it is determined whether there are defects in the current area based on the calculated regional detection index. This step is repeated until the accuracy of defect detection and positioning meets the requirements.
[0027] Furthermore, the calculation formula of the cross-correlation matrix C is as follows:
[0028]
[0029] In formula (1), T(i, j) represents the pixel value of the reference image at position (i, j), represents the average pixel value of the reference image, I(x+i,y+j) represents the pixel value of the sample image at position (x+i,y+j), It represents the average pixel value of the sample image in the sub-region with (x, y) as the starting coordinate, M represents the vertical size of the reference image, and N represents the horizontal size of the reference image.
[0030] Furthermore, the defect detection index is the structural similarity of the two-dimensional image;
[0031] The calculation formula of the structural similarity SSIM is as follows:
[0032]
[0033] In formula (2), A represents the area of the reference image where the structural similarity is currently calculated, B represents the area of the sample image where the structural similarity is currently calculated, and μ A represents the average pixel value of the reference image in area A, μ B represents the average pixel value of the sample image in area B, σ represents the covariance of the image, c1 and c2 represent two non-zero constants, σ AB represents the covariance between region A and region B, represents the variance of region A, represents the variance of region B.
[0034] To solve the above technical problems, another technical solution adopted by the present invention is to provide a device for detecting and locating surface defects of a PCB board, comprising:
[0035] An image acquisition module is used to acquire a reference image and a sample image of a PCB board;
[0036] An image processing module is used to process the light and dark distribution of the sample image to obtain a sample image with uniform illumination;
[0037] A correction module is used to correct the pixel difference between the sample image and the reference image so that the reference image and the sample image are aligned at the pixel level;
[0038] The detection and positioning module is used to calculate defect detection indicators by dividing the reference image and the sample image into regions, and detect and locate defects.
[0039] The method and device for detecting and locating surface defects of PCB boards of the present invention have at least the following beneficial effects: the present invention significantly improves the accuracy of detection results by correcting the interference and influence caused by uneven illumination and shift errors during the imaging process, ensuring that reliable detection results can be obtained even under complex and changeable imaging conditions, and reducing the risk of false positives and false negatives; the image structure similarity evaluation through multiple region divisions can achieve accurate positioning and efficient detection of surface defects of PCB boards, and the region division method not only improves the detection efficiency but also makes the positioning of defects more accurate; the present invention is based on the detection mode of image processing and machine vision, and compared with traditional image processing detection methods, it reduces the detection methods of image processing. The method is less dependent on imaging quality, and even if the imaging quality is not high, effective detection and positioning can still be performed, thereby improving the scope of application and flexibility of the present invention; it does not require a large number of PCB board samples to train the learning model, and its detection process only needs to obtain a defect-free reference sample, which greatly reduces the hardware cost and computing overhead required for deep learning detection methods, is easy to deploy and implement in the actual production process, and helps to reduce production costs and improve production efficiency; it has high automation properties and detection reliability; the size of the threshold and the number of area divisions can be controlled according to the needs of the actual detection process, thereby adjusting the degree of precision of detecting and positioning defects, and can be applied to different scenarios and needs, thereby improving its versatility and practicality. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0041] Figure 1 The figure is a flow chart of an embodiment of a method for detecting and locating surface defects of a PCB board according to the present invention.
[0042] Figure 2 1 is a comparison diagram of the results before and after illumination uniformity processing is performed on a sample image according to one embodiment of the present invention.
[0043] Figure 3 for Figure 1 Flowchart of step S2 in FIG.
[0044] Figure 4 for Figure 1 Flowchart of step S3 in FIG.
[0045] Figure 5 1 is a comparison diagram of the results before and after pixel difference correction processing in one embodiment of the present invention.
[0046] Figure 6 for Figure 1Flowchart of step S4 in FIG.
[0047] Figure 7 A diagram illustrating defect detection and positioning in one embodiment of the present invention.
[0048] Figure 8 This is a structural block diagram of an embodiment of a device for detecting and locating surface defects of a PCB board according to the present invention. DETAILED DESCRIPTION
[0049] The present invention will be further described below with reference to the accompanying drawings.
[0050] See also Figure 1 , is a flow chart of an embodiment of a method for detecting and locating surface defects of a PCB board according to the present invention. This embodiment specifically includes the following steps:
[0051] S1. Obtain a reference image and a sample image.
[0052] Specifically, an image of a defect-free PCB board is obtained as a reference image, and an image of the PCB board to be tested is obtained as a sample image, wherein both the reference image and the sample image are planar images, and the reference image and the sample image can be obtained by various means such as a CCD / CMOS camera.
[0053] S2. Perform illumination uniformity processing on the sample image.
[0054] Specifically, the brightness and darkness distribution of the sample image caused by uneven illumination is processed so that the brightness and darkness of the sample image are within a relatively uniform range, thereby obtaining a sample image with uniform illumination. Figure 2 , (a) is the original sample image, (b) is the sample image after illumination uniformization processing.
[0055] See also Figure 3 , this step S2 includes the following sub-steps:
[0056] S21. Form a brightness distribution matrix.
[0057] Specifically, a two-dimensional Gaussian filter is used to perform a two-dimensional Gaussian filter on the original sample image. The filtered image will smooth out the details in the image and only retain the brightness changes of the image to form a brightness distribution matrix. The brightness distribution matrix represents the brightness distribution of the image. The brightness distribution matrix BDM is obtained by the following formula:
[0058]
[0059] Where I(x+i,y+j) represents the pixel value of the sample image I at position (x+i,y+j), σ represents the standard deviation, which determines the width of the Gaussian function and also represents the degree of blurring of the filter, and k represents the radius of the Gaussian filter window.
[0060] S22. Obtain a sample image with uniform illumination.
[0061] Specifically, after obtaining the brightness distribution matrix, the brightness distribution matrix is used to perform illumination uniformity processing on the original sample image to obtain a sample image with uniform illumination. The processed image is obtained by the following formula:
[0062] I * (x,y)=I(x,y) / (BDM(x,y)+eps)
[0063] Among them, I * (x,y) represents the pixel value of the sample image at the coordinate (x,y) after illumination homogenization processing, I(x,y) represents the pixel value of the original sample image at the coordinate (x,y), and eps is a minimum value used to prevent the divisor from being zero.
[0064] S3. Correct the pixel difference between the sample image and the reference image.
[0065] During the imaging process, various factors (such as mechanical vibration) may cause shift errors between the sample image and the reference image. This error can cause pixel-level misalignment, affecting the accuracy of subsequent defect detection. To address this issue, this embodiment uses normalized cross-correlation to correct for this error, achieving pixel-level alignment between the reference and sample images.
[0066] See also Figure 4 , this step S3 includes the following sub-steps:
[0067] S31. Calculate and obtain a cross-correlation matrix.
[0068] Specifically, the reference image is slid across the sample image. This involves selecting a sliding window of the same size as the reference image and sliding it across the sample image at a specific step size. The sliding window covers all possible locations on the sample image. For each location covered by the sliding window, the normalized cross-correlation value between the reference image and the image data within the sliding window is calculated, thereby obtaining a normalized cross-correlation matrix. The cross-correlation matrix C is obtained using the following formula:
[0069]
[0070] Among them, T(i,j) represents the pixel value of the reference image at position (i,j), represents the average pixel value of the reference image, I(x+i,y+j) represents the pixel value of the sample image at position (x+i,y+j), It represents the average pixel value of the sample image in the sub-region with (x, y) as the starting coordinate, M represents the vertical size of the reference image, and N represents the horizontal size of the reference image.
[0071] S32: Determine the best matching position.
[0072] Specifically, the cross-correlation matrix is traversed to find the maximum value. This maximum value corresponds to the position where the reference image and the sample image are most similar, and the position where the maximum value is located is recorded as the best matching position of the reference image relative to the sample image.
[0073] S33. Calculate the offset.
[0074] Specifically, based on the best matching position, the pixel offsets of the sample image relative to the reference image in both horizontal and vertical directions are calculated. This is usually achieved by comparing the best matching position with the initial position of the sliding window.
[0075] S34. Translation transformation.
[0076] Specifically, the sample image is translated based on the pixel offset so that the sample image and the reference image are aligned at the pixel level. Figure 5 , (c) is the reference image, (d) is the sample image, and (e) is the sample image after pixel difference correction.
[0077] S4. Calculate defect detection indicators by region, detect and locate defects.
[0078] See also Figure 6 , this step S4 includes the following sub-steps:
[0079] S41. Regional division.
[0080] To ensure accuracy and consistency in subsequent calculations, the reference image and the sample image need to be divided into the same regions. Specifically, depending on actual needs, the image can be divided into rectangular, circular, or other shaped regions. The division can be based on the image size, the size of the expected detection area, etc.
[0081] S42. Calculate defect detection indicators.
[0082] Specifically, the structural similarity between each region of the sample image and the corresponding region in the reference image is calculated as the defect detection index of the region. The structural similarity is obtained by the following formula:
[0083]
[0084] Among them, A represents the area of the reference image where the structural similarity is currently calculated, B represents the area of the sample image where the structural similarity is currently calculated, and μ A represents the average pixel value of the reference image in area A, μ B represents the average pixel value of the sample image in area B, σ represents the covariance of the image, c1 and c2 represent two non-zero constants, σ AB represents the covariance between region A and region B, represents the variance of region A, represents the variance of region B.
[0085] S43. Determine whether there are defects.
[0086] Determine whether the current region has defects based on the calculated defect detection index. Specifically, a reasonable defect threshold is set based on the actual application requirements and image characteristics. The defect detection index of each region is compared with the defect threshold. If the defect detection index is less than the defect threshold, the current region is considered to have defects. Otherwise, the current region is considered to have no defects.
[0087] S44, subdivision detection.
[0088] Specifically, the area where the defect is detected is divided again, and steps S42 and S43 are repeated for each subdivided area. The defect detection index of the subdivided area is calculated, and the presence of a defect in the current area is determined based on the calculated area detection index. This process is repeated until the required defect detection and positioning accuracy is achieved. By subdividing the area multiple times and recalculating the defect detection index, the accuracy of defect detection and positioning can be improved. Figure 7 , (f) is a result diagram of the first area division and defect detection in this embodiment, and (g) is a result diagram of the second area division and defect detection in this embodiment.
[0089] See also Figure 8 , is a block diagram of an embodiment of a device for detecting and locating PCB surface defects according to the present invention. This device is used to implement the catalyst protection method for EGR valve leakage described in the above embodiment. Specifically, this device includes an image acquisition module 100, an image processing module 200, a correction module 300, and a detection and positioning module 400. Specifically,
[0090] The image acquisition module 100 is used to acquire a reference image and a sample image of a PCB board. The reference image is an image of a defect-free PCB board, and the sample image is an image of a PCB board to be tested.
[0091] The image processing module 200 is used to process the light and dark distribution of the sample image acquired by the image acquisition module 100 to obtain a sample image with uniform illumination.
[0092] Correction module 300 is used to correct the pixel differences between the sample image and the reference image, ensuring pixel-level alignment between the two images. During the imaging process, shift errors may occur between the sample and reference images. This error can cause pixel-level misalignment, impacting the accuracy of subsequent defect detection. Therefore, correction module 300 is required to correct these errors, ensuring pixel-level alignment between the reference and sample images.
[0093] The detection and positioning module 400 is used to calculate defect detection indicators by region based on the reference and sample images, thereby detecting and locating defects. To improve the speed of defect detection and positioning, the detection and positioning module 400 is also used to further subdivide the detected defective areas and recalculate the defect detection indicators for each subdivided area, thereby accurately locating the defect.
[0094] The present invention significantly improves the accuracy of detection results by correcting the interference and influence caused by uneven illumination and shift errors in the imaging process, ensuring that reliable detection results can be obtained even under complex and changeable imaging conditions, and reducing the risk of false positives and missed positives; the image structure similarity evaluation through multiple region divisions can achieve accurate positioning and efficient detection of PCB board surface defects, and the region division method not only improves the detection efficiency but also makes the defect positioning more accurate; the present invention is based on the detection mode of image processing and machine vision. Compared with traditional image processing detection methods, the present invention reduces the dependence of image processing detection methods on imaging quality, even if the imaging quality is not good, High, still can carry out effective detection and positioning, thereby improving the scope of application and flexibility of the present invention; does not require a large number of PCB board samples to train the learning model, its detection process only needs to obtain a defect-free reference sample, greatly reducing the hardware cost and computing overhead required for deep learning detection methods, easy to deploy and implement in the actual production process, help to reduce production costs and improve production efficiency; has high automation properties and detection reliability; can control the size of the threshold and the number of area divisions according to the needs of the actual detection process, thereby adjusting the degree of precision of detecting and positioning defects, can be applied to different scenarios and needs, and improve its versatility and practicality.
[0095] The above description merely expresses the preferred embodiments of the present invention, and its description is relatively specific and detailed, but it should not be construed as limiting the scope of the patent. It should be noted that a person skilled in the art may make a number of variations and improvements without departing from the concept of the present invention, and these variations and improvements fall within the scope of protection of the present invention. Therefore, the scope of protection of the patent of the present invention shall be based on the appended claims.
Claims
1. A method for detecting and locating surface defects of a PCB board, characterized in that: The following steps are involved: Get reference images and sample images of PCB boards; Processing the light and dark distribution of the sample image to obtain a sample image with uniform illumination; Correct the pixel difference between the sample image and the reference image so that the reference image and the sample image are aligned at the pixel level; The reference image and the sample image are divided into regions to calculate defect detection indicators, detect and locate defects.
2. The method for detecting and locating surface defects of a PCB board as claimed in claim 1, characterized in that: The step of obtaining a reference image and a sample image of the PCB board specifically includes: obtaining an image of a defect-free PCB board as a reference image, and obtaining an image of the PCB board to be tested as a sample image, wherein both the reference image and the sample image are planar images.
3. The method for detecting and locating surface defects of a PCB board as claimed in claim 1, characterized in that: The step of processing the light and dark distribution of the sample image to make the illumination of the sample image uniform specifically includes the following sub-steps: Perform two-dimensional Gaussian filtering on the original sample image to form a brightness distribution matrix; The original sample image is processed for illumination uniformity using the brightness distribution matrix to obtain a sample image with uniform illumination.
4. The method for detecting and locating surface defects of a PCB board as claimed in claim 1, characterized in that: The step of correcting the pixel difference between the sample image and the reference image so that the reference image and the sample image are aligned at the pixel level specifically includes the following sub-steps: Make the reference image slide on the sample image, calculate the corresponding cross-correlation value at each position, and obtain the normalized cross-correlation matrix; In the cross-correlation matrix, find the position with the maximum cross-correlation value, and record it as the best matching position between the reference image and the sample image; Calculating pixel offsets of the sample image relative to the reference image in both horizontal and vertical directions through the best matching position; The sample image is translated based on the pixel offset so that the sample image and the reference image are aligned at the pixel level.
5. The method for detecting and locating surface defects of a PCB board as claimed in claim 1, characterized in that: The step of calculating defect detection indicators by dividing the reference image and the sample image into regions, detecting and locating defects specifically includes the following sub-steps: Perform the same region division on the reference image and the sample image respectively; Calculate the structural similarity between each region of the sample image and the corresponding region in the reference image as the defect detection index of the region; Determine whether there is a defect in the current area based on the calculated defect detection index.
6. The method for detecting and locating surface defects of a PCB board as claimed in claim 5, characterized in that: The step of judging whether there is a defect in the current area based on the calculated defect detection index specifically includes: setting a defect threshold, comparing the defect detection index with the defect threshold, if the defect detection index is less than the defect threshold, judging that there is a defect in the current area, otherwise, judging that there is no defect in the current area.
7. The method for detecting and locating surface defects of a PCB board as claimed in claim 5, characterized in that: After the step of judging whether there is a defect in the current area according to the calculated defect detection index, the following steps are also included: The area where defects are detected is divided again, the defect detection index is calculated for each area, and it is determined whether there are defects in the current area based on the calculated regional detection index. This step is repeated until the accuracy of defect detection and positioning meets the requirements.
8. The method for detecting and locating surface defects of a PCB board as claimed in claim 4, characterized in that: The calculation formula of the cross-correlation matrix C is as follows: In formula (1), T(i,j) represents the pixel value of the reference image at position (i,j), represents the average pixel value of the reference image, I(x+i,y+j) represents the pixel value of the sample image at position (x+i,y+j), It represents the average pixel value of the sample image in the sub-region with (x, y) as the starting coordinates, M represents the vertical size of the reference image, and N represents the horizontal size of the reference image.
9. The method for detecting and locating surface defects of a PCB board as claimed in claim 5, characterized in that: The defect detection index is the structural similarity of the two-dimensional image; The SSIM calculation formula of the structural similarity is as follows: In formula (2), A represents the area of the reference image where the structural similarity is currently calculated, B represents the area of the sample image where the structural similarity is currently calculated, and μ A represents the average pixel value of the reference image in area A, μ B represents the average pixel value of the sample image in area B, σ represents the covariance of the image, c1 and c2 represent two non-zero constants, σ AB represents the covariance between region A and region B, represents the variance of region A, represents the variance of region B.
10. A device for detecting and locating surface defects of a PCB board, characterized in that: include: An image acquisition module, used to acquire a reference image and a sample image of a PCB board; An image processing module is used to process the light and dark distribution of the sample image to obtain a sample image with uniform illumination; A correction module, used to correct the pixel difference between the sample image and the reference image so that the reference image and the sample image are aligned at the pixel level; The detection and positioning module is used to calculate defect detection indicators by dividing the reference image and the sample image into regions, and detect and locate defects.
Citation Information
Cited By
Intelligent card defect detection method and system based on machine vision
CN120672763A
PCB defect detection method and system based on AI vision
CN120823208A
PCB defect detection method and system based on AI vision
CN120823208B
Vehicle foreign matter detection method, electronic equipment and storage medium
CN121147559A