PCB defect intelligent detection method and system based on image recognition

By using multi-angle illumination image sequence analysis and classification models, the problem of high false negative rate in traditional detection methods has been solved, achieving high-precision PCB defect detection.

CN122243976APending Publication Date: 2026-06-19JIANGXI KUNYU ELECTRONICS CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
JIANGXI KUNYU ELECTRONICS CO LTD
Filing Date
2026-03-24
Publication Date
2026-06-19

AI Technical Summary

Technical Problem

In existing technologies, PCB defect detection relies on manual visual inspection or traditional optical inspection, which makes it difficult to fully capture complex defects, resulting in a high rate of missed detections and an inability to distinguish between real defects and normal texture differences, thus failing to meet the needs of high-precision continuous production.

Method used

The PCB board is illuminated from multiple angles by an adjustable ring light source, and reflection images are acquired simultaneously to construct a multi-angle illumination image sequence. Pixel-level reflection characteristics are analyzed, and defect categories are determined by combining connected component analysis and classification models.

🎯Benefits of technology

It improves the detection rate of subtle defects, suppresses background texture interference, and achieves high-precision and high-robustness PCB defect detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122243976A_ABST
    Figure CN122243976A_ABST
Patent Text Reader

Abstract

This invention discloses an intelligent PCB defect detection method and system based on image recognition. The method includes: illuminating the test area of ​​the PCB board from multiple angles sequentially using an adjustable-angle ring light source to construct an image sequence of different illumination directions under the same field of view; performing pixel-level reflectance characteristic analysis on the image sequence to extract abnormal pixels that deviate from the normal copper foil and substrate reflectance characteristics; generating a candidate region set containing location and boundary information based on the spatial distribution and morphological characteristics of the abnormal pixels; inputting the candidate region set into a classification model based on the physical causes of defects, and determining the defect category of each candidate region by comparing the reflectance characteristics and geometric morphological characteristics corresponding to different defect types, and outputting the detection result. Using this invention, the detection rate of various subtle defects can be improved, background texture interference can be suppressed, and high-precision, highly robust intelligent PCB defect detection can be achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of image recognition technology, specifically a method and system for intelligent detection of PCB defects based on image recognition. Background Technology

[0002] Printed circuit boards (PCBs) are core components of electronic products, and even minor defects during their manufacturing process can lead to the failure of the entire circuit. Currently, PCB defect detection on industrial production lines mainly relies on manual visual inspection or traditional optical imaging inspection. Manual inspection is inefficient and highly subjective, making it difficult to meet the demands of high-precision continuous production. Traditional automated optical inspection (AOI) typically uses a fixed-angle ring light source to illuminate the surface, acquiring a single image for threshold segmentation and morphological comparison. However, due to the significant differences in the reflection characteristics of copper foil surfaces and substrates to incident light from different directions, a single illumination direction cannot comprehensively capture the characteristics of complex defects such as scratches, dents, and foreign objects, resulting in a high rate of missed detection for light-sensitive defects and an inability to effectively distinguish between real defects and normal texture differences. Therefore, how to improve the accuracy and robustness of PCB defect detection through multi-angle illumination information fusion has become a pressing technical problem to be solved in this field. Summary of the Invention

[0003] The purpose of this invention is to provide an intelligent PCB defect detection method and system based on image recognition, so as to overcome the shortcomings of the existing technology, improve the detection rate of various minor defects, suppress background texture interference, and achieve high-precision and high-robustness intelligent PCB defect detection.

[0004] One embodiment of this application provides a method for intelligent PCB defect detection based on image recognition, the method comprising:

[0005] An adjustable-angle ring light source illuminates the area under test of the PCB board from multiple angles, and the reflected images at each illumination angle are acquired simultaneously to construct an image sequence of different illumination directions under the same field of view.

[0006] The image sequence is subjected to pixel-level reflectance characteristic analysis. The gray value change pattern of each pixel under multi-angle illumination is calculated, and abnormal pixels that deviate from the normal reflectance characteristics of copper foil and substrate are extracted.

[0007] Based on the spatial distribution and morphological characteristics of the abnormal pixels, candidate regions with suspected defect features are selected through connected component analysis, and a set of candidate regions containing location and boundary information is generated.

[0008] The candidate region set is input into a classification model based on the physical causes of defects. By comparing the reflection characteristics and geometric features corresponding to different defect types, the defect category of each candidate region is determined and the detection results are output.

[0009] Optionally, the step of illuminating the PCB board test area from multiple angles sequentially using an adjustable-angle ring light source and simultaneously acquiring reflection images at each illumination angle to construct an image sequence of different illumination directions within the same field of view includes:

[0010] The PCB board is precisely fixed in the center of the stage, and the initial illumination angle of the ring light source is set to the preset starting position through the controller to generate the initial angle parameters of the light source.

[0011] Based on the initial angle parameters of the light source, the ring light source is driven to rotate sequentially at fixed step angles. At each angle position, the industrial camera is triggered to expose synchronously, and the reflected light image of the area to be tested on the PCB board is acquired to generate the original set of reflected images.

[0012] Feature point matching and image registration are performed on the original set of reflection images. The phase correlation algorithm is used to eliminate the tiny pixel shifts caused by mechanical motion, ensuring that all images are aligned in the same pixel coordinate system, and generating a registered image sequence.

[0013] Each image in the registered image sequence is labeled with a corresponding illumination angle, and then arranged and integrated in ascending order of angle to finally construct a complete multi-angle illumination image sequence.

[0014] Optionally, the step of performing pixel-level reflectance characteristic analysis on the image sequence, calculating the grayscale value variation pattern of each pixel under multi-angle illumination, and extracting abnormal pixels that deviate from the normal reflectance characteristics of copper foil and substrate includes:

[0015] The gray values ​​of all illumination angles are extracted pixel by pixel from the multi-angle illumination image sequence. A response curve is established for each pixel with the illumination angle as the independent variable and the gray value as the dependent variable, generating a pixel-level reflectance characteristic dataset.

[0016] Load the pre-established standard reflection feature library of normal copper foil and substrate, and calculate the similarity between the response curve of each pixel and the standard curve based on the pixel-level reflection characteristic dataset. Use the dynamic time warping algorithm to measure the degree of deviation and generate a set of pixel deviation measurement values.

[0017] An adaptive threshold is set based on the statistical distribution of the set of pixel deviation values. Pixels with deviation values ​​exceeding the adaptive threshold are marked as abnormal candidate points, and an initial set of abnormal pixels is generated.

[0018] The initial set of anomalous pixels is processed by morphological opening to eliminate isolated noise and minor interference, retaining anomalous pixels with physical continuity, and generating the final set of anomalous pixels.

[0019] Optionally, the step of filtering candidate regions with suspected defect features based on the spatial distribution and morphological characteristics of the abnormal pixels through connected component analysis, and generating a candidate region set containing location and boundary information, includes:

[0020] The final set of abnormal pixels is mapped back to the original image coordinate space to construct a binary abnormal pixel distribution map.

[0021] The abnormal pixel distribution map is processed by the eight-neighbor connected region labeling algorithm, which combines adjacent abnormal pixels into independent connected regions to generate a connected region labeling map.

[0022] Traverse each connected region in the connected region label graph, calculate the geometric morphological parameters including its area, perimeter, aspect ratio of the minimum bounding rectangle, and roundness, and generate a set of region morphological feature parameters;

[0023] The set of regional morphological feature parameters is filtered according to the preset threshold range of suspected defect morphology. Regions that do not conform to the typical defect morphology features are eliminated, and candidate regions with suspected defect features are retained. The centroid coordinates and contour point sequence of each candidate region are recorded to generate a candidate region set.

[0024] Optionally, the step of inputting the candidate region set into a classification model based on the physical causes of defects, and determining the defect category of each candidate region and outputting the detection result by comparing the reflection characteristics and geometric features corresponding to different defect types, includes:

