Part surface defect detection method
By converting part surface defects from pixel level into geometric characteristic vector representation and combining it with efficient algorithms, the problems of large data volume and insufficient precision in traditional methods are solved, and fast and accurate detection and classification of part surface defects are achieved, thus improving the performance of the detection system.
Patent Information
- Application Number
- CN202510749445.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-05
- Publication Date
- 2025-09-16
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Traditional methods for detecting surface defects in parts rely on pixel-level image processing, resulting in large amounts of data, high storage and transmission costs, and difficulty in accurately quantifying the geometric characteristics of defects. This affects the computational efficiency and analytical capabilities of the detection system, making it difficult to quickly and accurately identify complex defects.
The pixel-level description of defects is converted into a vector representation based on geometric characteristics. Through efficient contour feature extraction, similarity measurement and matching algorithms, region growing, Fourier descriptor, local sensitive hashing, KD tree and K-means clustering algorithms are used to achieve accurate quantification, rapid classification and retrieval of defects.
It improves the accuracy and efficiency of part surface defect detection, can quickly and accurately detect and classify various complex defects, and supports manufacturing quality control.
Smart Images

Figure SMS_1 
Figure SMS_4 
Figure SMS_6
Abstract
Description
Technical Field
[0001] The invention relates to a method for detecting surface defects of parts. Background Art
[0002] Part surface defect detection is a core area of quality control in the manufacturing industry, directly impacting product quality and production efficiency. Its importance is self-evident. With the advancement of industrial automation, the demand for precision and efficiency in defect detection technology is becoming increasingly urgent. Traditional detection methods rely on pixel-level image processing, which consumes large amounts of data, is costly to store and transmit, and has difficulty accurately quantifying the geometric characteristics of defects, limiting the computational efficiency and analytical capabilities of detection systems. These limitations make it difficult for existing methods to quickly and accurately identify and manage complex defect morphologies.
[0003] In the field of defect detection, building an efficient defect description and management system faces multiple challenges. Feature extraction of defect contours is the primary difficulty. Traditional pixel-level descriptions struggle to capture the geometric characteristics and topological structure of defects, resulting in information redundancy and insufficient quantification accuracy. Consequently, measuring the similarity of defect contours becomes a subsequent difficulty. Without precise feature extraction, similarity calculations are often distorted, affecting the efficiency of defect classification and retrieval. Furthermore, the design of efficient contour matching and query algorithms is limited by the aforementioned two issues. Unresolved feature extraction and similarity issues make it difficult for the algorithm to achieve rapid positioning and accurate identification in complex scenarios. These technical factors are intertwined and collectively restrict the performance improvement of the detection system. Summary of the Invention
[0004] The present invention proposes a method for detecting surface defects of automotive parts, which converts the pixel-level description of defects into a vector representation based on geometric characteristics. Through efficient contour feature extraction, similarity measurement and matching algorithms, it realizes accurate quantification, rapid classification and retrieval of defects, thereby improving the reliability of detection.
[0005] The technical solution of the present invention is achieved as follows: A method for detecting surface defects of automobile parts, comprising: Step 1: Obtain an original image of the part surface through an image sensor, and use grayscale conversion and Canny edge detection algorithm to extract a contour point sequence from the grayscale image to obtain a first defect contour image; if the edge continuity in the contour point sequence of the first defect contour image is lower than a preset threshold, repair the discontinuous contour point sequence to obtain a second defect contour image; Step 2: Based on the contour point sequence of the second defect contour image, a region growing algorithm is used to segment the defect area, and the perimeter, area, and shape factor of the contour are calculated to obtain a defect geometric feature set; the contour point sequence in the defect geometric feature set is Fourier transformed using a Fourier descriptor algorithm to generate frequency domain coefficients, extract low-frequency components and high-frequency components, perform normalization processing, calculate the energy distribution, and obtain a vector feature sequence; if the Euclidean distance between the energy distribution of the vector feature sequence and the preset complex defect template is less than a preset threshold, a local sensitive hashing algorithm is used to calculate the hash value of the frequency domain coefficient to generate a defect feature index; Step 3: Based on the high-dimensional features of the defect feature index, a KD tree algorithm is used to construct a tree structure, generate a segmentation hyperplane, store the feature index in the leaf node, and obtain a fast retrieval database. By inputting the vector feature sequence of the query defect, the KD tree nearest neighbor search algorithm is used to compare the high-dimensional features along the search path, calculate the distance metric, perform pruning optimization, match similar defects within the neighborhood radius, and obtain a preliminary classification result. If the confidence level of the preliminary classification result is lower than the preset threshold, the principal component analysis algorithm is used to reduce the feature dimensionality of the frequency domain coefficients of the vector feature sequence, and the distance metric is recalculated to obtain the final classification result. Step 4: Based on the high-dimensional features of the final classification results, the K-means clustering algorithm is used to group the defect types, generate a defect management report containing contour point sequences and frequency domain coefficients, and obtain the output data of the detection system.
[0006] The present invention has the following beneficial effects: the method can quickly and accurately detect and classify various complex defects, improve the efficiency and reliability of parts quality inspection, and provide strong support for manufacturing quality control. DETAILED DESCRIPTION
[0007] The following will clearly and completely describe the technical solutions of the present invention in conjunction with the embodiments of the present invention. Obviously, the embodiments described are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0008] A method for detecting surface defects of a part, comprising: Step 1: Obtain the original image of the part surface through the image sensor, use grayscale conversion and Canny edge detection algorithm to extract the contour point sequence from the grayscale image to obtain the first defect contour image; if the edge continuity in the contour point sequence of the first defect contour image is lower than the preset threshold, repair the discontinuous contour point sequence to obtain the second defect contour image.
[0009] Among them, if the edge continuity in the contour point sequence of the first defect contour image is lower than a preset threshold, repairing the discontinuous contour point sequence to obtain the second defect contour image specifically includes: using an interpolation algorithm to repair the contour point sequence of the first defect contour image to obtain a repair sequence, generating a defect contour image according to the repair sequence, and using a boundary tracking algorithm to draw the contour to obtain a second defect contour image.
[0010] Step 2: Based on the contour point sequence of the second defect contour image, the defect area is segmented using the region growing algorithm, the perimeter, area and shape factor of the contour are calculated, and the defect geometric feature set is obtained; the contour point sequence in the defect geometric feature set is Fourier transformed through the Fourier descriptor algorithm to generate frequency domain coefficients, extract low-frequency components and high-frequency components, perform normalization processing, calculate the energy distribution, and obtain a vector feature sequence; if the Euclidean distance between the energy distribution of the vector feature sequence and the preset complex defect template is less than a preset threshold, the local sensitive hashing algorithm is used to calculate the hash value of the frequency domain coefficient to generate a defect feature index.
[0011] According to the contour point sequence of the second defect contour image, the defect area is segmented using the region growing algorithm, and the perimeter, area and shape factor of the contour are calculated to obtain the defect geometric feature set, including: According to the contour point sequence of the second defect contour image, a region growing algorithm is used to segment the defect area to generate a defect area set, the contour perimeter and area of each defect area are calculated, and a geometric parameter set is generated; According to the geometric parameter set, the shape factor of each defect area is calculated to generate a feature set. If the shape factor in the feature set exceeds the preset threshold, the morphological operation is used to optimize the boundary of the defect area set to generate an optimized area set. According to the optimized region set, the boundary tracking algorithm is used to extract the continuous contour point sequence to generate the contour point set. The least square method is used to fit the contour curve to generate the smooth contour set and the defect image.
[0012] Among them, the contour point sequence in the defect geometric feature set is Fourier transformed through the Fourier descriptor algorithm to generate frequency domain coefficients, extract low-frequency components and high-frequency components, perform normalization processing, calculate energy distribution, and obtain a vector feature sequence, including: Through the Fourier descriptor algorithm, the contour point sequence is subjected to Fourier transform to generate a frequency domain coefficient sequence, and the low-frequency component and high-frequency component are separated by filtering method to obtain a component coefficient set; Normalization is performed on the component coefficient set, and the normalized value of each coefficient is calculated using the L2 norm to obtain the normalized coefficient set.
[0013] represents the normalized coefficient value of the i-th, represents the value of the i-th original coefficient, j ranges from 1 to n; According to the normalization coefficient set, the energy distribution of low-frequency components and high-frequency components is calculated to obtain the vector feature sequence.
[0014] represents the energy value of the kth component, m represents the number of coefficients contained in the component, and the energy feature set is obtained.
[0015] Step 2 also includes: querying a preset defect feature database based on the generated defect feature index to obtain matching defect categories and obtain a defect category set; calculating the cosine similarity between the feature vector of each category and the frequency domain coefficient set through the defect category set,
[0016] represents the maximum similarity value, represents the similarity score of the i-th defect, K represents the total number of defect categories, and is used to determine the main defect category. If the cosine similarity of the main defect category is higher than the preset similarity threshold, the feature subset of the corresponding category is extracted from the frequency domain coefficient set to obtain the feature subset; The principal component analysis algorithm is used to perform dimensionality reduction on the feature subset to generate a reduced-dimensionality feature set. Based on the reduced-dimensionality feature set, the statistical distribution parameters of the feature vector are calculated to obtain the defect feature description set.
[0017] Step 3: Based on the high-dimensional features of the defect feature index, the KD tree algorithm is used to construct a tree structure, generate a segmentation hyperplane, store the feature index in the leaf node, and obtain a fast retrieval database; by inputting the vector feature sequence of the query defect, the KD tree nearest neighbor search algorithm is used to compare the high-dimensional features along the search path, calculate the distance metric, perform pruning optimization, match similar defects within the neighborhood radius, and obtain a preliminary classification result; if the confidence level of the preliminary classification result is lower than the preset threshold, the principal component analysis algorithm is used to perform feature dimensionality reduction on the frequency domain coefficients of the vector feature sequence, recalculate the distance metric, and obtain the final classification result.
[0018] Extract high-dimensional features from the defect feature index, use the KD tree algorithm to recursively partition the feature space, generate a set of hyperplanes and leaf nodes, and obtain a tree structure. Based on the tree structure, traverse the leaf nodes, extract the feature index from each leaf node, and generate an index set. Using the nearest neighbor search algorithm, the KD tree is traversed along the search path to calculate the distance metric between the high-dimensional features of each node and the input feature sequence to obtain a distance distribution set. If the minimum distance in the distance distribution set is less than a preset threshold, the corresponding feature index is extracted from the distance distribution set to generate a preliminary matching defect set. The K-means algorithm is used to cluster the feature vectors in the set to generate a cluster center set. The feature description of each cluster center is extracted from the cluster center set, and the cosine similarity with the input feature sequence is calculated to obtain a similarity distribution set; if the maximum similarity in the similarity distribution set is greater than the preset threshold, the corresponding cluster center is extracted from the similarity distribution set, and the pre-established defect category database is queried to determine the final classification result. Based on the final classification result, a feature description set containing defect categories and similarity scores is generated, and the classification set is output.
[0019] Step 4: Based on the high-dimensional features of the final classification results, the K-means clustering algorithm is used to group the defect types, generate a defect management report containing contour point sequences and frequency domain coefficients, and obtain the output data of the detection system.
[0020] Obtain high-dimensional feature data from the classification results, use the principal component analysis algorithm to extract the main feature components, obtain the feature set after dimensionality reduction, use the K-means clustering algorithm to group the defect types, and determine the cluster labels of the defect types; Based on the cluster labels, the contour point sequence corresponding to the defect is extracted from the original data to obtain a contour point sequence set. The frequency domain coefficients are calculated using the fast Fourier transform algorithm to generate a frequency domain feature set. If the coefficient amplitude of the frequency domain feature set exceeds the preset threshold, it is integrated with the contour point sequence set to generate defect management data. Obtain defect management data, use data standardization processing, and obtain the output results of the detection system.
[0021] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for detecting surface defects of parts, characterized in that: include: Step 1: Obtain an original image of the part surface through an image sensor, and use grayscale conversion and Canny edge detection algorithm to extract a contour point sequence from the grayscale image to obtain a first defect contour image; If the edge continuity in the contour point sequence of the first defect contour image is lower than a preset threshold, repairing the discontinuous contour point sequence to obtain a second defect contour image; Step 2: Based on the contour point sequence of the second defect contour image, a region growing algorithm is used to segment the defect area, and the perimeter, area, and shape factor of the contour are calculated to obtain a defect geometric feature set; the contour point sequence in the defect geometric feature set is Fourier transformed using a Fourier descriptor algorithm to generate frequency domain coefficients, extract low-frequency components and high-frequency components, perform normalization processing, calculate the energy distribution, and obtain a vector feature sequence; if the Euclidean distance between the energy distribution of the vector feature sequence and the preset complex defect template is less than a preset threshold, a local sensitive hashing algorithm is used to calculate the hash value of the frequency domain coefficient to generate a defect feature index; Step 3: Based on the high-dimensional features of the defect feature index, a KD tree algorithm is used to construct a tree structure, generate a segmentation hyperplane, store the feature index in the leaf node, and obtain a fast retrieval database. By inputting the vector feature sequence of the query defect, the KD tree nearest neighbor search algorithm is used to compare the high-dimensional features along the search path, calculate the distance metric, perform pruning optimization, match similar defects within the neighborhood radius, and obtain a preliminary classification result. If the confidence level of the preliminary classification result is lower than the preset threshold, the principal component analysis algorithm is used to reduce the feature dimensionality of the frequency domain coefficients of the vector feature sequence, and the distance metric is recalculated to obtain the final classification result. Step 4: Based on the high-dimensional features of the final classification results, the K-means clustering algorithm is used to group the defect types, generate a defect management report containing contour point sequences and frequency domain coefficients, and obtain the output data of the detection system.
2. The method according to claim 1, wherein In step 1, if the edge continuity in the contour point sequence of the first defect contour image is lower than a preset threshold, repairing the discontinuous contour point sequence to obtain the second defect contour image specifically includes: using an interpolation algorithm to repair the contour point sequence of the first defect contour image to obtain a repaired sequence, generating a defect contour image according to the repaired sequence, and using a boundary tracking algorithm to draw the contour to obtain the second defect contour image.
3. The method according to claim 1, wherein In step 2, based on the contour point sequence of the second defect contour image, the defect region is segmented using the region growing algorithm, the perimeter, area and shape factor of the contour are calculated, and the defect geometric feature set is obtained, including: According to the contour point sequence of the second defect contour image, a region growing algorithm is used to segment the defect area to generate a defect area set, the contour perimeter and area of each defect area are calculated, and a geometric parameter set is generated; According to the geometric parameter set, the shape factor of each defect area is calculated to generate a feature set. If the shape factor in the feature set exceeds the preset threshold, the morphological operation is used to optimize the boundary of the defect area set to generate an optimized area set. According to the optimized region set, the boundary tracking algorithm is used to extract the continuous contour point sequence to generate the contour point set. The least square method is used to fit the contour curve to generate the smooth contour set and the defect image.
4. The method according to claim 1, wherein In step 2, the contour point sequence in the defect geometric feature set is Fourier transformed by the Fourier descriptor algorithm to generate frequency domain coefficients, extract low-frequency components and high-frequency components, perform normalization processing, calculate energy distribution, and obtain a vector feature sequence, including: Through the Fourier descriptor algorithm, the contour point sequence is subjected to Fourier transform to generate a frequency domain coefficient sequence, and the low-frequency component and high-frequency component are separated by filtering method to obtain a component coefficient set; Normalization is performed on the component coefficient set, and the normalized value of each coefficient is calculated using the L2 norm to obtain the normalized coefficient set. represents the normalized coefficient value of the i-th, represents the i-th original coefficient value, j ranges from 1 to n; According to the normalization coefficient set, the energy distribution of low-frequency components and high-frequency components is calculated to obtain the vector feature sequence. represents the energy value of the kth component, m represents the number of coefficients contained in the component, and the energy feature set is obtained.
5. The method according to claim 1, wherein Step 2 also includes: According to the generated defect feature index, the preset defect feature database is queried to obtain the matching defect category and obtain the defect category set; through the defect category set, the cosine similarity between the feature vector of each category and the frequency domain coefficient set is calculated. represents the maximum similarity value, represents the similarity score of the i-th defect, K represents the total number of defect categories, and is used to determine the main defect category. If the cosine similarity of the main defect category is higher than the preset similarity threshold, the feature subset of the corresponding category is extracted from the frequency domain coefficient set to obtain the feature subset; The principal component analysis algorithm is used to perform dimensionality reduction on the feature subset to generate a reduced-dimensionality feature set. Based on the reduced-dimensionality feature set, the statistical distribution parameters of the feature vector are calculated to obtain the defect feature description set.
6. The method according to claim 1, wherein Step 3 includes: Extract high-dimensional features from the defect feature index, use the KD tree algorithm to recursively partition the feature space, generate a set of hyperplanes and leaf nodes, and obtain a tree structure. Based on the tree structure, traverse the leaf nodes, extract the feature index from each leaf node, and generate an index set. Using the nearest neighbor search algorithm, the KD tree is traversed along the search path to calculate the distance metric between the high-dimensional features of each node and the input feature sequence to obtain a distance distribution set. If the minimum distance in the distance distribution set is less than a preset threshold, the corresponding feature index is extracted from the distance distribution set to generate a preliminary matching defect set. The K-means algorithm is used to cluster the feature vectors in the set to generate a cluster center set. The feature description of each cluster center is extracted from the cluster center set, and the cosine similarity with the input feature sequence is calculated to obtain a similarity distribution set; if the maximum similarity in the similarity distribution set is greater than the preset threshold, the corresponding cluster center is extracted from the similarity distribution set, and the pre-established defect category database is queried to determine the final classification result. Based on the final classification result, a feature description set containing defect categories and similarity scores is generated, and the classification set is output.
7. The method according to claim 1, wherein In step 4, based on the high-dimensional features of the final classification results, the K-means clustering algorithm is used to group the defect types, generate a defect management report containing contour point sequences and frequency domain coefficients, and obtain the detection system output data, including: Obtain high-dimensional feature data from the classification results, use the principal component analysis algorithm to extract the main feature components, obtain the feature set after dimensionality reduction, use the K-means clustering algorithm to group the defect types, and determine the cluster labels of the defect types; Based on the cluster labels, the contour point sequence corresponding to the defect is extracted from the original data to obtain a contour point sequence set. The frequency domain coefficients are calculated using the fast Fourier transform algorithm to generate a frequency domain feature set. If the coefficient amplitude of the frequency domain feature set exceeds the preset threshold, it is integrated with the contour point sequence set to generate defect management data. Obtain defect management data, use data standardization processing, and obtain the output results of the detection system.