A few-sample PCB defect detection method and system
By combining local adaptive thresholding and probabilistic convolutional networks with morphological processing, the problem of high-frequency false alarms in the detection of small defects under conditions of few samples is solved, and efficient defect identification and localization are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- PINGDINGSHAN UNIVERSITY
- Filing Date
- 2026-06-08
- Publication Date
- 2026-07-31
AI Technical Summary
Existing technologies cannot effectively distinguish between accurate afterimages and high-frequency false alarms caused by sudden changes in illumination under conditions of few samples, resulting in high rates of missed detection and false alarms in the detection of minute defects.
A local adaptive threshold is generated by using the local gray-level mean and the global basic illumination constant. The absolute difference map is then binarized, and the defect probability response value is extracted by a probabilistic convolutional network. Combined with morphological closing operation and binary masking, the defect judgment is refined.
It enables accurate identification of minute defects under conditions of few samples, reduces the high-frequency false alarm rate, and improves the reliability and accuracy of detection.
Smart Images

Figure CN122492676A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of PCB defect detection, and in particular to a method and system for detecting defects in a small number of PCB samples. Background Technology
[0002] Printed circuit boards undergo online optical re-inspection at downstream stations in mass assembly lines. These stations feed back defect coordinates upstream at fixed intervals, triggering rework routing. The frequency of production line changes and the physical constraints of small-batch customized orders compress the number of compatible images of the same model available for training or modeling to only a few dozen. The lens's field of view is constantly exposed to high-frequency micro-vibrations from the conveyor mechanism, slight warping due to residual thermal expansion of the substrate, and localized spot drift of the top-light ring source caused by the vibration of reflectors at adjacent stations.
[0003] Chinese invention patent application CN121639582A discloses a high-precision defect detection system based on image difference and thresholding. This scheme uses shape features to complete affine registration between a reference image and the image to be tested. A fixed mask is transformed into a dynamic mask through geometric mapping. Within the mask's defined range, the registered image undergoes preprocessing for edge strength and width. The difference detection stage performs local motion difference on the preprocessed image and multiple reference images, and outputs a difference response map by recursively fusing the reference domain and time domain, thereby extracting candidate region priors. The correction stage estimates the local displacement field based on the candidate regions and performs bending correction and coordinate mapping on the preprocessed image. Within the corrected effective judgment region, joint thresholding of grayscale and color is performed, and a defect set is output after verification using connected component rules.
[0004] Affine transformations, with only six degrees of freedom, cannot absorb perspective distortion caused by unilateral clamping of the substrate. The traces on the clamped side retain a sub-pixel-level lateral offset after correction. This offset is amplified into a high-contrast afterimage band extending along the trace contour during pixel-by-pixel subtraction. The temporal recursive fusion of multiple reference images, supported by long sequences of good product historical frames, suffers from a baseline that fails to converge to a stable illumination background when the sample size is compressed to dozens of images. The instantaneous drift of the ring light source directly enters the low-frequency components of the differential response map, raising its global baseline. Subsequent gray-color joint thresholding is performed independently at the pixel level, lacking independent weighted channels for neighborhood spatial evidence. Gray-level steps in the afterimage band and color shifts in sudden light spots on the board surface are allowed to proceed equally under the same threshold. Connectivity growth spreads along the afterimage band towards the actual solder joint, causing the defect circumscribed coordinates to deviate from the actual pad geometry. Isolated light spot pixels are included in the candidate set, forming dense false alarm points. The inseparability of afterimages, light spots, and micro-defects under the same scalar criterion makes it impossible for this scheme to simultaneously reduce the false alarm rate and the missed detection rate in high-cycle workstations with few samples. Summary of the Invention
[0005] To address the high-frequency false alarms induced by registration ghosting and sudden changes in illumination, and to achieve accurate and independent identification of minute defects, this application provides a method and system for detecting PCB defects using a small sample size.
[0006] Firstly, this application provides a method for detecting defects in a small sample PCB, employing the following technical solution: A method for detecting defects in a small sample PCB, comprising:
[0007] Extract the core areas of the standard PCB and the PCB under test, and generate reference images and images under test respectively;
[0008] The image to be tested is geometrically corrected, and the absolute difference map with the reference image is calculated. The absolute difference map is divided into pixel sub-blocks, and the local gray-level mean of each pixel sub-block is added to a preset global base illumination constant to generate a local adaptive threshold. The absolute difference map is binarized according to the local adaptive threshold corresponding to the sub-block to which each pixel belongs to generate a binary mask, and the binary mask is ANDed with the absolute difference map to obtain a clean difference map.
[0009] The pure difference map is input into a preset probabilistic convolutional network, and spatial features are extracted by a pre-convolutional layer and mapped by a single-channel core convolutional layer with non-negative constraints, and an initial probability map is output. The weights of the single-channel core convolutional layer are truncated to the non-negative half axis by a truncation operator, and the probabilistic convolutional network is trained based on a composite loss function that includes a weighted sparse loss term. Each pixel value of the initial probability map independently represents the probability response value of the defect.
[0010] A morphological closing operation is performed on the binary mask to generate a closing operation mask, and the closing operation mask is multiplied pixel by pixel with the initial probability map to generate a refined probability map; connected components are extracted from the refined probability map, and the average value of the probability response values of all pixels in each connected component is calculated. When the average value is greater than a preset judgment threshold, the corresponding connected component is determined to be a real defect and the location information is output.
[0011] Optionally, before extracting the core areas of the standard PCB and the PCB under test and generating the reference image and the image under test respectively, the original acquired images of the standard PCB and the PCB under test are obtained and smoothing filtering is performed to generate the denoised reference image and the denoised image under test respectively.
[0012] The process of extracting the core regions of the standard PCB and the PCB under test, and generating corresponding reference and test images, includes:
[0013] The preset physical fixture shielding mask is mapped onto the denoised reference image and the denoised test image respectively to mask the non-circuit area, and the unmasked area is extracted and output as the reference image and the test image respectively.
[0014] Optionally, the geometric correction of the image to be tested includes:
[0015] Based on a preset response difference threshold, the corner points of the reference image and the image under test are extracted and feature descriptors are generated by combining the gray-scale centroid direction;
[0016] Calculate the response distance between each feature descriptor, and extract the matching pairs whose response distance is not greater than a preset distance threshold as valid matching pairs;
[0017] The homography matrix is estimated based on the effective matching pairs, and perspective transformation is performed on the image under test using the homography matrix.
[0018] Optionally, before estimating the homography matrix based on the effective matching pairs:
[0019] When the number of valid matching pairs is less than a preset point threshold, the response difference threshold is reduced by a preset proportional constant, and the reduced response difference threshold is not lower than a preset minimum threshold. The corner points are then extracted again based on the reduced response difference threshold to update the valid matching pairs until the number of updated valid matching pairs is not less than the point threshold, or a retest signal is triggered when the number of iterations reaches a preset iteration limit.
[0020] Optionally, dividing the absolute difference map into pixel sub-blocks includes:
[0021] Based on the physical mapping relationship between the target trace width and imaging resolution of the standard PCB, the spatial size specifications are determined, and the absolute difference map is divided into grids according to the spatial size specifications to generate each pixel sub-block.
[0022] The preset global base illumination constant is the illumination offset baseline calculated based on the global differential statistics of the defect-free verification board.
[0023] Optionally, the step of inputting the pure difference map into a preset probabilistic convolutional network, sequentially extracting spatial features through a pre-convolutional layer, and mapping through a single-channel core convolutional layer with non-negative constraints, includes:
[0024] Local spatial texture context features of the pure difference map are extracted through the preceding convolutional layer with a depthwise separable convolutional structure;
[0025] The local spatial texture context features are input into the single-channel core convolutional layer to perform dimensionality reduction mapping, and non-negative probability response values are extracted based on non-negative activation constraints to generate the initial probability map.
[0026] Optionally, the method further includes a step of pre-training the probabilistic convolutional network, comprising: acquiring training samples containing pixel-level defect labels; calculating the weighted sparse loss term based on the weight parameters of the single-channel core convolutional layer, and calculating a defect pixel recall loss term and a non-defect pixel suppression loss term based on the sample probability map output after inputting the training samples into the probabilistic convolutional network, combined with the probability response values of the sample defect region and background region divided by the pixel-level defect labels; weighting and summing the weighted sparse loss term, the defect pixel recall loss term, and the non-defect pixel suppression loss term according to a preset ratio to construct the composite loss function, and using the composite loss function to backpropagate and update the parameters of the probabilistic convolutional network.
[0027] Optionally, the step of performing a morphological closing operation on the binary mask to generate a closing operation mask, and multiplying the closing operation mask pixel-by-pixel with the initial probability map to generate a refined probability map, includes:
[0028] Based on the preset structural elements, the binary mask is sequentially subjected to dilation and erosion operations to stitch up the broken pixels, thereby generating the closing operation mask;
[0029] The closing operation mask is multiplied pixel-by-pixel with the initial probability map, and the probability response values not covered by the closing operation mask are set to zero to output the fine probability map.
[0030] Optionally, after calculating the average of the probability response values of all pixels within each connected component: when the average value is between the judgment threshold and the preset lower limit, extract the coordinates of the bounding rectangle corresponding to the connected component, and extract the original pixel block from the geometrically corrected image based on the bounding rectangle coordinates; input the original pixel block into a preset secondary classification network, and determine for the second time whether the connected component is a real defect based on the classification confidence output by the secondary classification network.
[0031] Secondly, this application provides a few-sample PCB defect detection system, which adopts the following technical solution: A few-sample PCB defect detection system, comprising:
[0032] The image extraction module is used to extract the core areas of the standard PCB and the PCB under test, and generate reference images and images under test respectively.
[0033] The difference processing module is used to perform geometric correction on the image to be tested and calculate the absolute difference map with the reference image; divide the absolute difference map into pixel sub-blocks, add the local gray-level mean of each pixel sub-block to a preset global base illumination constant to generate a local adaptive threshold; binarize the absolute difference map according to the local adaptive threshold corresponding to the sub-block to which each pixel belongs to generate a binary mask, and perform an AND operation between the binary mask and the absolute difference map to obtain a clean difference map;
[0034] The probabilistic inference module is used to input the pure difference map into a preset probabilistic convolutional network, extract spatial features through a pre-convolutional layer, and map through a single-channel core convolutional layer with non-negative constraints to output an initial probability map. The weights of the single-channel core convolutional layer are truncated to the non-negative half-axis by a truncation operator, and the probabilistic convolutional network is trained based on a composite loss function that includes a weighted sparse loss term. Each pixel value of the initial probability map independently represents the probability response value of the defect.
[0035] The defect determination module is used to perform morphological closing operations on the binary mask to generate a closing operation mask, and multiply the closing operation mask with the initial probability map pixel by pixel to generate a fine probability map; extract the connected components in the fine probability map, calculate the average value of the probability response values of all pixels in each connected component, and when the average value is greater than a preset determination threshold, determine that the corresponding connected component is a real defect and output the location information.
[0036] In summary, this application includes the following beneficial technical effects:
[0037] 1. A local adaptive threshold is generated based on the sum of the local gray-level mean and the global base illumination constant, and the absolute difference is then applied. Figure 2 After valueization, an AND operation is performed with the absolute difference map to obtain a clean difference map. The clean difference map is then input into a probabilistic convolutional network to output the independent defect probability response value of each pixel. After a morphological closing operation is performed on the binary mask, it is multiplied pixel by pixel with the initial probability map. The sum of the probability response values in the connected domain is used to determine the real defect. The registration afterimage and the false alarm pixels caused by the sudden change in illumination are separated in the probability domain, which realizes the accurate identification of small defects and reduces high-frequency false alarms.
[0038] 2. In geometric correction, when the number of effective matching pairs is insufficient, the corner response difference threshold is lowered and corner points are extracted again in a loop to update the matching pairs until the number reaches the standard or the iteration limit is reached. In the case of weak texture or few samples, enough matching pairs can still be obtained, which ensures the robustness of homography matrix estimation and avoids perspective transformation failure caused by insufficient registration points.
[0039] 3. For connected components whose sum of probability response values falls between the judgment threshold and the preset lower limit, the original pixel block corresponding to the bounding rectangle is extracted and input into the secondary classification network for secondary judgment. The classification confidence is used to verify the suspicious connected components. This reduces the trade-off between missed detections and false alarms without significantly increasing computational overhead, thus improving the reliability of defect detection results. Attached Figure Description
[0040] Figure 1 A flowchart of a few-sample PCB defect detection method provided in an embodiment of the present invention;
[0041] Figure 2 A schematic diagram illustrating the principle of the core region extraction process provided in this embodiment of the invention;
[0042] Figure 3 This is a schematic diagram illustrating the principle of absolute difference graph mesh division provided in an embodiment of the present invention. Detailed Implementation
[0043] The following combination Figures 1-3 This application will be described in further detail.
[0044] This embodiment discloses a method for detecting defects in PCBs with a small sample size, and the execution logic framework is as follows: Figure 1 As shown, the method specifically includes the following steps:
[0045] S1: Image Acquisition and Core Region Extraction
[0046] When the I / O level of the photoelectric pair at the workstation transitions from low to high, the image acquisition trigger outputs a hardware external trigger pulse to the area array CMOS camera with a microsecond delay. The coaxial ring-shaped white light is synchronously selected on the rising edge of the pulse, and the light source illuminance is locked within ±2% of the calibrated value by the constant current driver. The camera uses a global shutter mode with an exposure time locked at 800μs. One image is acquired each time the standard PCB and the PCB under test are positioned sequentially. The original image resolution is no less than 2448×2048, with a single pixel physical mapping of approximately 0.02mm. The original image is smoothed using a 3×3 Gaussian kernel with a standard deviation of 0.8, outputting a denoised reference image and a denoised test image. If the image acquisition module fails to transmit two original images within the preset image acquisition cycle, the trigger sends a retest signal for this batch to the host computer and skips the subsequent processes for this frame.
[0047] The physical fixture shielding mask is stored as an unsigned 8-bit single-channel bitmap, where a value of 255 represents the circuit area and a value of 0 represents the shielding area. Combined with... Figure 2As shown in the mapping topology, the denoised reference image and the denoised test image are used as independent image path inputs. The physical fixture mask is used as a common masking matrix and superimposed onto the denoised reference image and the denoised test image by bitwise AND operation. The pixels in the non-circuit area at the corner of the masking bit are forced to zero, while the pixel grayscale of the core circuit area in the middle is preserved as is. The superposition result is output as the reference image and the test image.
[0048] S2: Iterative Feature Registration and Adaptive Sub-Block Differentiation
[0049] The reference image and the image to be tested are respectively fed into the FAST corner detection window. The detection window scans a Bresenham discrete circle with a radius of 3 pixels centered on the candidate pixel, and samples 16 neighboring pixels sequentially along the circle. When the number of consecutive neighboring pixels whose absolute value of the gray level difference with the center pixel is greater than the response difference threshold is not less than 9, the candidate pixel is confirmed as a corner. The initial value of the response difference threshold is 20 gray levels. The first moment of the gray level of the 31×31 neighboring pixels of the corner is used to calculate the centroid vector, and the angle between the centroid vector and the corner is taken as the principal direction. The 256 pre-generated pairs of pixel sampling positions are rotated as a whole along the principal direction, and binary gray level comparison is performed on each pair to generate a 256-bit oriented BRIEF descriptor, which is merged with the corner coordinates to form ORB feature points. A brute-force matcher calculates the Hamming distance between each pair of feature descriptors on both sides. Matching pairs with a distance of no more than 64 are entered into the high-quality matching pair set. In the lightweight deployment scenario, this matcher is replaced by a KD-Tree-based nearest neighbor matcher, while the matching criteria remain unchanged. When the number of high-quality matching pairs is less than the point threshold of 30, the FAST response difference threshold is reduced by one level by multiplying it by the proportional constant 0.8, and the lower limit of the reduction is not lower than 5 gray levels. Based on the reduced threshold, the corner points are rescanned, the ORB features are reconstructed, and the matching is performed again. The loop is executed for a maximum of 5 rounds. If the number of matching pairs in any round meets the standard, the loop will be terminated. If all 5 rounds fail to meet the standard and the number of matching pairs in the last round is less than 4 pairs, the retest signal of this frame is sent back to the host computer and the subsequent process of this frame is terminated.
[0050] The coordinates of high-quality matching pairs are fed into the RANSAC estimator. In each iteration, four matching pairs are randomly selected to solve for a 3×3 homography matrix. This matrix reprojects the coordinates of the test side to the reference side, and the number of matching pairs with a reprojection residual of no more than 3 pixels is counted as the inlier count. After 500 iterations, the homography matrix with the largest number of inliers is retained. In scenarios where the quality gradient of the matching pairs is significant, the RANSAC estimator is replaced by the PROSAC estimator. This matrix performs perspective transformation on the test image, and the gray levels at the sampling locations are synthesized by bilinear interpolation or bicubic interpolation, outputting a corrected image.
[0051] The absolute value of the pixel-by-pixel grayscale difference between the corrected image and the reference image is taken to obtain an absolute difference image with the same resolution as the reference image. The standard PCB target trace width is 0.1mm, the imaging resolution is 0.02mm / pixel, a single trace occupies 5 pixels in width on the image, and the sub-block space size is set to 16×16 pixels. For example... Figure 3 As shown, the absolute difference map is divided into pixel sub-blocks by a 16×16 non-overlapping grid. Within the spatial grid of a single pixel sub-block, the extension trajectory along the target trace simultaneously includes trace pixels and surrounding base pixels. The aim is to ensure that pixel sub-blocks located in the trace edge region simultaneously include trace and base pixels.
[0052] The global baseline illumination constant is pre-calibrated using a defect-free verification board before production line startup: several absolute difference images of the verification boards are taken, and the global pixel mean μ and standard deviation σ are combined and statistically analyzed. μ+2σ is written into a parameter register with power-off retention properties as the global baseline illumination constant, with a typical value falling within the 3 to 8 gray level range. In long-term production line operation scenarios, the global baseline illumination constant is updated online by statistically analyzing the mean of the historical defect-free frame difference images using a sliding time window. The local gray level mean is obtained by summing pixels within a sub-block and dividing by 256, and then added to the global baseline illumination constant to obtain the local adaptive threshold for that sub-block.
[0053] In the absolute difference image, pixels with values greater than the local adaptive threshold of their sub-blocks are set to 1 at the corresponding positions in the binary mask, and vice versa. A pixel-by-pixel AND operation is performed between the binary mask and the absolute difference image. Differential pixels at mask positions of 0 are forced to zero, and the remaining non-zero grayscale values constitute the clean difference image. The clean difference image is fed into the probabilistic convolutional inference module, and the binary mask is fed into the cascaded decision module.
[0054] S3: Spatial Context Awareness and Independent Probability Mapping
[0055] The probabilistic convolutional inference module loads the clean difference map into GPU memory in a single-channel manner and feeds it into a pre-trained probabilistic convolutional network. The network's front layer is a 3×3 depthwise separable convolutional layer. The depthwise convolutional branch scans the local spatial neighborhood channel by channel with a 3×3 kernel, while the pointwise convolutional branch completes cross-channel linear combination with a 1×1 kernel. Batch normalization is applied after each layer, allowing the extracted local spatial texture context features to contain negative values. The output is a 16-channel local spatial texture context feature map with spatial resolution strictly aligned with the clean difference map. In scenarios prioritizing computing power, the number of channels in the front layer remains at 16; in scenarios with stricter power constraints, the number of channels in the front layer is reduced to 8.
[0056] A 16-channel context feature map is fed into the core convolutional layer. The core convolutional layer performs cross-channel fusion with a 1×1 kernel, inputting 16 channels and outputting 1 channel. All weights of the convolutional kernel are updated after each round of backpropagation, and then truncated element-wise according to W=max(0,W) to the non-negative half-axis. During forward computation, the core layer is equivalent to a weighted sum of non-negative weights, followed by a sigmoid activation to ensure the output falls within the probability interval [0,1]. The core layer outputs a single-channel initial probability map, with spatial resolution and purity difference. Figure 1 Each coordinate scalar value falls within the [0,1] interval, independently representing the probability response value that the pixel at that coordinate is a defect.
[0057] The probabilistic convolutional network was trained offline before production line deployment. The training set consisted of 60 good boards and 30 defective boards with pixel-level annotations, and data augmentation strategies including rotation, flipping, affine transformation, and brightness adjustment were used to augment the samples. Each defective board underwent S1 to S2 isomorphic preprocessing to obtain a clean difference image and a strictly registered 0 / 1 label image. The loss function consisted of a weighted sum of three terms: the first term was the L1 norm of all weights in the core 1×1 convolutional layer; the second term was the average of (1 - probability response value) at the pixel position with label 1; and the third term was the average of the probability response value at the pixel position with label 0. The weighting coefficients were 0.1:1.0:0.5, the Adam optimizer learning rate was initially set to 1e-3, and 200 iterations were performed until the loss curve reached a plateau. The network parameters were then frozen and loaded by the probabilistic convolutional inference module.
[0058] S4: Morphological closed-loop filtering and qualitative analysis of cascaded defects
[0059] The cascaded decision module integrates a binary mask and an initial probability map. The binary mask is first expanded using 3×3 rectangular structuring elements: if any pixel within the window is 1, the center pixel is set to 1, and connected components extend outwards by 1 pixel along their boundaries. Then, it is eroded using structuring elements of the same size: if all pixels within the window are 1, the center pixel is preserved, and connected components shrink inwards by 1 pixel along their boundaries. In scenarios with high trace density, the size of the rectangular structuring elements adaptively switches from 3×3 to 5×5. The cascaded expansion-erosion process bridges the 1-pixel-wide breaks within the binary mask caused by threshold conditions, outputting a closing operation mask.
[0060] The initial probability map is multiplied pixel by pixel with the closing operation mask. When the closing operation mask is 0, the probability response value of the corresponding coordinate in the initial probability map is reduced to zero, thus obtaining the refined probability map.
[0061] The refined probabilistic map extracts connected components according to the 8-neighborhood rule, and calculates the average probability response value of all pixels within each connected component. The judgment threshold is set to 0.5. Connected components with an average value greater than 0.5 are judged as real defects, and the coordinates of the upper left and lower right corners of their bounding rectangles are used as defect location information and output to the host computer's distribution module.
[0062] Connected components with an average value between the lower limit of 0.2 and the decision threshold of 0.5 enter the secondary decision channel: the coordinates of the bounding rectangle of the connected component are extracted, and the original grayscale pixel blocks are cropped on the corrected image according to the bounding rectangle coordinates. These blocks are then bilinearly scaled to 64×64 pixels and fed into the secondary classification network. The secondary classification network uses an improved MobileNetV3 as its backbone, with an input tensor shape of (1, 1, 64, 64). The fully connected layer at the end outputs the Softmax binary classification confidence scores for defects and non-defects. Parameters are obtained through offline training on the training set using binary cross-entropy loss, based on the connected component subgraphs. If the confidence score for the defect class is greater than 0.7, the connected component is added as a true defect; otherwise, it is discarded. If the cascaded decision module does not receive a response within the preset receipt window after sending the positioning information to the host computer, the positioning information for this frame is pushed back to the local buffer and a retest signal is triggered.
[0063] This application also discloses a few-sample PCB defect detection system. The few-sample PCB defect detection system includes an image extraction module, a differential processing module, a probabilistic inference module, and a defect determination module.
[0064] The image extraction module is communicatively coupled to the photoelectric trigger interface of the inspection station and the area array CMOS camera. It is configured to trigger image acquisition in response to the station's arrival level, receiving raw images of the standard PCB and the PCB under test. The raw images are then smoothed and filtered to obtain a denoised reference image and a denoised test image. A physical fixture shielding mask is then overlaid bit-by-bit onto the denoised reference image and the denoised test image. The core circuit region is extracted and output as the reference image and the test image, respectively. The image extraction module is also communicatively coupled to the host computer's feedback channel and is configured to send back a retest signal for the current batch when image acquisition timeout occurs or a downstream back-off command arrives.
[0065] The differential processing module is downstream coupled to the image extraction module and is configured to carry a FAST corner detector, a directional BRIEF descriptor generator, a brute-force matcher, an iterative threshold downscaling controller, a RANSAC homography estimator, and an adaptive sub-block differential unit. The FAST corner detector and BRIEF descriptor generator are configured to generate ORB feature points on the reference image and the image to be tested, respectively; the brute-force matcher is configured to filter high-quality matching pairs using Hamming distance; the iterative threshold reduction controller is configured to reduce the response difference threshold proportionally by a constant and re-extract the data when the number of high-quality matching pairs is lower than the point count threshold, and backtrack to the image extraction module when the loop reaches its limit and the number of matching pairs is insufficient to support homography solving; the RANSAC homography estimator is configured to solve the homography matrix based on high-quality matching pairs and perform perspective transformation on the image to be tested to generate a corrected image; the adaptive sub-block difference unit is configured to calculate the absolute difference map between the corrected image and the reference image, divide the pixel sub-blocks according to a preset spatial size specification, construct a local adaptive threshold using the sum of the local gray-level mean and the global base illumination constant, and use the local adaptive threshold to calculate the absolute difference. Figure 2 Values are used to generate a binary mask. A pixel-by-pixel AND operation is then performed between the binary mask and the absolute difference image to generate a clean difference image. The difference processing module includes a parameter register with power-down retention properties, which stores global base illumination constants.
[0066] Downstream of the probabilistic inference module, coupled to the clean difference map output of the difference processing module, it is configured to carry a probabilistic convolutional network. The probabilistic convolutional network includes a pre-separable depthwise convolutional layer and a core 1×1 convolutional layer. The pre-separable depthwise convolutional layer is configured to extract multi-channel local spatial texture context features from the clean difference map. The number of input channels of the core 1×1 convolutional layer corresponds to the number of output channels of the pre-separable depthwise convolutional layer, with a single output channel. All kernel weights of the core 1×1 convolutional layer are communicatively coupled to a non-negative truncation operator, configured to maintain non-negativity constraints after parameter updates. A sigmoid activation unit follows the core 1×1 convolutional layer to ensure the output falls within the probability interval [0,1]. The output is an initial probability map with the same spatial resolution as the clean difference map. Each pixel value in the initial probability map independently represents the probability response value corresponding to the defect coordinates.
[0067] The upstream of the defect determination module is coupled to the binary mask output of the difference processing module and the initial probability map output of the probability inference module, respectively. It is configured to carry morphological closing operation unit, pixel-by-pixel multiplication unit, connected component extraction unit, probability accumulation unit, cascaded decision unit and secondary classification network. The morphological closing unit is configured to perform dilation followed by erosion on a binary mask using rectangular structuring elements to generate a closing mask. The pixel-by-pixel multiplication unit is configured to multiply the closing mask with the initial probability map pixel-by-pixel to generate a refined probability map. The connected component extraction unit is configured to extract connected components from the refined probability map according to the 8-neighborhood rule. The probability accumulation unit is configured to calculate the average probability response value of each pixel within a connected component. The cascaded decision unit is configured to output the true defect location information to the host computer using the bounding rectangle coordinates of the corresponding connected component when the average value is greater than a decision threshold. The secondary classification network, coupled to the cascaded decision unit, is configured to receive the original pixel block cropped and scaled by the bounding rectangle of the corrected image when the average value is between a preset lower limit and a decision threshold, and output the binary classification confidence scores for defects and non-defects to add to the decision. The cascaded decision unit, coupled to the host computer's receipt channel, is configured to fall back to the local buffer and trigger a retest signal when the location information receipt times out.
[0068] This few-sample PCB defect detection system, at the material level, consists of an industrial camera, a photoelectric triggering circuit, an FPGA hardware accelerator, a GPU or NPU inference accelerator, a processor, and memory, all coupled via a system bus. The industrial camera and photoelectric triggering circuit form the front-end of the image extraction module; the FPGA hardware accelerator carries the parallel pipeline for ORB feature extraction and brute-force matching in the differential processing module; the GPU or NPU carries the forward inference operator of the probabilistic convolutional network in the probabilistic inference module; and the processor carries the main algorithms for RANSAC estimation, adaptive sub-block differencing in the differential processing module, and morphological and connected component analysis in the defect determination module. These algorithms are implemented by the processor executing executable instructions from memory. The micro-parameter values, threshold boundaries, loss function ratios, and anomaly backoff criteria for each of the above modules have been detailed in the aforementioned method embodiments and will not be repeated here.
[0069] The above are all preferred embodiments of this application, and are not intended to limit the scope of protection of this application. Therefore, all equivalent changes made in accordance with the structure, shape and principle of this application should be covered within the scope of protection of this application.
Claims
1. A method for detecting defects in PCBs with a small sample size, characterized in that, include: Extract the core areas of the standard PCB and the PCB under test, and generate reference images and images under test respectively; The image to be tested is geometrically corrected, and the absolute difference map with the reference image is calculated. The absolute difference map is divided into pixel sub-blocks, and the local gray-level mean of each pixel sub-block is added to a preset global base illumination constant to generate a local adaptive threshold. The absolute difference map is binarized according to the local adaptive threshold corresponding to the sub-block to which each pixel belongs to generate a binary mask, and the binary mask is ANDed with the absolute difference map to obtain a clean difference map. The pure difference map is input into a preset probabilistic convolutional network, and spatial features are extracted by a pre-convolutional layer and mapped by a single-channel core convolutional layer with non-negative constraints, and an initial probability map is output. The weights of the single-channel core convolutional layer are truncated to the non-negative half axis by a truncation operator, and the probabilistic convolutional network is trained based on a composite loss function that includes a weighted sparse loss term. Each pixel value of the initial probability map independently represents the probability response value of the defect. A morphological closing operation is performed on the binary mask to generate a closing operation mask, and the closing operation mask is multiplied pixel by pixel with the initial probability map to generate a refined probability map; connected components are extracted from the refined probability map, and the average value of the probability response values of all pixels in each connected component is calculated. When the average value is greater than a preset judgment threshold, the corresponding connected component is determined to be a real defect and the location information is output.
2. The method for detecting defects in a small number of PCB samples according to claim 1, characterized in that: Before extracting the core areas of the standard PCB and the PCB under test and generating the reference image and the image under test respectively, the original acquired images of the standard PCB and the PCB under test are obtained and smoothing filtering is performed to generate the denoised reference image and the denoised image under test respectively. The process of extracting the core regions of the standard PCB and the PCB under test, and generating corresponding reference and test images, includes: The preset physical fixture shielding mask is mapped onto the denoised reference image and the denoised test image respectively to mask the non-circuit area, and the unmasked area is extracted and output as the reference image and the test image respectively.
3. The method for detecting defects in a small number of PCB samples according to claim 2, characterized in that, The geometric correction of the image to be tested includes: Based on a preset response difference threshold, the corner points of the reference image and the image under test are extracted and feature descriptors are generated by combining the gray-scale centroid direction; Calculate the response distance between each feature descriptor, and extract the matching pairs whose response distance is not greater than a preset distance threshold as valid matching pairs; The homography matrix is estimated based on the effective matching pairs, and perspective transformation is performed on the image under test using the homography matrix.
4. The method for detecting defects in a small number of PCB samples according to claim 3, characterized in that, Before estimating the homography matrix based on the effective matching pairs: When the number of valid matching pairs is less than a preset point threshold, the response difference threshold is reduced by a preset proportional constant, and the reduced response difference threshold is not lower than a preset minimum threshold. The corner points are then extracted again based on the reduced response difference threshold to update the valid matching pairs until the number of updated valid matching pairs is not less than the point threshold, or a retest signal is triggered when the number of iterations reaches a preset iteration limit.
5. The method for detecting defects in a small number of PCB samples according to claim 4, characterized in that, The step of dividing the absolute difference map into pixel sub-blocks includes: Based on the physical mapping relationship between the target trace width and imaging resolution of the standard PCB, the spatial size specifications are determined, and the absolute difference map is divided into grids according to the spatial size specifications to generate each pixel sub-block. The preset global base illumination constant is the illumination offset baseline calculated based on the global differential statistics of the defect-free verification board.
6. The method for detecting defects in a small number of PCB samples according to claim 5, characterized in that, The process of inputting the pure difference map into a preset probabilistic convolutional network, sequentially extracting spatial features through a pre-convolutional layer, and mapping through a single-channel core convolutional layer with non-negative constraints includes: Local spatial texture context features of the pure difference map are extracted through the preceding convolutional layer with a depthwise separable convolutional structure; The local spatial texture context features are input into the single-channel core convolutional layer to perform dimensionality reduction mapping, and non-negative probability response values are extracted based on non-negative activation constraints to generate the initial probability map.
7. The method for detecting defects in a small number of PCB samples according to claim 6, characterized in that, The method also includes a pre-training step for the probabilistic convolutional network, comprising: acquiring training samples containing pixel-level defect labels; calculating the weighted sparse loss term based on the weight parameters of the single-channel core convolutional layer, and calculating the defect pixel recall loss term and the non-defect pixel suppression loss term based on the sample probability map output after inputting the training samples into the probabilistic convolutional network, combined with the probability response values of the sample defect region and background region divided by the pixel-level defect labels; weighting and summing the weighted sparse loss term, the defect pixel recall loss term, and the non-defect pixel suppression loss term according to a preset ratio to construct the composite loss function, and using the composite loss function to backpropagate and update the parameters of the probabilistic convolutional network.
8. The method for detecting defects in a small number of PCB samples according to claim 6, characterized in that, The step of performing a morphological closing operation on the binary mask to generate a closing operation mask, and then multiplying the closing operation mask pixel-by-pixel with the initial probability map to generate a refined probability map, includes: Based on the preset structural elements, the binary mask is sequentially subjected to dilation and erosion operations to stitch up the broken pixels, thereby generating the closing operation mask; The closing operation mask is multiplied pixel-by-pixel with the initial probability map, and the probability response values not covered by the closing operation mask are set to zero to output the fine probability map.
9. A method for detecting defects in a small number of PCB samples according to claim 8, characterized in that, After calculating the average of the probability response values of all pixels within each connected component: when the average value is between the judgment threshold and the preset lower limit, the coordinates of the bounding rectangle corresponding to the connected component are extracted, and the original pixel block is cropped from the geometrically corrected image based on the bounding rectangle coordinates; the original pixel block is input into a preset secondary classification network, and the connected component is determined a second time based on the classification confidence output by the secondary classification network to determine whether it is a real defect.
10. A few-sample PCB defect detection system, used to implement the few-sample PCB defect detection method as described in any one of claims 1-9, characterized in that, include: The image extraction module is used to extract the core areas of the standard PCB and the PCB under test, and generate reference images and images under test respectively. The difference processing module is used to perform geometric correction on the image to be tested and calculate the absolute difference map with the reference image; divide the absolute difference map into pixel sub-blocks, add the local gray-level mean of each pixel sub-block to a preset global base illumination constant to generate a local adaptive threshold; binarize the absolute difference map according to the local adaptive threshold corresponding to the sub-block to which each pixel belongs to generate a binary mask, and perform an AND operation between the binary mask and the absolute difference map to obtain a clean difference map; The probabilistic inference module is used to input the pure difference map into a preset probabilistic convolutional network, extract spatial features through a pre-convolutional layer, and map through a single-channel core convolutional layer with non-negative constraints to output an initial probability map. The weights of the single-channel core convolutional layer are truncated to the non-negative half-axis by a truncation operator, and the probabilistic convolutional network is trained based on a composite loss function that includes a weighted sparse loss term. Each pixel value of the initial probability map independently represents the probability response value of the defect. The defect determination module is used to perform morphological closing operations on the binary mask to generate a closing operation mask, and multiply the closing operation mask with the initial probability map pixel by pixel to generate a fine probability map; extract the connected components in the fine probability map, calculate the average value of the probability response values of all pixels in each connected component, and when the average value is greater than a preset determination threshold, determine that the corresponding connected component is a real defect and output the location information.