[0025] Extract the gray value sequence and geometric parameters of each candidate region in the multi-angle illumination image from the candidate region set, and combine them into a feature vector to be classified.

[0026] The pre-trained defect classification model is invoked. This model is built based on the physical reflection mechanism and morphological features of various defects and includes feature templates for typical defect types such as short circuit, open circuit, void, and burr.

[0027] The feature vector to be classified is input into the classification model, and the support vector machine classifier is used to calculate its matching probability with each defect type template, generating the preliminary defect category determination result for each candidate region;

[0028] The initial defect category determination results are evaluated for confidence level. False detection areas with confidence levels below the preset confidence threshold are eliminated. Information from multiple perspectives is integrated for consistency verification. Finally, a complete detection result containing defect category, location coordinates, and confidence level is output.

[0029] Another embodiment of this application provides an image recognition-based intelligent PCB defect detection system, the system comprising:

[0030] The acquisition module is used to illuminate the area under test of the PCB board from multiple angles through an adjustable ring light source, and simultaneously acquire the reflection image at each illumination angle to construct an image sequence of different illumination directions under the same field of view.

[0031] The extraction module is used to perform pixel-level reflectance characteristic analysis on the image sequence, calculate the gray value change pattern of each pixel under multi-angle illumination, and extract abnormal pixels that deviate from the normal reflectance characteristics of copper foil and substrate.

[0032] The filtering module is used to filter out candidate regions with suspected defect features through connected component analysis based on the spatial distribution and morphological characteristics of the abnormal pixels, and generate a set of candidate regions containing location and boundary information.

[0033] The output module is used to input the candidate region set into a classification model based on the physical causes of defects, and to determine the defect category of each candidate region by comparing the reflection characteristics and geometric features corresponding to different defect types and output the detection results.

[0034] Another embodiment of this application provides a storage medium storing a computer program, wherein the computer program is configured to execute the method described in any of the preceding claims when running.

[0035] Another embodiment of this application provides an electronic device including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the method described in any of the preceding claims.

[0036] Compared with existing technologies, the present invention provides an intelligent PCB defect detection method based on image recognition, which can improve the detection rate of various subtle defects, suppress background texture interference, and achieve high-precision and high-robustness intelligent PCB defect detection. Attached Figure Description

[0037] Figure 1 A hardware structure block diagram of a computer terminal for an image recognition-based intelligent PCB defect detection method provided in an embodiment of the present invention;

[0038] Figure 2 A flowchart illustrating an image recognition-based intelligent PCB defect detection method provided in an embodiment of the present invention;

[0039] Figure 3 This is a schematic diagram of the structure of an image recognition-based intelligent PCB defect detection system provided in an embodiment of the present invention. Detailed Implementation

[0040] The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.

[0041] This invention first provides an intelligent PCB defect detection method based on image recognition. This method can be applied to electronic devices, such as computer terminals, specifically ordinary computers.

[0042] The following detailed explanation uses a computer terminal as an example. Figure 1 This is a hardware structure block diagram of a computer terminal for an image recognition-based intelligent PCB defect detection method provided in an embodiment of the present invention. Figure 1 As shown, the computer device includes a processor, memory, and network interface connected via a system bus, wherein the memory may include non-volatile storage media and internal memory.

[0043] See Figure 2 The present invention provides an intelligent PCB defect detection method based on image recognition, which may include the following steps:

[0044] S201 illuminates the area under test of the PCB board from multiple angles through an adjustable ring light source, and simultaneously acquires the reflection image at each illumination angle to construct an image sequence of different illumination directions under the same field of view.

[0045] Specifically, the PCB board can be precisely fixed in the center of the stage, and the initial illumination angle of the ring light source can be set to the preset starting position through the controller to generate the initial angle parameters of the light source;

[0046] The core of this step is to achieve precise positioning of the PCB board and initial calibration of the ring light source. Through mechanical fixation and parameter preset, a spatial reference and parameter foundation are laid for subsequent multi-angle illumination and image acquisition. The specific implementation method is as follows:

[0047] The stage employs a high-precision vacuum adsorption fixing structure, with the flatness error of the stage surface controlled within ±0.005mm, ensuring that the PCB board is placed without warping or offset. During fixing, the PCB board is first coarsely positioned using the positioning pins on the edge of the stage. The spacing of the positioning pins is adapted to the standard dimensions of common PCB boards. Then, the vacuum adsorption device is activated to generate a negative pressure of -0.06MPa, tightly adsorbing the PCB board to the center of the stage surface. After adsorption, a laser displacement sensor detects the surface height of the PCB board to ensure that the object distance between the board and the industrial camera lens is fixed at 100mm, with an object distance deviation of no more than ±0.5mm, avoiding image scaling distortion caused by distance changes.

[0048] The ring light source features a multi-segment adjustable angle structure, consisting of eight evenly distributed LED groups. Each group can independently rotate around the central axis of the PCB board, providing an overall illumination angle adjustment range of 0°-360° with an accuracy of ±1°. The controller connects to the ring light source via RS485 communication protocol, supporting digital setting and real-time feedback of angle parameters. The preset starting position is determined based on the reflectivity of the PCB board's copper foil and substrate. Typically, the initial illumination angle is set to 0°, meaning the first LED group points vertically to the center of the area to be tested on the PCB board. The generated initial angle parameters contain key information: initial angle value of 0°, brightness uniformity parameters for each LED group (deviation ≤5%), color temperature of 6500K (neutral white light to reduce color interference), and illuminance of 5000 lux (to ensure sufficient dynamic range of image grayscale). All parameters are stored in a structured data format, providing a reference for subsequent angle step rotation.

[0049] Based on the initial angle parameters of the light source, the ring light source is driven to rotate sequentially at fixed step angles. At each angle position, the industrial camera is triggered to expose synchronously, and the reflected light image of the area to be tested on the PCB board is acquired to generate the original set of reflected images.

[0050] The core of this step is to achieve the orderly rotation of the ring light source and the synchronous image acquisition of the industrial camera. By using a fixed step angle to cover the entire angular illumination, it ensures the acquisition of complete reflection images from different lighting directions within the same field of view. The specific implementation method is as follows:

[0051] The fixed step angle setting needs to balance the integrity of illumination coverage and acquisition efficiency. Considering the accuracy requirements of PCB board defect detection and the pace of industrial production, the step angle is set to 30°. That is, the ring light source rotates 30° and then stops to complete one image acquisition. 12 rotations can achieve full-angle coverage from 0° to 360°, ensuring no blind spots in illumination and avoiding low acquisition efficiency due to too small a step. The rotation drive is implemented by a stepper motor with a step angle of 1.8°. The torque is amplified by a reduction gear set, and the rotation positioning accuracy reaches ±0.5°, ensuring that the illumination direction at each angle position accurately matches the preset parameters.

[0052] Synchronous exposure is achieved via the controller's I / O trigger signal. Once the ring light source rotates to the target angle and stabilizes for 0.1 seconds, the controller sends a rising-edge trigger signal to the industrial camera, triggering exposure and acquisition. The industrial camera is a CMOS area-array camera with a resolution of 1920×1080 pixels and a pixel size of 3.75μm×3.75μm. The exposure time is set to 200μs based on the light intensity to ensure the image grayscale value distribution is between 50-200 (16-bit grayscale range), avoiding overexposure or underexposure. During acquisition, a 25mm industrial lens is used with an aperture set to F4, and the depth of field covers the PCB board thickness range (0.8-2.0mm) to ensure clear imaging of all pixels in the test area.

[0053] After acquiring images from each angle, the system automatically stores the images in uncompressed RAW format. The filename includes the PCB board number, acquisition timestamp, and current illumination angle, for example, "PCB_20250610_143000_0°.raw". After acquiring images from all 12 angles, they are integrated in the acquisition order to form a raw reflection image set. Each image in the set retains complete 16-bit grayscale information without compression distortion, providing high-quality raw data for subsequent registration processing.

