Unsupervised PCBA (Printed Circuit Board Assembly) surface defect detection method based on spatial position perception
By using a spatial location-aware unsupervised detection method, a feature memory library is constructed using a VIT network for PCBA surface defect detection. This solves the problems of insufficient utilization of spatial structural characteristics and inconsistent judgment visualization in existing technologies, and achieves detection results with high accuracy and low false alarm rate.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HEBEI UNIV OF TECH
- Filing Date
- 2026-01-21
- Publication Date
- 2026-04-17
AI Technical Summary
Existing PCBA surface defect detection methods do not fully utilize the spatial structural characteristics, resulting in a high false alarm rate, sensitivity to assembly deviations and image acquisition errors, and inconsistency between defect judgment and visualization.
The spatial location-aware unsupervised detection method extracts spatial features through a VIT network, constructs a feature memory, and scores defects. By utilizing spatial location constraints and generalization based on similar structures, it achieves robustness and consistency in defect detection.
It improves the accuracy and stability of defect detection, reduces the false alarm rate, is suitable for industrial scenarios with diverse defect types and scarce samples, and generates interpretable defect heatmaps.
Smart Images

Figure CN121883471A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of industrial visual inspection and electronic manufacturing quality control technology, specifically to an unsupervised PCBA (Printed Circuit Board Assembly) surface defect detection method based on spatial position perception. Background Technology
[0002] In modern electronics manufacturing, printed circuit board assembly (PCBA) has become a critical component of most electronic devices, and its quality directly affects the overall performance and reliability of the equipment. Defect detection is a crucial step in ensuring product quality. During the production process, PCBAs often suffer from defects such as component damage or misalignment, which can lead to varying degrees of failure or potential failure. As PCBA products become increasingly miniaturized and component integration increases, defect detection becomes increasingly challenging.
[0003] Common PCBA surface defects include, but are not limited to: cold solder joints, bridging, insufficient solder, excessive solder, missing components, misalignment, skewness, damage, foreign matter residue, surface contamination, or scratches. Existing PCBA surface defect detection methods mainly fall into the following categories: rule-based or template-matching methods, which rely on manual experience to set detection rules or reference templates, have weak adaptability to environmental changes, product differences, and complex defects, and have high maintenance costs. Supervised learning-based classification or target detection methods, which typically require a large number of labeled defect samples; however, in actual production, PCBA defect types are diverse and their distribution is extremely uneven, with some defects occurring very infrequently, making it difficult to obtain sufficient labeled samples and limiting the practicality of the methods. Unsupervised or weakly supervised defect detection methods, which model normal samples and detect areas that significantly deviate from the normal pattern during the inference stage, can alleviate the problem of insufficient defect samples to some extent.
[0004] However, existing PCBA surface defect detection methods still have the following shortcomings: They ignore the spatial structural characteristics of the PCBA, often mixing features from different spatial locations in their modeling, failing to fully utilize the structural priors of fixed components or solder joints at each spatial location, easily leading to feature confusion between different structural regions and thus false alarms; they are sensitive to slight positional shifts, as assembly tolerances, alignment errors, or image acquisition errors can cause slight spatial shifts in PCBA samples in actual production, and strict positional matching can easily misclassify normal samples as defects; and there is inconsistency between defect assessment and visualization, with some existing methods using different standards or thresholds in defect assessment and visualization, resulting in inconsistencies between detection and visualization results, affecting practical use and defect localization. Therefore, there is an urgent need for a PCBA surface defect detection method that can fully utilize the spatial structural priors of the PCBA, consider positional robustness, and maintain consistency between defect assessment and visualization. Summary of the Invention
[0005] To address the shortcomings of existing technologies, the technical problem this invention aims to solve is to provide a position-aware unsupervised PCBA surface defect detection method, which aims to solve problems such as strong dependence on defect samples, insufficient utilization of prior spatial structures, sensitivity to assembly deviations and image acquisition errors, and inconsistency between defect judgment and defect visualization.
[0006] The technical solution adopted by the present invention to solve the above-mentioned technical problems is as follows: An unsupervised PCBA surface defect detection method based on spatial location awareness includes the following steps: Step 1: Construct a feature memory library using normal PCBA images; Multiple normal PCBA images are selected for preprocessing. Each preprocessed normal PCBA image is then processed through a VIT network for feature extraction to obtain spatial features at each spatial location. Spatial features at the same spatial location in all normal PCBA images are combined into a spatial feature set, thus obtaining the spatial feature set at each spatial location. If the structural similarity of spatial features at any two spatial locations in a normal PCBA image is greater than or equal to the structural similarity threshold, the structures at the two spatial locations are considered to belong to the same type of component. Then, the spatial feature sets at the two spatial locations are merged to obtain a set of generalized spatial features of the same type of structure at the spatial location. The set of spatial features at the remaining spatial locations and the set of generalized spatial features of the same type of structure at all spatial locations constitute the feature memory. Step 2: Calculate the defect score at each spatial location in the test PCBA image; Test any spatial location in the PCBA image neighborhood Represented as: (5) in, Indication of spatial location Adjacent spatial locations, Indicates taking the absolute value; The neighborhood radius; Construct a reference spatial feature set for each spatial location based on the feature memory: (6) in, Indicates spatial location The reference space feature set, Indicates spatial location The set of spatial features at the location, Indicates spatial location The set of spatial features at the location, To represent taking the union of sets, Indicates spatial location The set of spatial locations where similar structures are generalized; The test PCBA image is processed by the ViT network to extract features and obtain spatial features at each spatial location; for any spatial feature at any spatial location, the minimum distance between the spatial feature and the reference spatial feature is calculated according to Equation (6) to obtain the defect score at that spatial location. (7) in, Indicates spatial location Defect rating at the location, For distance measurement function, Indicates the spatial location of the test PCBA image Spatial characteristics of the location Indicates the characteristics of the reference space; Traverse all spatial locations of the test PCBA image to obtain the defect score at each spatial location; Step 3: Aggregate the defect scores at all spatial locations in the test PCBA image to obtain an image-level defect score; when the image-level defect score exceeds the defect score threshold, the test PCBA image is determined to have a defect; otherwise, it is determined to be normal.
[0007] Compared with the prior art, the beneficial effects of the present invention are: 1. By introducing a spatial location-aware modeling mechanism, the spatial discrimination capability of defect detection is improved. This invention generates spatial features with spatial structure information based on a feature extraction network (ViT network), and introduces spatial location constraints during the detection process to ensure that feature matching and defect judgment are consistent in space, effectively avoiding feature confusion between different regions and improving the accuracy and stability of PCBA surface defect detection.
[0008] 2. By dividing the structure into regions and generalizing modeling of similar structures, false alarms are reduced and the adaptability to normal structural changes is enhanced. This invention divides the PCBA surface into component regions and substrate regions, and performs unified modeling of regions with similar structural features within the component regions. This can characterize the normal structural distribution of similar components under conditions of changes in size, packaging, or arrangement, thereby effectively distinguishing normal structural changes from actual defects and significantly reducing the false alarm rate.
[0009] 3. Achieve robust and interpretable defect detection without relying on defect samples. This invention constructs a feature memory based on normal samples, eliminating the need for pre-collection or labeling of defect samples. It is suitable for industrial scenarios with diverse defect types and scarce samples. Furthermore, it can generate defect heatmaps based on defect scores at spatial locations, intuitively displaying defect locations and facilitating engineering applications and manual verification. Attached Figure Description
[0010] Figure 1 A flowchart illustrating the construction of the feature memory library for this invention; Figure 2 This is a flowchart of the defect detection process of the present invention. Detailed Implementation
[0011] The technical solution of the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments, but this does not limit the scope of protection of this application.
[0012] This invention provides an unsupervised PCBA surface defect detection method based on spatial location awareness (hereinafter referred to as the method, see below). Figures 1-2 ), including the following steps: Based on size The PCBA image is used as input, where and These represent the width and height pixel values of the image, respectively. This PCBA image contains various types of electronic components, such as resistors, capacitors, and chips. Different components differ in appearance, arrangement, and local structure, but they still have similar structural features within the same type of component.
[0013] Step 1: Construct a feature memory library based on spatial location and generalization of similar structures using normal PCBA images; Multiple defect-free normal PCBA images are selected and preprocessed, including geometric correction and size normalization, to ensure that different images maintain consistency in spatial scale and distribution. The preprocessed normal PCBA image is processed by a VIT network for feature extraction to obtain spatial features at each spatial location. Each spatial feature corresponds to a local region in the image and implicitly encodes the spatial structure and morphological information of the local region. The set of spatial features corresponding to each normal PCBA image is represented as follows: (1) in, Indicates spatial location Spatial characteristics of the location Representing feature dimension, It represents a set of spatial locations.
[0014] Collect spatial features at the same spatial location from all normal PCBA images to obtain a set of spatial features at each spatial location. (2) in, Indicates spatial location The set of spatial features at the location, Indicates the first Zhang Zhengchang PCBA Image Spatial Location Spatial characteristics of the location This indicates the number of normal PCBA images; To enhance the model's adaptability to structural differences among similar components, a structural similarity metric function is introduced while maintaining spatial constraints. This is used to characterize the structural consistency of similar components located in different spatial locations under different sizes, appearances, or layout conditions. For a normal PCBA image, if the structural similarity of spatial features at any two spatial locations satisfies equation (3), it is considered that the structures at the two spatial locations belong to the same type of component. Then, the spatial feature sets at the two spatial locations are merged to obtain a spatial feature set of generalized similar structures at the spatial locations. This design allows the establishment of associations between different spatial locations, so that similar components across locations can share the spatial feature set. The spatial feature set at the remaining spatial locations and the spatial feature set of generalized similar structures at all spatial locations constitute a feature memory based on spatial location and generalized similar structures. This feature memory has good spatial location constraints and generalization ability of similar component structures. (3) in, Indicates spatial location Spatial characteristics of the location This represents the structural similarity threshold.
[0015] Spatial location Spatial location set of similar structures Represented as: (4) Step 2: Calculate the defect score at each spatial location in the test PCBA image; Determine any spatial location in the test PCBA image neighborhood : (5) in, Indication of spatial location Adjacent spatial locations, Indicates taking the absolute value; The neighborhood radius is used to constrain spatial alignment during the matching process and suppress interference from features in non-corresponding regions. Based on this, and to take into account the differences in the internal structure of similar components, a reference spatial feature set for each spatial location is constructed according to the feature memory: (6) in, Indicates spatial location The reference space feature set, Indicates spatial location The set of spatial features at the location, Indicates spatial location The set of spatial features at the location, This represents taking the union of sets; the first term on the right side of the equation reflects spatial location-aware constraints, and the second term reflects the generalization and sharing of similar structures.
[0016] The test PCBA images were processed using a ViT network for feature extraction to obtain spatial features at each spatial location; for spatial location... Spatial characteristics of the place The minimum distance between the spatial feature and the reference spatial feature is calculated to obtain the defect score of the spatial location. The defect score reflects both spatial alignment consistency and similarity of similar structures, thus maintaining stable discrimination capability when similar components have changes in appearance or arrangement.
[0017] (7) in, Indicates spatial location Defect rating at the location; The distance metric function can be Euclidean distance, cosine distance, or a distance metric based on statistical distribution. Indicates the characteristics of the reference space; Repeat the above process to traverse all spatial locations of the test PCBA image and obtain the defect score at each spatial location.
[0018] Step 3: Aggregate the defect scores at all spatial locations in the test PCBA image to obtain the image-level defect score; (8) in, This represents an aggregate function, which can be a maximum value, mean, or a sorted statistical function; When image-level defect scoring Exceeding the defect scoring threshold If the test PCBA image is normal, it is determined that there is a defect; otherwise, it is determined to be normal. At the same time, the defect scores at each spatial location can be mapped to the image space to generate a defect heat map to indicate the defect location.
[0019] Any aspects not covered in this invention are applicable to existing technologies.
Claims
1. An unsupervised PCBA surface defect detection method based on spatial location awareness, characterized in that, Includes the following steps: Step 1: Construct a feature memory library using normal PCBA images; Multiple normal PCBA images are selected for preprocessing. Each preprocessed normal PCBA image is then processed through a VIT network to extract features, thereby obtaining the spatial features at each spatial location. The spatial features of all normal PCBA images at the same spatial location form a spatial feature set, thus obtaining the spatial feature set at each spatial location. If the structural similarity of spatial features at any two spatial locations in a normal PCBA image is greater than or equal to the structural similarity threshold, the structures at the two spatial locations are considered to belong to the same type of component. Then, the spatial feature sets at the two spatial locations are merged to obtain a set of generalized spatial features of the same type of structure at the spatial location. The set of spatial features at the remaining spatial locations and the set of generalized spatial features of the same type of structure at all spatial locations constitute the feature memory. Step 2: Calculate the defect score at each spatial location in the test PCBA image; Test any spatial location in the PCBA image neighborhood Represented as: (5) in, Indication of spatial location Adjacent spatial locations, Indicates taking the absolute value; The neighborhood radius; Construct a reference spatial feature set for each spatial location based on the feature memory: (6) in, Indicates spatial location The reference space feature set, Indicates spatial location The set of spatial features at the location, Indicates spatial location The set of spatial features at the location, To represent taking the union of sets, Indicates spatial location The set of spatial locations where similar structures are generalized; The test PCBA image is processed by the ViT network to extract features and obtain spatial features at each spatial location; for any spatial feature at any spatial location, the minimum distance between the spatial feature and the reference spatial feature is calculated according to Equation (6) to obtain the defect score at that spatial location. (7) in, Indicates spatial location Defect rating at the location, For distance measurement function, Indicates the spatial location of the test PCBA image Spatial characteristics of the location Indicates the characteristics of the reference space; Traverse all spatial locations of the test PCBA image to obtain the defect score at each spatial location; Step 3: Aggregate the defect scores at all spatial locations in the test PCBA image to obtain an image-level defect score; when the image-level defect score exceeds the defect score threshold, the test PCBA image is determined to have a defect; otherwise, it is determined to be normal.