[0054] Feature point matching and image registration are performed on the original set of reflection images. The phase correlation algorithm is used to eliminate the tiny pixel shifts caused by mechanical motion, ensuring that all images are aligned in the same pixel coordinate system, and generating a registered image sequence.

[0055] The core of this step is to eliminate the spatial offset caused by mechanical motion during multi-angle acquisition. Precise image alignment is achieved through feature matching and phase correlation algorithms to ensure the consistency of coordinates of the same physical pixel in images from different angles. The specific implementation method is as follows:

[0056] First, feature point matching preprocessing is performed. Gaussian filtering is applied to each image in the original reflection image set for noise reduction, with a filter kernel size of 3×3 and a standard deviation σ=1.0 to reduce the interference of image noise on feature point extraction. Then, the SIFT algorithm is used to extract feature points from each image. The feature point selection thresholds are set to a contrast threshold of 0.03 and an edge threshold of 10 to ensure that the extracted feature points are concentrated in textured areas such as copper foil lines and pads on the PCB board. At least 500 effective feature points are extracted from each image. Using the initial angle (0°) image as the reference image and the images at other angles as the images to be registered, the FLANN matching algorithm is used to calculate feature point matching pairs between the images to be registered and the reference image. The matching distance threshold is set to 200, and false matches are discarded, retaining matching results with an accuracy of ≥95%.

[0057] Based on the feature point matching results, a phase correlation algorithm is used to calculate the translational offset of the image to be registered relative to the reference image. This algorithm calculates the phase difference of the two-dimensional Fourier transforms of the two images to accurately solve for the pixel offsets in the x and y directions. Due to mechanical rotation and positioning errors, the image to be registered typically has a small offset of ±1 pixel; the phase correlation algorithm can achieve a sub-pixel accuracy of 0.1 pixels. Based on the calculated offset, a bilinear interpolation algorithm is used to resample the image to be registered, translating it to the position relative to the reference image. Figure 1 An consistent pixel coordinate system is used. For example, if an image at a 30° angle has an x-direction offset of +0.8 pixels and a y-direction offset of -0.3 pixels, then the coordinate position of each pixel is adjusted through an interpolation algorithm to achieve image alignment.

[0058] After registration, the alignment accuracy of each image is verified. Twenty common feature points are randomly selected, and their coordinate deviations in the reference image and the registered image are calculated. If the average deviation of all feature points is ≤0.2 pixels, the registration is considered valid. All verified registered images are arranged in order of acquisition angle to generate a registered image sequence. The pixel coordinate system of each image in the sequence is completely unified. Defects at the same physical location are at the same pixel coordinates in images from different angles, providing basic data for spatial alignment for subsequent pixel-level reflectance characteristic analysis.

[0059] Each image in the registered image sequence is labeled with a corresponding illumination angle, and then arranged and integrated in ascending order of angle to finally construct a complete multi-angle illumination image sequence.

[0060] The core of this step is to achieve precise correlation and orderly integration between the image and the lighting angle. By labeling and sorting, it is ensured that subsequent analysis can accurately trace the reflection response of each pixel under different lighting directions. The specific implementation method is as follows:

[0061] The tag attachment adopts a metadata embedding method, adding a structured EXIF ​​metadata tag to each registered image. The tag contains three core types of information: illumination angle parameters (accurate to 0.1°, such as 0.0°, 30.0°, 60.0°…330.0°), acquisition auxiliary parameters (exposure time 200μs, illumination intensity 5000lux, color temperature 6500K), and registration information (reference image identifier, translation offset, registration accuracy). All tag information is stored in key-value pair format to ensure that image processing software can directly read and parse it.

[0062] During the image integration process, the registered images are sorted in ascending order based on the illumination angle values, covering a range of 0°-360° with a step size of 30°, ultimately forming an ordered sequence of 12 images. After sorting, the sequence is checked for integrity to ensure there are no missing angles, duplicates, or sorting errors. If an image at a certain angle is found to be missing, the system will automatically trigger a re-acquisition process; if duplicate images are found, the version with higher registration accuracy will be retained.

[0063] The integrated multi-angle illumination image sequence is stored in TIFF format, retaining 16-bit original grayscale data to avoid grayscale loss caused by format conversion. The sequence files are named using a unified format of "PCB number_series number_angle value.tif", such as "PCB_001_Series_001_0.0.tif" and "PCB_001_Series_002_30.0.tif", facilitating subsequent image retrieval by angle index. This sequence completely records the reflection images of the same PCB test area under 12 illumination directions evenly distributed at 360°, with all images pixel-aligned and angles traceable, providing a complete and standardized data source for subsequent pixel-level reflection characteristic analysis.

[0064] S202, perform pixel-level reflectance characteristic analysis on the image sequence, calculate the gray value change law of each pixel under multi-angle illumination, and extract abnormal pixels that deviate from the normal copper foil and substrate reflectance characteristics.

[0065] Specifically, grayscale values ​​at all illumination angles can be extracted pixel by pixel from a multi-angle illumination image sequence, and a response curve can be established for each pixel with illumination angle as the independent variable and grayscale value as the dependent variable, generating a pixel-level reflectance characteristic dataset.

[0066] The core of this step is to achieve pixel-level grayscale value extraction from all angles and reflectance response modeling. By tracing grayscale changes under different illumination angles pixel by pixel, a dataset that can accurately characterize the reflectance characteristics of each pixel is constructed, providing a foundation for subsequent anomaly identification. The specific implementation method is as follows:

[0067] The multi-angle illumination image sequence consists of 12 registered 1920×1080 pixel 16-bit grayscale images, covering illumination angles from 0° to 360° with a step size of 30°. All image pixel coordinate systems are fully aligned, and the coordinates of the same physical pixel remain consistent across images from different angles. During pixel-by-pixel extraction, a pixel coordinate system is established with the top-left corner of the image sequence as the origin. Pixel coordinates are represented as (x, y), with x ranging from 0 to 1919 and y ranging from 0 to 1079. Each pixel is traversed in row-major order. For each pixel (x, y), its corresponding grayscale value G_θ is extracted sequentially from the 12 images, where θ is the illumination angle (0°, 30°, 60°…330°), and the grayscale value ranges from 0 to 65535. The original 16-bit precision is preserved during extraction; no compression or quantization is performed.

[0068] When establishing a response curve for each pixel, the illumination angle θ is used as the abscissa (independent variable), and the corresponding gray value G_θ is used as the ordinate (dependent variable). Twelve sets of (θ, G_θ) data are connected in ascending order of angle to form the reflectivity response curve for that pixel. The response curve is a broken line composed of discrete data points, which can intuitively reflect the variation of the pixel's reflectivity intensity under different illumination directions. For example, the response curve of a normal copper foil pixel exhibits the characteristics of "high gray value and gradual change," with the gray value remaining between 50,000 and 60,000 at all angles. In contrast, the response curve of a substrate pixel has a lower gray value, mostly between 10,000 and 20,000, and fluctuates slightly with changes in angle.

[0069] The response curves of all pixels, along with their corresponding (x, y) coordinates and full-angle grayscale value sequences, are structurally integrated to generate a pixel-level reflectivity dataset. This dataset uses pixels as the basic unit, with each unit containing pixel coordinates, a list of grayscale values ​​for 12 illumination angles, and response curve feature parameters (such as curve mean, variance, and peak value). It is stored in binary file format to ensure efficient data reading and processing. The dataset fully preserves the full-angle reflectivity information of each pixel, laying the foundation for subsequent comparison with standard features.

[0070] Load the pre-established standard reflection feature library of normal copper foil and substrate, and calculate the similarity between the response curve of each pixel and the standard curve based on the pixel-level reflection characteristic dataset. Use the dynamic time warping algorithm to measure the degree of deviation and generate a set of pixel deviation measurement values.

[0071] The core of this step is to quantify the degree of deviation between the pixel response curve and the standard feature through precise comparison, thereby providing a basis for identifying abnormal pixels. The specific implementation method is as follows:

[0072] The pre-established standard reflectance feature library for normal copper foil and substrate is a feature set constructed by collecting copper foil and substrate samples from 1000 defect-free PCB boards, acquiring data through multi-angle illumination, and averaging the data. The feature library contains two core standard curves: the normal copper foil standard curve C_cu and the normal substrate standard curve C_sub. Each standard curve is a sequence of grayscale values ​​corresponding to 12 illumination angles, and includes statistical features (mean μ, standard deviation σ, rate of change k). For example, the normal copper foil standard curve has a mean μ_cu = 55000, a standard deviation σ_cu = 2000, and a rate of change k_cu = 0.05 (indicating that the grayscale value changes smoothly with angle); the normal substrate standard curve has a mean μ_sub = 15000, a standard deviation σ_sub = 3000, and a rate of change k_sub = 0.12 (indicating that the grayscale value changes slightly more significantly with angle). The feature library supports dynamic updates, and the accuracy of the standard curves can be continuously optimized by adding new defect-free samples.

[0073] Similarity calculation employs the Dynamic Time Warping (DTW) algorithm, specifically designed to address similarity measurement issues arising from inconsistent time series lengths or phase shifts. This algorithm effectively handles curve misalignment caused by minute angular deviations during illumination angle acquisition. During calculation, DTW is performed on the response curve C_p of each pixel in the pixel-level reflectivity dataset and C_cu and C_sub in the feature library, yielding two deviation metrics, d_cu and d_sub. The physical meaning of these deviation metrics is the minimum cumulative distance between the two curves, ranging from 0 to +∞. Smaller values ​​indicate higher similarity and closer pixel reflectivity characteristics to the corresponding standard. For example, if a pixel's response curve has a DTW deviation of d_cu = 800 from C_cu and d_sub = 5000 from C_sub, then this pixel is closer to the reflectivity characteristics of normal copper foil.

[0074] For each pixel, the minimum value between d_cu and d_sub is selected as the final deviation metric d_p for that pixel, i.e., d_p = min(d_cu, d_sub), representing the degree of deviation of the pixel's reflectivity from the closest normal standard. The (x, y, d_p) coordinates of all pixels are integrated in coordinate order to generate a set of pixel deviation metrics. This set is in the form of a two-dimensional matrix, with dimensions consistent with the image resolution (1920 × 1080). Each matrix element corresponds to the deviation metric value of a single pixel, achieving a spatial representation of the degree of deviation.

[0075] An adaptive threshold is set based on the statistical distribution of the set of pixel deviation values. Pixels with deviation values ​​exceeding the adaptive threshold are marked as abnormal candidate points, and an initial set of abnormal pixels is generated.

[0076] The core of this step is to dynamically set a reasonable anomaly detection threshold by analyzing the global statistical characteristics of the deviation metric, thereby achieving preliminary screening of abnormal pixels. The specific implementation method is as follows:

[0077] First, a statistical distribution analysis is performed on the pixel deviation metric set to calculate the statistical parameters of the global deviation metric, including the mean μ_d, standard deviation σ_d, maximum value d_max, and minimum value d_min. During the statistical process, extreme outliers in the pixel deviation metric set are removed (using the 3σ principle, i.e., removing values ​​exceeding the range of μ_d ± 3σ_d) to ensure that the statistical parameters accurately reflect the distribution characteristics of normal deviations. For example, the pixel deviation metric statistics for a batch of PCB boards are μ_d = 1200, σ_d = 500, d_max = 15000, and d_min = 100. After removing extreme values, μ_d' = 1150 and σ_d' = 480. This result indicates that the deviation metric values ​​of most normal pixels are concentrated around 1150, with a relatively small fluctuation range.

[0078] The adaptive threshold T is set using a dynamic formula of "mean + k times standard deviation", where k is an adjustment coefficient, set to 3.0 based on the accuracy requirements of PCB board inspection. That is, T = μ_d' + k × σ_d'. This formula adapts to the differences in deviation distribution among different batches of PCB boards, avoiding missed or false detections caused by a fixed threshold. Using the example above, T = 1150 + 3.0 × 480 = 2590, meaning that pixels with a deviation value exceeding 2590 have reflection characteristics that deviate from normal copper foil or substrate beyond a reasonable range and need to be marked as abnormal candidate points.

[0079] When marking abnormal candidate points, each pixel (x, y) in the pixel deviation metric set is traversed. If its deviation metric d_p > T, the pixel is marked as an abnormal candidate point. The marking method is to record its (x, y) coordinates and assign a mark value of 1 (normal pixels are marked as 0). After marking is completed, the coordinates of all pixels marked as 1 are integrated in row priority to generate an initial abnormal pixel set. This set is in the form of a coordinate list and contains the spatial location information of all initially determined abnormal pixels. For example, an initial abnormal pixel set may contain continuous coordinates such as (520, 310), (521, 310), and (520, 311), or it may contain isolated coordinates such as (100, 200). No filtering process is performed, and all pixels exceeding the threshold are retained.

[0080] The initial set of anomalous pixels is processed by morphological opening to eliminate isolated noise and minor interference, retaining anomalous pixels with physical continuity, and generating the final set of anomalous pixels.

[0081] The core of this step is to filter out false anomalies through morphological operations, retain the continuous abnormal pixels corresponding to real defects, and improve the accuracy of anomaly recognition. The specific implementation method is as follows:

[0082] The core logic of morphological opening is "erosion followed by dilation." Erosion eliminates tiny, isolated noise points, and dilation restores the shape of the effective anomalous region, preventing the effective region from shrinking excessively due to erosion. First, the initial set of anomalous pixels is converted into a binary image with the same size as the original image (1920×1080). The pixel values ​​corresponding to the anomalous candidate points are set to 255 (foreground), and normal pixels are set to 0 (background), generating the initial anomalous binary image.

[0083] The erosion operation uses a 3×3 rectangular structuring element, with the center pixel of the structuring element as the origin and the surrounding 8 adjacent pixels as the neighborhood. The erosion rules are as follows: if any background pixel (0) exists within the 3×3 area covered by the structuring element, the center pixel is set to a background pixel (0); the center pixel remains a foreground pixel (255) only when all pixels within the 3×3 area are foreground pixels (255). This operation can effectively eliminate isolated noise points and small interference areas with ≤3 pixels. For example, a single isolated anomalous candidate point (100, 200) will be converted into a background pixel after the erosion operation, while an anomalous area containing 5 consecutive pixels can retain the core part.

[0084] After the erosion operation is completed, a dilation operation is performed using the same 3×3 rectangular structuring element as the erosion operation. The dilation rules are as follows: if any foreground pixel (255) exists within the 3×3 area covered by the structuring element, the center pixel is set as the foreground pixel (255); the center pixel remains a background pixel (0) only when all pixels within the 3×3 area are background pixels (0). This operation can restore the original shape of the effective abnormal area after erosion, avoiding area shrinkage or breakage caused by erosion. For example, the abnormal core area retained after erosion can be restored to a continuous area close to its initial size through the dilation operation.

[0085] After the opening operation is completed, the (x, y) coordinates of all foreground pixels (255) are extracted from the processed binary image, sorted and integrated according to spatial location, to generate the final set of abnormal pixels. The abnormal pixels in this set all have physical continuity, and isolated noise and minor interference have been removed. They can accurately correspond to areas on the PCB board that may have defects. For example, a certain final set of abnormal pixels contains a continuous group of pixels from (520, 310) to (525, 315), which corresponds to a suspected defect area on the PCB board, providing a high-quality abnormal pixel data source for subsequent candidate area screening.

[0086] S203, based on the spatial distribution and morphological characteristics of the abnormal pixels, candidate regions with suspected defect characteristics are selected through connected component analysis, and a set of candidate regions containing location and boundary information is generated.

[0087] Specifically, the final set of abnormal pixels can be mapped back to the original image coordinate space to construct a binarized abnormal pixel distribution map;

[0088] The core of this step is to accurately restore the coordinates of abnormal pixels from the feature processing space to the original image space. Binarization is used to highlight the boundaries between abnormal and normal regions, generating an intuitive visualization of the anomaly distribution. This provides a clear image foundation for subsequent connected component analysis. The specific implementation method is as follows:

[0089] The (x,y) coordinates of the final set of abnormal pixels are based on the unified pixel coordinate system of the registered image sequence. The coordinate space of the original image is completely consistent with the registered coordinate system (both have the upper left corner of the image as the origin, the x-axis is horizontal to the right and the y-axis is vertical to the down). Therefore, the mapping process does not require additional coordinate transformation. It is only necessary to directly map all the abnormal pixel coordinates in the set to the same position in the original image to ensure that the spatial position of the abnormal pixels completely matches the actual defect position of the PCB board.

[0090] When constructing the binarized abnormal pixel distribution map, a blank image is created based on the resolution of the original image (1920×1080 pixels), with all initial pixel values ​​set to 0 (representing a black background, corresponding to normal areas). For each (x, y) coordinate in the final abnormal pixel set, the corresponding pixel value in the original image is modified to 255 (representing a white foreground, corresponding to an abnormal area), thus visually marking the abnormal pixels. The binarization process uses a single threshold segmentation method with a threshold set to 127. Pixel values ​​≥ 255 are considered foreground (abnormal), and < 255 are considered background (normal). This threshold maximizes the distinction between abnormal and normal areas, avoiding grayscale value confusion.

[0091] The generated abnormal pixel distribution map is an 8-bit single-channel binary image in PNG format. The white pixel clusters in the image visually represent the spatial aggregation of abnormal pixels. For example, a short-circuit defect in a certain area of ​​a PCB board will appear as a continuous block of white pixels in the corresponding distribution map; if a tiny void defect exists, it will appear as an isolated but continuous cluster of white pixels. This image preserves the spatial distribution information of abnormal pixels while simplifying image complexity through binarization, providing a clear analytical object for subsequent connected component labeling.

[0092] The abnormal pixel distribution map is processed by the eight-neighbor connected region labeling algorithm, which combines adjacent abnormal pixels into independent connected regions to generate a connected region labeling map.

[0093] The core of this step is to classify spatially continuous abnormal pixels into independent connected regions through eight-neighbor connectivity determination, thereby achieving structured division of abnormal regions and providing independent analysis units for subsequent morphological parameter calculations. The specific implementation method is as follows:

[0094] The core logic of the eight-neighbor connected component labeling algorithm is to determine the adjacency relationship of pixels. The eight-neighbor refers to the eight neighboring pixels around a certain pixel (x,y), including the horizontal direction (x±1,y), the vertical direction (x,y±1), and the diagonal direction (x±1,y±1). As long as a pixel and another abnormal pixel satisfy the eight-neighbor relationship, they are determined to be connected. The labeling process is executed in the order of "traversal-labeling-expansion". First, starting from the upper left corner (0,0) of the abnormal pixel distribution map, the algorithm traverses pixel by pixel in row priority order. When a pixel with a value of 255 (abnormal) and no label is encountered, a unique label number is assigned to it (incrementing from 1). Then, using this pixel as the seed point, the algorithm recursively traverses all unlabeled abnormal pixels in its eight-neighbor, assigns them the same label number, and forms an independent connected region. The algorithm continues to traverse the image until all abnormal pixels are labeled, and the background pixel (0) remains unlabeled.

[0095] For example, in an abnormal pixel distribution map, there are two independent clusters of white pixels. The first cluster contains consecutive pixels from (520, 310) to (525, 315). When traversing to (520, 310), it assigns a label number of 1, and recursively labels all associated abnormal pixels in its eight neighborhoods, forming connected region 1. The second cluster contains consecutive pixels from (800, 450) to (803, 452), assigns a label number of 2, and forms connected region 2. After labeling, a connected region label map is generated. This map is a 16-bit grayscale image with the same size as the abnormal pixel distribution map. The pixel value of each connected region is its corresponding label number (1, 2, 3...), and the background pixel value is 0. The maximum value of the label number is the total number of connected regions. This map clearly distinguishes different abnormal clusters, providing a structured basis for subsequent analysis of region morphology.

[0096] Traverse each connected region in the connected region label graph, calculate the geometric morphological parameters including its area, perimeter, aspect ratio of the minimum bounding rectangle, and roundness, and generate a set of region morphological feature parameters;

[0097] The core of this step is to perform quantitative morphological analysis on each independent connected region, extract key parameters that characterize the geometric features of the region, and provide a quantitative basis for distinguishing between suspected defects and invalid interference. The specific implementation method is as follows:

[0098] When traversing the connected component label graph, all pixel coordinates corresponding to each label number are extracted sequentially in ascending order, forming a set of pixel coordinates for a single connected component. Based on this set, four core geometric morphological parameters are calculated. The area parameter refers to the total number of pixels contained in the connected component, directly reflecting the size of the region. The calculation formula is A=N, where N is the total number of pixels in the region, in pixels². For example, if a connected component contains 30 pixels, its area A=30 pixels². This parameter can initially filter out interference regions that are too small (e.g., <5 pixels).

[0099] The perimeter parameter refers to the pixel length of the boundary contour of a connected region. When calculating it, the contour pixels of the region (i.e., pixels adjacent to the background pixels on the boundary of the region) are first extracted by the edge detection algorithm, and then the total number of contour pixels is counted. The unit is "pixels". For example, if a region has 28 contour pixels, its perimeter P = 28 pixels. The perimeter can reflect the complexity of the boundary of the region. The perimeter of a defective region is usually proportional to its area.

[0100] The aspect ratio parameter of the minimum bounding rectangle refers to the ratio of the length to the width of the smallest rectangle that can completely enclose the connected region. It is calculated by first determining the maximum x-coordinate (x_max) and minimum x-coordinate (x_min) of all pixels in the region, and the maximum y-coordinate (y_max) and minimum y-coordinate (y_min). The length of the minimum bounding rectangle is L = max(x_max - x_min, y_max - y_min), and the width is W = min(x_max - x_min, y_max - y_min). The aspect ratio is R = L / W. This parameter has no unit and can distinguish the shape characteristics of the region. For example, the connected regions of open circuit defects are often elongated, with an aspect ratio R > 5; void defects are often nearly circular, with an aspect ratio R ≈ 1.

[0101] The roundness parameter refers to the degree to which the shape of a connected region approximates a circle. The calculation formula is C=4πA / P², where A is the area, P is the perimeter, and π is 3.1416. The roundness C ranges from 0 to 1. The closer the value is to 1, the closer the region is to an ideal circle. The smaller the value is, the more irregular the shape of the region. For example, the roundness C of a void defect is approximately 0.8-0.9, and the roundness C of a burr defect is approximately 0.2-0.4.

[0102] The label number, area A, perimeter P, aspect ratio R, and circularity C of each connected region are integrated in a structured format to generate a set of region morphological feature parameters. Each parameter is retained to two decimal places, and the parameter set is stored in tabular form to facilitate subsequent threshold filtering and feature comparison.

[0103] The set of regional morphological feature parameters is filtered according to the preset threshold range of suspected defect morphology. Regions that do not conform to the typical defect morphology features are eliminated, and candidate regions with suspected defect features are retained. The centroid coordinates and contour point sequence of each candidate region are recorded to generate a candidate region set.

[0104] The core of this step is to set reasonable parameter threshold ranges based on the morphological patterns of typical PCB defects, filter out connected regions that meet the defect characteristics, and extract key spatial information of the regions to generate a structured set of candidate regions. The specific implementation method is as follows:

[0105] The preset threshold range for suspected defect morphology is derived statistically from the morphological characteristics of four typical PCB defects: short circuit, open circuit, void, and burr. The threshold range balances defect diversity and discriminability, specifically set as follows: Area A ∈ [5, 1000] pixels² (eliminating minor interference of <5 pixels and large-area anomalies of >1000 pixels, the latter often caused by image acquisition failure); Aspect R ∈ [0.1, 10] (covering near-circular defects with R≈1 and elongated defects with R≈10); Circularity C ∈ [0.2, 0.95] (eliminating interference with excessively irregular shapes (C<0.2) and excessively idealized noise (C>0.95). The threshold range can be flexibly adjusted according to different PCB specifications and defect types to ensure targeted screening.

[0106] During the screening process, the morphological parameters of each connected region are compared with the preset threshold range. If all four parameters of a region are within the threshold range, it is determined to be a candidate region with suspected defect features; if any parameter exceeds the range, it is determined to be an invalid interference region and is removed. For example, the parameters of a connected region are A=25 pixels², R=6.2, and C=0.3, all within the threshold range, and it is determined to be a candidate region; another region has A=3 pixels², which exceeds the lower limit of the area threshold, and is determined to be an interference region and is removed.

[0107] For the retained candidate regions, their centroid coordinates and contour point sequences are further recorded. The centroid coordinates (x_c, y_c) are the average of all pixel coordinates in the region, calculated using the formulas x_c = (x_1 + x_2 + ... + x_n) / n and y_c = (y_1 + y_2 + ... + y_n) / n, where (x_1, y_1) to (x_n, y_n) are the coordinates of all pixels within the region. The centroid coordinates accurately represent the center position of the candidate region. For example, the centroid coordinates of a candidate region are (522, 312), corresponding to its specific location on the PCB board. The contour point sequence is a set of pixel coordinates of the candidate region's boundary contour arranged in clockwise order, which can completely represent the boundary shape of the region. For example, the contour point sequence of a region may contain coordinates such as (520, 310), (521, 310), and (525, 315).

[0108] Finally, the label numbers, centroid coordinates, contour point sequences, and four morphological parameters of all candidate regions are structurally integrated to generate a candidate region set. This set is structured data in JSON format, with each candidate region being an independent data object containing complete spatial location and morphological feature information, providing an accurate analysis object for subsequent defect classification.

[0109] S204, the candidate region set is input into a classification model based on the physical causes of defects. By comparing the reflection characteristics and geometric features corresponding to different defect types, the defect category of each candidate region is determined and the detection result is output.

[0110] Specifically, the gray value sequence and geometric parameters of each candidate region in the multi-angle illumination image can be extracted from the candidate region set and combined into a feature vector to be classified.

[0111] The core of this step is to accurately extract two types of core feature information from the selected candidate region set: a multi-angle gray value sequence that can characterize the optical reflection properties of the defect, and morphological parameters that can characterize the geometric shape of the defect. Through feature concatenation and normalization, a standardized feature vector to be classified that meets the input requirements of the classification model is generated. The specific implementation method is as follows:

[0112] First, the grayscale value sequence of the candidate region under multi-angle illumination is extracted. The multi-angle illumination image sequence contains grayscale images registered under 12 different illumination angles. Each candidate region corresponds to a fixed set of pixel coordinates and contour point sequence in the original image. Taking the centroid coordinates of the candidate region as the center, the grayscale values ​​of all pixels within the contour range are extracted in the 12 illumination images. The arithmetic mean of the grayscale values ​​of all pixels in the region is taken to obtain the representative grayscale value of the candidate region under the corresponding illumination angle. All 12 illumination angles are traversed in turn to generate a grayscale value sequence of length 12. This sequence completely records the variation law of reflection intensity of the defect region under different illumination directions, and can accurately distinguish the optical reflection characteristics of different defects. For example, the grayscale value sequence of the short-circuit defect region is generally high and fluctuates gently, the grayscale value sequence of the open-circuit defect region is generally low and the variation range is small, and the grayscale value sequence of the void defect region will show the characteristics of low in the middle and high at the edge.

[0113] Subsequently, the geometric morphology parameters of the candidate region are extracted. The parameters directly adopt the four core indicators calculated during the candidate region generation process: area, perimeter, minimum bounding rectangle aspect ratio, and circularity. The area represents the total number of pixels in the candidate region, the perimeter represents the outline length of the region boundary, the minimum bounding rectangle aspect ratio reflects the stretching degree of the region, and the circularity reflects how close the region is to a standard circle. The four parameters describe the geometric shape of the defect from different dimensions and can effectively distinguish the morphological differences of different defects. For example, open circuit defects are mostly long strips with a large aspect ratio, void defects are mostly near-circular with a high circularity value, and burr defects are mostly irregular spikes with both aspect ratio and circularity in the medium range.

[0114] After extracting two types of features, all feature values ​​are normalized to eliminate computational biases caused by different feature dimensions and numerical ranges. The minimum-maximum normalization method is used to map the grayscale value sequence and morphological parameter values ​​to the range of 0 to 1. The normalized 12-dimensional grayscale value sequence and the 4-dimensional geometric morphological parameters are then horizontally concatenated sequentially to form a 16-dimensional feature vector to be classified. Each dimension of the vector corresponds to a standardized feature value, and each candidate region corresponds to a unique 16-dimensional feature vector. This vector simultaneously integrates the optical reflection characteristics and geometric morphological characteristics of the defect and can be directly input into the defect classification model to complete the category determination.

[0115] The pre-trained defect classification model is invoked. This model is built based on the physical reflection mechanism and morphological features of various defects and includes feature templates for typical defect types such as short circuit, open circuit, void, and burr.

[0116] The core of this step is to load and call a dedicated classification model based on the physical causes of defects. The model is trained based on the optical reflection and geometric morphology of real PCB defects and has built-in standardized feature templates for four types of typical defects, providing a stable and reliable judgment benchmark for the accurate classification of candidate regions. The specific implementation method is as follows:

[0117] The defect classification model is based on the physical causes and optical characteristics of PCB defects. Short-circuit defects are formed by abnormal adhesion of adjacent copper foil lines. Physically, this is characterized by an abnormally large copper foil area. Reflective characteristics show that the overall grayscale value is high from multiple angles and close to the reflection curve of normal copper foil. Morphological characteristics show that it is an irregular block shape with a small aspect ratio. Open-circuit defects are formed by broken or missing copper foil lines. Physically, this is characterized by discontinuous copper foil and exposed substrate. Reflective characteristics show that the overall grayscale value is low from multiple angles and close to the reflection curve of the substrate. Morphological characteristics show that it is a thin strip shape with a large aspect ratio. Void defects are formed by insufficient etching of copper foil in certain areas. Physically, this is characterized by circular or near-circular missing areas of copper foil. Reflective characteristics show that the grayscale value is low in the center and high at the edge. Morphological characteristics show that it is near-circular with a high degree of roundness. Burr defects are formed by residual etching at the edge of copper foil. Physically, this is characterized by small, sharp burr-like protrusions at the edge of the line. Reflective characteristics show that the grayscale value fluctuates greatly. Morphological characteristics show that it is an irregular, thin strip shape with a low degree of roundness.

[0118] During the training phase, the model collected a large number of labeled real-world defect samples, covering PCB boards of different specifications and processes. A 16-dimensional feature vector was extracted for each type of defect sample. Standardized feature templates for each defect type were generated through cluster analysis. Each template is the mean vector of the feature vectors of all samples in that defect type, representing the typical characteristics of that type of defect. The four defect templates are independent of each other and have significant feature differences, effectively avoiding confusion during classification. The model uses a support vector machine (SVM) as its classifier, employing a radial basis function (RBF) kernel to perform nonlinear partitioning of the high-dimensional feature space. During training, cross-validation was used to optimize the kernel function parameters and penalty coefficients, improving the model's classification accuracy and generalization ability. After training, the model is saved as a standardized model file containing all information, including the four defect feature templates, kernel function parameters, and classification decision boundaries, which can be directly loaded and used.

[0119] When the model is called, the model file is loaded and initialized through the system interface. During the initialization process, the feature template is read and the classifier parameters are configured to ensure that the model is in a stable running state. The model input port matches the 16-dimensional feature vector to be classified, and the output port is the matching probability and category determination result of four types of defects. The model runs without manual intervention and can automatically complete feature comparison and category determination.

[0120] The feature vector to be classified is input into the classification model, and the support vector machine classifier is used to calculate its matching probability with each defect type template, generating the preliminary defect category determination result for each candidate region;

[0121] The core of this step is to use a support vector machine (SVM) classifier to calculate the similarity between the feature vector to be classified and the defect feature template. This similarity is then converted into a standardized matching probability. Based on the maximum probability, the defect category of the candidate region is determined, generating a preliminary category determination result. The specific implementation is as follows:

[0122] Each candidate region's corresponding 16-dimensional feature vector is input into the initialized defect classification model. The model uses a support vector machine classifier to calculate the Euclidean distance between the feature vector and the four types of defect feature templates. The smaller the Euclidean distance, the higher the feature similarity, and the greater the probability that the candidate region belongs to the corresponding defect category. The Euclidean distance is calculated as d = √[(x_1-t_1)² + (x_2-t_2)² + ... + (x_16-t_16)²], where x_1 to x_16 are the values ​​of each dimension of the feature vector to be classified, t_1 to t_16 are the values ​​of each dimension of a certain type of defect feature template, and d is the distance between the feature vector and the template.

[0123] The classifier converts the calculated Euclidean distance into a matching probability between 0 and 1 using the Softmax function. The sum of the matching probabilities of the four defect types is 1. The Softmax function can convert the distance value into a statistically significant probability value. The higher the probability value, the higher the confidence that the candidate region belongs to the corresponding defect category. For example, if the matching probabilities of the feature vector of a candidate region with the four template types of short circuit, open circuit, void, and burr are 0.05, 0.10, 0.15, and 0.70, respectively, then the region has the highest matching degree with the burr defect.

[0124] The classifier iterates through the matching probabilities of four defect types and selects the category with the highest probability value as the preliminary defect category for the candidate region, thus completing the preliminary category determination. The preliminary defect category determination result contains three core pieces of information: the unique ID of the candidate region, the preliminary determined defect category, and the matching probabilities corresponding to the four defect types. The results are stored in structured data format, with each candidate region corresponding to an independent determination record. For example, the candidate region with ID 3 has a preliminary determined category of short circuit, and the probabilities of the four categories are 0.82, 0.08, 0.06, and 0.04, respectively. The preliminary determination result is based only on the classification calculation of a single set of feature vectors and has not undergone confidence and consistency verification, so there is a small possibility of false positives. Further optimization and screening are needed in subsequent steps.

[0125] The initial defect category determination results are evaluated for confidence level. False detection areas with confidence levels below the preset confidence threshold are eliminated. Information from multiple perspectives is integrated for consistency verification. Finally, a complete detection result containing defect category, location coordinates, and confidence level is output.

[0126] The core of this step is to eliminate false positives and low-reliability judgments through confidence screening and multi-angle consistency verification, retain true and valid defect judgment information, and finally generate standardized inspection results containing complete information to achieve accurate identification and output of PCB defects. The specific implementation method is as follows:

[0127] First, a confidence assessment is conducted. The highest matching probability in the preliminary defect category determination results is used as the confidence level for that category. The confidence level ranges from 0 to 1, with values ​​closer to 1 indicating a more reliable determination. A preset confidence threshold of 0.7 is set. This threshold was determined through extensive sample testing to effectively balance the false negative and false positive rates. The preliminary determination results of all candidate regions are iterated. If the confidence level of a region is greater than or equal to 0.7, the determination result is retained. If the confidence level is less than 0.7, the region is determined to be a false positive region and removed from the candidate region set, no longer participating in subsequent processing. For example, if the confidence level of a candidate region is 0.65, which is below the threshold, it is determined to be an interference region and removed. If the confidence level of a candidate region is 0.85, which is above the threshold, the valid determination result is retained.

[0128] Subsequently, a consistency check is performed using multi-angle information fusion. Based on the multi-angle illumination image sequence, sub-feature vectors of the same candidate region under different illumination angles are extracted and input into the classification model to obtain independent category determination results. The verification rule is that if the determination results under more than 8 illumination angles are consistent with the preliminary determination category, the determination result passes the consistency check; if the number of consistent angles is less than 8, the determination result is ambiguous, marked as a region to be reviewed, and removed. The consistency check makes full use of the redundant information of multi-angle illumination, effectively avoiding misjudgments caused by single-angle illumination deviations, and improving the stability and reliability of the detection results.

[0129] After completing the confidence assessment and consistency verification, the retained valid defect results are integrated. The integrated information includes defect category, centroid coordinates, contour point sequence, and judgment confidence level. The defect category is one of the four final confirmed types: short circuit, open circuit, void, and burr. The centroid coordinates and contour point sequence accurately locate the defect on the PCB board. The confidence level represents the reliability of the final judgment. All information is organized in a standardized format to generate complete PCB defect detection results. The detection results are output as structured data and can also generate visually annotated images. Different colors are used to mark the location and boundaries of various defects on the original PCB image, facilitating intuitive viewing by operators. The final output detection results are complete, accurate, and reliable, meeting the practical application needs of intelligent PCB defect detection in industrial scenarios.

[0130] Another embodiment of the present invention provides an intelligent PCB defect detection system based on image recognition, see [link to relevant documentation]. Figure 3 The system may include:

[0131] The acquisition module 301 is used to illuminate the area to be tested on the PCB board from multiple angles through an adjustable ring light source, and simultaneously acquire the reflection image under each illumination angle to construct an image sequence of different illumination directions under the same field of view.

[0132] The extraction module 302 is used to perform pixel-level reflectance characteristic analysis on the image sequence, calculate the gray value change law of each pixel under multi-angle illumination, and extract abnormal pixels that deviate from the normal copper foil and substrate reflectance characteristics.

[0133] The filtering module 303 is used to filter out candidate regions with suspected defect features through connected component analysis based on the spatial distribution and morphological characteristics of the abnormal pixels, and generate a set of candidate regions containing location and boundary information.

[0134] The output module 304 is used to input the candidate region set into a classification model based on the physical causes of defects, and to determine the defect category of each candidate region by comparing the reflection characteristics and geometric features corresponding to different defect types and output the detection results.

[0135] This invention also provides a storage medium storing a computer program, wherein the computer program is configured to execute the steps in any of the above method embodiments when running.

[0136] This invention also provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the steps in any of the above method embodiments.

[0137] Specifically, the aforementioned electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the aforementioned processor, and the input / output device is connected to the aforementioned processor.

[0138] The above description, based on the embodiments shown in the figures, details the structure, features, and effects of the present invention. The above description is only a preferred embodiment of the present invention, but the present invention is not limited to the scope of implementation shown in the figures. Any changes made in accordance with the concept of the present invention, or equivalent embodiments modified to have equivalent changes, that do not exceed the spirit covered by the specification and figures, should be within the protection scope of the present invention.

Claims

1. A method for intelligent PCB defect detection based on image recognition, characterized in that, The method includes: An adjustable-angle ring light source illuminates the area under test of the PCB board from multiple angles, and the reflected images at each illumination angle are acquired simultaneously to construct an image sequence of different illumination directions under the same field of view. The image sequence is subjected to pixel-level reflectance characteristic analysis. The gray value change pattern of each pixel under multi-angle illumination is calculated, and abnormal pixels that deviate from the normal reflectance characteristics of copper foil and substrate are extracted. Based on the spatial distribution and morphological characteristics of the abnormal pixels, candidate regions with suspected defect features are selected through connected component analysis, and a set of candidate regions containing location and boundary information is generated. The candidate region set is input into a classification model based on the physical causes of defects. By comparing the reflection characteristics and geometric features corresponding to different defect types, the defect category of each candidate region is determined and the detection results are output.

2. The method according to claim 1, characterized in that, The process involves illuminating the PCB board test area from multiple angles sequentially using an adjustable-angle ring light source, and simultaneously acquiring reflection images at each illumination angle to construct an image sequence of different illumination directions within the same field of view, including: The PCB board is precisely fixed in the center of the stage, and the initial illumination angle of the ring light source is set to the preset starting position through the controller to generate the initial angle parameters of the light source. Based on the initial angle parameters of the light source, the ring light source is driven to rotate sequentially at fixed step angles. At each angle position, the industrial camera is triggered to expose synchronously, and the reflected light image of the area to be tested on the PCB board is acquired to generate the original set of reflected images. Feature point matching and image registration are performed on the original set of reflection images. The phase correlation algorithm is used to eliminate the tiny pixel shifts caused by mechanical motion, ensuring that all images are aligned in the same pixel coordinate system, and generating a registered image sequence. Each image in the registered image sequence is labeled with a corresponding illumination angle, and then arranged and integrated in ascending order of angle to finally construct a complete multi-angle illumination image sequence.

3. The method according to claim 2, characterized in that, The step of performing pixel-level reflectance characteristic analysis on the image sequence, calculating the grayscale value variation pattern of each pixel under multi-angle illumination, and extracting abnormal pixels that deviate from the normal reflectance characteristics of copper foil and substrate includes: The gray values ​​of all illumination angles are extracted pixel by pixel from the multi-angle illumination image sequence. A response curve is established for each pixel with the illumination angle as the independent variable and the gray value as the dependent variable, generating a pixel-level reflectance characteristic dataset. Load the pre-established standard reflection feature library of normal copper foil and substrate, and calculate the similarity between the response curve of each pixel and the standard curve based on the pixel-level reflection characteristic dataset. Use the dynamic time warping algorithm to measure the degree of deviation and generate a set of pixel deviation measurement values. An adaptive threshold is set based on the statistical distribution of the set of pixel deviation values. Pixels with deviation values ​​exceeding the adaptive threshold are marked as abnormal candidate points, and an initial set of abnormal pixels is generated. The initial set of anomalous pixels is processed by morphological opening to eliminate isolated noise and minor interference, retaining anomalous pixels with physical continuity, and generating the final set of anomalous pixels.

4. The method according to claim 3, characterized in that, Based on the spatial distribution and morphological characteristics of the abnormal pixels, candidate regions with suspected defect features are selected through connected component analysis, and a set of candidate regions containing location and boundary information is generated, including: The final set of abnormal pixels is mapped back to the original image coordinate space to construct a binary abnormal pixel distribution map. The abnormal pixel distribution map is processed by the eight-neighbor connected region labeling algorithm, which combines adjacent abnormal pixels into independent connected regions to generate a connected region labeling map. Traverse each connected region in the connected region label graph, calculate the geometric morphological parameters including its area, perimeter, aspect ratio of the minimum bounding rectangle, and roundness, and generate a set of region morphological feature parameters; The set of regional morphological feature parameters is filtered according to the preset threshold range of suspected defect morphology. Regions that do not conform to the typical defect morphology features are eliminated, and candidate regions with suspected defect features are retained. The centroid coordinates and contour point sequence of each candidate region are recorded to generate a candidate region set.

5. The method according to claim 4, characterized in that, The process of inputting the candidate region set into a classification model based on the physical causes of defects, and determining the defect category of each candidate region by comparing the reflection characteristics and geometric features corresponding to different defect types, and outputting the detection results includes: Extract the gray value sequence and geometric parameters of each candidate region in the multi-angle illumination image from the candidate region set, and combine them into a feature vector to be classified. The pre-trained defect classification model is invoked. This model is built based on the physical reflection mechanism and morphological features of various defects and includes feature templates for typical defect types such as short circuit, open circuit, void, and burr. The feature vector to be classified is input into the classification model, and the support vector machine classifier is used to calculate its matching probability with each defect type template, generating the preliminary defect category determination result for each candidate region; The initial defect category determination results are evaluated for confidence level. False detection areas with confidence levels below the preset confidence threshold are eliminated. Information from multiple perspectives is integrated for consistency verification. Finally, a complete detection result containing defect category, location coordinates, and confidence level is output.

6. A PCB defect intelligent detection system based on image recognition, characterized in that, The system includes: The acquisition module is used to illuminate the area under test of the PCB board from multiple angles through an adjustable ring light source, and simultaneously acquire the reflection image at each illumination angle to construct an image sequence of different illumination directions under the same field of view. The extraction module is used to perform pixel-level reflectance characteristic analysis on the image sequence, calculate the gray value change pattern of each pixel under multi-angle illumination, and extract abnormal pixels that deviate from the normal reflectance characteristics of copper foil and substrate. The filtering module is used to filter out candidate regions with suspected defect features through connected component analysis based on the spatial distribution and morphological characteristics of the abnormal pixels, and generate a set of candidate regions containing location and boundary information. The output module is used to input the candidate region set into a classification model based on the physical causes of defects, and to determine the defect category of each candidate region by comparing the reflection characteristics and geometric features corresponding to different defect types and output the detection results.

7. The system according to claim 6, characterized in that, The acquisition module is specifically used for: The PCB board is precisely fixed in the center of the stage, and the initial illumination angle of the ring light source is set to the preset starting position through the controller to generate the initial angle parameters of the light source. Based on the initial angle parameters of the light source, the ring light source is driven to rotate sequentially at fixed step angles. At each angle position, the industrial camera is triggered to expose synchronously, and the reflected light image of the area to be tested on the PCB board is acquired to generate the original set of reflected images. Feature point matching and image registration are performed on the original set of reflection images. The phase correlation algorithm is used to eliminate the tiny pixel shifts caused by mechanical motion, ensuring that all images are aligned in the same pixel coordinate system, and generating a registered image sequence. Each image in the registered image sequence is labeled with a corresponding illumination angle, and then arranged and integrated in ascending order of angle to finally construct a complete multi-angle illumination image sequence.

8. The system according to claim 7, characterized in that, The extraction module is specifically used for: The gray values ​​of all illumination angles are extracted pixel by pixel from the multi-angle illumination image sequence. A response curve is established for each pixel with the illumination angle as the independent variable and the gray value as the dependent variable, generating a pixel-level reflectance characteristic dataset. Load the pre-established standard reflection feature library of normal copper foil and substrate, and calculate the similarity between the response curve of each pixel and the standard curve based on the pixel-level reflection characteristic dataset. Use the dynamic time warping algorithm to measure the degree of deviation and generate a set of pixel deviation measurement values. An adaptive threshold is set based on the statistical distribution of the set of pixel deviation values. Pixels with deviation values ​​exceeding the adaptive threshold are marked as abnormal candidate points, and an initial set of abnormal pixels is generated. The initial set of anomalous pixels is processed by morphological opening to eliminate isolated noise and minor interference, retaining anomalous pixels with physical continuity, and generating the final set of anomalous pixels.

9. A storage medium, characterized in that, The storage medium stores a computer program, wherein the computer program is configured to execute the method of any one of claims 1-5 when it is run.

10. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the method of any one of claims 1-5.