A visual inspection method for defects in complex precision parts
By dividing the part surface into multiple areas to be inspected, acquiring image data under multiple angles and light source conditions, and using grayscale co-occurrence matrix and spectrum analysis combined with fuzzy logic to optimize the detection algorithm, the problem of decreased detection accuracy caused by the similarity of complex surface textures and defects is solved, thus achieving high-precision and reliable defect detection.
Patent Information
- Application Number
- CN202510743530.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-05
- Publication Date
- 2025-09-05
- Estimated Expiration
- 2045-06-05
AI Technical Summary
When existing technologies are used to inspect precision and complex parts, the similarity between complex surface textures and defects leads to errors in the adaptive adjustment of detection algorithm parameters, resulting in decreased detection accuracy and increased systematic deviations and misjudgment rates.
The part surface is divided into multiple areas to be inspected, and image data is obtained under multi-angle and multi-light source conditions. The surface texture features are extracted through gray-level co-occurrence matrix and spectrum analysis. The texture complexity and defect similarity are calculated. The risk of misjudgment is analyzed using fuzzy logic, the detection algorithm is optimized, and the parameter adjustment range is verified and limited through test data.
It improves the accuracy and reliability of detection, reduces the misjudgment rate, ensures high-precision detection under complex surface conditions, and improves the quality control efficiency of the production line.
Smart Images

Figure CN120259312B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of parts detection, and in particular to a method for visually detecting defects of precise and complex parts. Background Art
[0002] Visual inspection for defects in complex precision parts utilizes vision technology to detect surface defects on complex parts produced during the manufacturing process through image acquisition and processing. These parts typically possess complex geometries and demand high manufacturing precision, and even the slightest imperfection or defect can impact their functionality and service life. Visual inspection systems use cameras and other devices to scan parts, capturing images of their appearance and using algorithms to analyze and detect surface defects such as scratches, dents, cracks, and contamination. Compared to traditional manual inspection, visual inspection is faster and more accurate, making it particularly suitable for quality control in large-scale production. Furthermore, these systems often incorporate artificial intelligence (AI) and machine learning technologies. By training on a large number of defect samples, they are able to automatically identify and classify different defects. These systems can monitor production lines in real time and adjust production parameters based on detected defects to reduce the number of defective products.
[0003] The existing technology has the following shortcomings:
[0004] When using high-resolution industrial cameras or other optical devices to scan or capture the surface of complex precision parts and acquire image data, these parts often have unique surface textures or complex geometric structures that can visually resemble real defects. In some highly automated inspection systems, the detection algorithm may have adaptive adjustment capabilities to optimize the detection of different part types. However, if the complex surface texture resembles a defect, the system may incorrectly adjust the detection algorithm parameters, resulting in a significant decrease in subsequent inspection accuracy. Furthermore, if the confusion between complex surface textures and defects causes the system to remain in an incorrect adaptive adjustment mode for a long period of time, this will induce systematic bias. This long-term adaptive bias will not only gradually deteriorate the performance of the inspection system but may also lead to a continuous decline in inspection accuracy for all subsequent production batches. Summary of the Invention
[0005] The purpose of the present invention is to provide a method for visually detecting defects of precision and complex parts to address the shortcomings of the background technology.
[0006] In order to achieve the above object, the present invention provides the following technical solution: a method for visually detecting defects of precision and complex parts, comprising the following steps:
[0007] S1: Divide the part surface into S areas to be inspected, and obtain part images under several angles and light source conditions in each area to be inspected, as well as sample data of actual defects and normal surface textures that have been annotated;
[0008] S2: Calculate the eigenvalues of the gray-level co-occurrence matrix of each area to be detected in the part image, obtain the texture feature distribution of each area to be detected on the part surface, perform spectrum analysis on the entire part image, calculate the main frequency distribution, and obtain the surface texture complexity;
[0009] S3: Compare the surface protrusion features and grayscale difference features of the normal texture area on the part surface and the area to be inspected, and calculate the surface defect similarity value in the area to be inspected;
[0010] S4: Based on the surface texture complexity and surface defect similarity values calculated in each area to be inspected, a comprehensive analysis is performed using fuzzy logic to determine the risk of misjudgment in each area to be inspected. Based on the risk of misjudgment in each area to be inspected, each area to be inspected is divided into high-risk areas to be inspected, medium-risk areas to be inspected, and low-risk areas to be inspected. The inspection algorithm is optimized for areas with different risk levels to improve the accuracy of the inspection results.
[0011] S5: Verify the optimized detection algorithm through test data and actual part inspection results, evaluate its performance on complex surfaces, and compare the changes in the false positive rate. If the false positive rate increases, limit the adjustment range of the detection algorithm parameters.
[0012] Preferably, in S2, a spectrum analysis is performed on the image of the entire part, and the main frequency distribution is calculated to obtain the surface texture complexity, which is specifically:
[0013] Perform spectrum analysis on the image of the entire part and convert the image in the spatial domain to the frequency domain. The conversion expression is: Where f(x,y) is the pixel value of the image, F(u,v) is the Fourier coefficient in the frequency domain, M and N are the width and height of the area to be detected, u and v are the frequency coordinates, and j is the imaginary unit. The modulus value of the Fourier transform is calculated to obtain the spectrum information of the image. The expression is: Where, is the modulus of the Fourier transform, are the real and imaginary parts of the Fourier transform, respectively, and the logarithmic amplitude spectrum is calculated , the expression is: ; Calculate the frequency distribution of the highest peak in the spectrum and determine the main frequency by counting the peak position in the amplitude spectrum , the expression is: ; The surface texture complexity is measured by the proportion of high-frequency components in the spectrum, and the calculation expression is: Where, Indicates high-frequency components greater than the preset high-frequency threshold. is the surface texture complexity.
[0014] Preferably, in S3, the surface defect similarity value in the area to be detected is calculated as follows:
[0015] Morphological operations are used to detect the shape features of surface protrusions. The expression is: Where I is the image, Dilation and Erosion represent dilation and erosion operations respectively. The edge detection algorithm is applied to detect the edge of the protrusion, extract the geometric parameters of the protrusion, and calculate the area to be detected pixel by pixel. and normal area Grayscale difference , the expression is: ; Then calculate the average grayscale difference of the entire area , the expression is: ; Where M and N are the width and height of the area to be detected, and H is the total number of pixels; the surface protrusion features are compared using cosine similarity, and the protrusion feature vectors are normal areas and the area to be detected , the expression is: Where, represents the dot product of the protrusion eigenvectors, 、 are the moduli of the protruding feature vectors of the normal area and the area to be detected; calculate the grayscale difference similarity , the similarity of grayscale difference is measured by cosine similarity, and the grayscale vectors are normal areas and the area to be detected , the expression is: ; The surface defect similarity value is obtained by performing weighted average calculation on the protrusion feature similarity and grayscale difference similarity.
[0016] Preferably, in S4, based on the surface texture complexity and surface defect similarity values calculated in each area to be inspected, a comprehensive analysis is performed using fuzzy logic to determine the risk of misjudgment in each area to be inspected, specifically:
[0017] The surface texture complexity and surface defect similarity values are used as input items of fuzzy logic, and the risk level of misjudgment of each area to be inspected is used as the output item of fuzzy logic;
[0018] The input surface texture complexity and surface defect similarity values are converted into fuzzy sets, and the membership degree of each set is calculated;
[0019] Reasoning is performed based on fuzzy rules, combining the membership of surface texture complexity and surface defect similarity values to derive the fuzzy output of risk level;
[0020] The defuzzification method is used to calculate a clear risk level, that is, the risk of misjudgment in the area to be detected;
[0021] Output the risk level of the detection misjudgment, divide the to-be-detected area with a high risk level into a high risk to-be-detected area, divide the to-be-detected area with a medium risk level into a medium risk to-be-detected area, and divide the to-be-detected area with a low risk level into a low risk to-be-detected area.
[0022] Preferably, in S5, the optimized detection algorithm is verified by using test data and actual part inspection results, its performance on complex surfaces is evaluated, and the change in the false positive rate is compared. If the false positive rate increases, the adjustment range of the detection algorithm parameters is limited, specifically:
[0023] Collect images of various complex surface parts, including parts with actual defects and normal parts, use the optimized detection algorithm to detect the parts in the test data set, and record the results of each detection, including: the area TP correctly detected as a defect, the part TN correctly detected as a normal area, the normal area FP incorrectly detected as a defect, and the defect area FN incorrectly ignored. Based on the detection results, calculate the error rate of different areas , the expression is: ; Calculate the misjudgment rate for high-risk, medium-risk and low-risk areas respectively By comparing the test data with the detection results of the previously unoptimized algorithm, the change in the misjudgment rate of each risk level area is calculated. The expression is: Where, is the change value of the misjudgment rate, is the optimized misjudgment rate, is the false positive rate before optimization. If ΔFPR>0, it means that the false positive rate of the optimized algorithm increases. If ΔFPR<0, it means that the false positive rate of the optimized algorithm decreases and the detection performance is improved.
[0024] Preferably, in S5, when the misjudgment rate increases, the parameters that need to be adjusted during the detection process are marked as , limiting its adjustment range, the expression is: ; and are the lower and upper limits of the parameter, respectively. is the currently calculated adaptive adjustment value; if If it exceeds the preset range, the system will correct it to the preset upper and lower limits;
[0025] When detecting complex surfaces, we can reduce misjudgment by limiting the algorithm parameters when processing complex textures. The expression is adjusted to: ; and is the allowed texture complexity processing range, is the adjusted surface texture complexity, is the currently calculated surface texture complexity;
[0026] When the misjudgment rate increases, the similarity threshold needs to be constrained. The constraint expression is: Where, is the range allowed by the similarity threshold, is the adjusted surface defect similarity, is the surface defect similarity currently calculated;
[0027] After limiting the parameter range, retest the test data and calculate the new error rate , compare the changes in misjudgment rate: ; is the change in the error rate after adjustment. If ΔFPR′<0, it means that the error rate is reduced by limiting the parameter adjustment range.
[0028] In the above technical solution, the technical effects and advantages provided by the present invention are:
[0029] 1. The present invention divides the part surface into multiple areas to be inspected and, combined with image data from multiple angles and multiple light sources, uses techniques such as grayscale co-occurrence matrix and spectrum analysis to extract surface texture features and calculate surface texture complexity. The protrusion features and grayscale differences between the inspected area and the normal area are compared to further calculate the similarity of surface defects. Based on these eigenvalues, fuzzy logic is used to analyze the risk of misjudgment in each area, and the detection algorithm is optimized according to the risk level, thereby achieving high-precision defect detection. By continuously optimizing the algorithm, the accuracy of detection is ensured, and in particular, misjudgments and missed detections can be significantly reduced under complex surface conditions.
[0030] 2. This invention verifies the performance of its detection algorithm using test data and actual part inspection results. If the false positive rate increases, the detection system is corrected by limiting the range of adaptive adjustment parameters to prevent further performance degradation. By dynamically adjusting the thresholds for surface texture complexity and defect similarity, the optimized system effectively handles complex surfaces, reduces false positives, and ensures the reliability and consistency of detection results, thereby improving the overall quality control efficiency of the production line. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments described in the present invention. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.
[0032] Figure 1 Flow chart of the method of the present invention. DETAILED DESCRIPTION
[0033] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0034] For examples, see Figure 1 As shown, the present embodiment of the present invention provides a method for visually detecting defects of a precision and complex part, comprising the following steps:
[0035] S1: Divide the part surface into S areas to be inspected, and obtain part images under several angles and light source conditions in each area to be inspected, as well as sample data of actual defects and normal surface textures that have been annotated;
[0036] S2: Calculate the eigenvalues of the gray-level co-occurrence matrix of each area to be detected in the part image, obtain the texture feature distribution of each area to be detected on the part surface, perform spectrum analysis on the entire part image, calculate the main frequency distribution, and obtain the surface texture complexity;
[0037] S3: Compare the surface protrusion features and grayscale difference features of the normal texture area on the part surface and the area to be inspected, and calculate the surface defect similarity value in the area to be inspected;
[0038] S4: Based on the surface texture complexity and surface defect similarity values calculated in each area to be inspected, a comprehensive analysis is performed using fuzzy logic to determine the risk of misjudgment in each area to be inspected. Based on the risk of misjudgment in each area to be inspected, each area to be inspected is divided into high-risk areas to be inspected, medium-risk areas to be inspected, and low-risk areas to be inspected. The inspection algorithm is optimized for areas with different risk levels to improve the accuracy of the inspection results.
[0039] S5: Verify the optimized detection algorithm through test data and actual part inspection results, evaluate its performance on complex surfaces, and compare the changes in the false positive rate. If the false positive rate increases, limit the adjustment range of the detection algorithm parameters.
[0040] In S1, the part surface is divided into S areas to be inspected, and part images under several angles and light source conditions in each area to be inspected are obtained, as well as sample data of actual defects and normal surface textures that have been annotated. Specifically:
[0041] Use 3D modeling software or laser scanning technology to obtain part geometry. Mark complex areas, such as corners, curved surfaces, or areas with significant surface variations, as these areas are often prone to defects. Determine the size range for each area based on the overall size of the part. Typically, complex areas are divided more finely, while smooth areas can be more loosely divided. Determine the inspection area to be covered within each area, ensuring that each area is of equal importance or adjusting it as needed. For example, critical functional areas can be divided into smaller inspection areas to increase accuracy.
[0042] The part surface is divided into S regions to be inspected, typically using a regular or adaptive grid. If the part surface is relatively regular, a uniform grid can be used to divide the entire surface into regions of equal area. For example, the surface can be divided into a rectangular or square grid, with each grid representing a region to be inspected. For parts with complex geometries, an adaptive grid is used to adjust the region size based on curvature or changes in surface features. Areas with large surface curvature are given a finer grid, while flat areas are given a larger grid. Each region to be inspected is assigned a unique number to facilitate precise location during image acquisition and data analysis.
[0043] Determine the installation position of the camera and light source to ensure the flexibility and adjustability of the image acquisition equipment. Use a multi-axis robotic arm or an adjustable workbench to ensure that the camera can capture the surface of the part from multiple angles. Set up multiple light sources (such as ring light sources, oblique light sources, backlight sources, etc.) to illuminate the surface of the part in different directions to highlight surface features or defects. Acquire images from different angles of each area to be inspected to ensure that no surfaces are missed. For each area to be inspected, set several different angles, usually including directly above, oblique angles (such as 30°, 45°, 60°), etc., to ensure that all surfaces can be fully captured by the camera. In complex geometric areas, such as grooves or curved surfaces, add additional shooting angles to ensure detection accuracy.
[0044] Utilize different lighting conditions to enhance surface features and highlight defects. Capture images under a variety of lighting conditions, using oblique lighting to capture subtle surface bumps or scratches, ring lighting to eliminate shadows, and backlighting to highlight outlines. Record the specific angle and intensity of each light source so that you can optimize the inspection algorithm based on these lighting conditions in subsequent analysis.
[0045] Acquire complete image data. For each area to be inspected, capture multiple images at different angles and lighting conditions to ensure that every detail of each area is fully captured. Store the captured images and associate them with the number of each area to be inspected.
[0046] By capturing actual defective parts on the production line, we collect common defect types, including scratches, dents, cracks, and contamination. We carefully record the type, location, size, and severity of each defect and capture images of the defects. We then manually annotate the defect images using image annotation software. Specific annotations include the defect's location, edges, shape, and type. This annotation information is combined with the image data to generate a defect sample database for use by the detection algorithm.
[0047] Acquire normal surface texture data and collect surface images of multiple normal parts, ensuring data capture of different texture surfaces under various lighting conditions and angles. For parts made of different materials and surface treatments, obtain corresponding normal surface texture samples, such as polished and frosted surfaces.
[0048] Classify defect images and normal surface images by category, texture features, and surface treatment. Label each image sample (defect or normal texture) and integrate this data into a database for algorithm use.
[0049] In this application, the part surface is first divided into multiple inspection areas to ensure that image data from different angles and lighting conditions can fully capture surface features and defects. By manually annotating actual defects and normal surface textures, a rich dataset is constructed for subsequent training and validation of the detection algorithm. This process not only ensures high-precision defect identification but also provides a valuable data foundation for optimizing the detection algorithm.
[0050] S2: Calculate the eigenvalues of the gray-level co-occurrence matrix of each area to be detected in the part image, obtain the texture feature distribution of each area to be detected on the part surface, perform spectral analysis on the image of the entire part, and calculate the main frequency distribution to obtain the surface texture complexity.
[0051] The Gray Level Co-occurrence Matrix (GLCM) is a statistical method used to describe the spatial relationship between the grayscale levels of pixels in an image. The GLCM represents the frequency of grayscale values between adjacent pixels in an image and can effectively describe the texture characteristics of an image.
[0052] Let's denote the grayscale of an image as G, with pixel values ranging from 0 to G-1. The GLCM is a G×G matrix, where each element P(i, j) represents the number of times a pixel with value i co-occurs with a pixel with value j at a given pixel spacing and orientation. The orientation and distance are set: 0°, 45°, 90°, and 135° are commonly chosen, and a distance of 1 pixel is commonly used. The grayscale co-occurrence matrix P(i, j) is constructed by counting the number of co-occurrences of pixels at each grayscale level at a given orientation and distance.
[0053] Commonly used eigenvalues of the gray-level co-occurrence matrix include contrast, entropy, homogeneity, and correlation, which describe different aspects of image texture. Among them, contrast is used to measure the degree of difference between grayscale values in an image. The higher the value, the more drastic the grayscale changes of pixels in the image and the rougher the texture. The expression is: Where, is the contrast, and entropy represents the randomness and uncertainty of the image. The larger the entropy value, the more complex the image texture. The expression is: ; is a constant used to avoid zero when taking logarithms. is entropy; homogeneity describes whether the grayscale values of adjacent pixels in the image are similar. The larger the value, the smoother the image texture. The expression is: ; is homogeneity; calculate the linear correlation between pixels. An image with high correlation indicates that there is a strong linear dependence between pixels. The linear correlation calculation expression is: Where, is a linear correlation. For each region to be detected, the above eigenvalues of the gray-level co-occurrence matrix are calculated to obtain the texture feature distribution of each region. Separate calculations can be performed for different directions (0°, 45°, 90°, and 135°) and the average is taken to obtain the comprehensive texture feature.
[0054] Perform spectrum analysis on the image of the entire part and convert the spatial domain image into the frequency domain. The information in the frequency domain can reveal the periodicity and texture patterns in the image. The conversion expression is: Where f(x,y) is the pixel value of the image, F(u,v) is the Fourier coefficient in the frequency domain, M and N are the width and height of the area to be detected, u and v are the frequency coordinates, and j is the imaginary unit. The modulus value of the Fourier transform is calculated to obtain the spectrum information of the image. The expression is: Where, is the modulus of the Fourier transform, are the real and imaginary parts of the Fourier transform, and the amplitude spectrum of the Fourier transform It reflects the frequency distribution in the image. In order to visually represent the spectrum more clearly, we can take the logarithm of the amplitude spectrum, that is, calculate the logarithmic amplitude spectrum. , the expression is: The main frequency reflects the dominant texture periodicity and feature change frequency in the image. Through spectrum analysis, the main frequency components of the image can be extracted. The frequency distribution of the highest peak in the spectrum is calculated, that is, which frequencies dominate the image. The main frequency is determined by the peak position in the statistical amplitude spectrum. , the expression is: The main frequency reflects the most significant texture pattern in the image. Usually, high frequency means complex surface texture, while low frequency means smooth texture.
[0055] The surface texture complexity is measured by the ratio of high-frequency components in the spectrum. Images with more high-frequency components have complex textures, while images with more low-frequency components have smooth textures. The calculation expression is: Where, Indicates high-frequency components greater than the preset high-frequency threshold. is the surface texture complexity.
[0056] A higher level of surface texture complexity means more high-frequency details and complex variations, such as small bumps, cluttered textures, or minute surface features. In these cases, detection algorithms can easily misclassify normal complex textures as defects, as normal textures are visually difficult to distinguish from actual defects. Highly complex areas are more prone to false positives, where the system mistakenly identifies a normal surface as a defect, increasing the risk of misjudgment. Therefore, in highly complex areas, the system requires stricter control of detection parameters to avoid misjudgments.
[0057] Conversely, lower surface texture complexity indicates a smoother and more uniform texture, with less pixel variation and significantly different defect signatures from a normal surface. In this case, detection algorithms are more likely to accurately identify actual defects because surface anomalies are more visible. However, if the algorithm relies too heavily on high sensitivity parameters, it may overlook small and subtle defects, leading to false negatives—failure to detect actual defects. Therefore, while low-complexity areas have a lower risk of false positives, the risk of false negatives should be mitigated.
[0058] S3: Compare the surface protrusion features and grayscale difference features of the normal texture area on the part surface and the area to be inspected, and calculate the surface defect similarity value in the area to be inspected.
[0059] Preprocessing is performed on the acquired images of the area to be inspected and the normal texture area, including denoising, contrast enhancement, and edge detection, to ensure image quality and facilitate subsequent feature extraction. Common filtering methods include Gaussian filtering and median filtering to eliminate noise and ensure clear protrusions and defect features.
[0060] Use morphological operations (such as dilation, erosion, gradient) to detect the shape features of surface protrusions. The expression is: Where I is the image, Dilation and Erosion represent dilation and erosion operations respectively. Edge detection algorithms (such as Sobel and Canny operators) are applied to detect the edges of the protrusions, extract the geometric parameters of the protrusions, and calculate the area to be detected pixel by pixel. and normal area Grayscale difference , the expression is: ; Then calculate the average grayscale difference of the entire area , the expression is: ; Where M and N are the width and height of the area to be detected, and H is the total number of pixels; the surface protrusion features are compared using cosine similarity, and the protrusion feature vectors are normal areas and the area to be detected , the expression is: Where, represents the dot product of the protrusion eigenvectors, 、 are the moduli of the protruding feature vectors of the normal area and the area to be detected. Calculate the grayscale difference similarity , the similarity of grayscale difference can also be measured by cosine similarity, and the grayscale vectors are normal areas and the area to be detected , the expression is: ; The surface defect similarity value is obtained by performing weighted average calculation on the protrusion feature similarity and grayscale difference similarity.
[0061] A higher surface defect similarity value indicates that the difference between the inspected area and the normal surface texture is small, meaning that the surface features of the inspected area are very similar to those of the normal area. In this case, the detection algorithm struggles to distinguish between a normal surface and an actual defect, leading to misjudgments, mistaking a normal complex texture for a defect (false positives). Therefore, a higher similarity value increases the risk of misjudgment in each inspected area. Especially in the case of complex surface textures, the detection system may become overly sensitive, leading to an increased false positive rate.
[0062] On the contrary, when the surface defect similarity value is smaller, it indicates that there are obvious differences between the area to be detected and the normal surface texture area, and the surface feature differences are significant. In this case, the detection algorithm can accurately identify the difference between the defect and the normal area, and the risk of misjudgment is relatively low. However, if the similarity is too small, the detection system may be insensitive to relatively small or hidden defects on the surface, resulting in false negatives, that is, the actual existing defects are not detected. Therefore, the smaller the similarity value, the lower the risk of false positives, but attention should be paid to preventing the possibility of false negatives.
[0063] S4: According to the surface texture complexity and surface defect similarity values calculated in each area to be detected, through comprehensive analysis using fuzzy logic, determine the risk of detection misjudgment in each area to be detected; according to the risk of detection misjudgment in each area to be detected, divide each area to be detected into high-risk areas to be detected, medium-risk areas to be detected, and low-risk areas to be detected, and optimize the detection algorithm for areas to be detected with different risk levels to improve the accuracy of the detection results.
[0064] Take the surface texture complexity CZ and the surface defect similarity value HG as the input items of fuzzy logic, and take the risk level L of detection misjudgment in each area to be detected as the output item of fuzzy logic;
[0065] The surface texture complexity CZ describes the complexity of the surface texture in the area to be detected. The more complex the surface texture, the more high-frequency information it contains, and the detection algorithm is likely to misjudge normal texture as a defect. Fuzzification: According to different texture complexities, divide the value range of CZ into several fuzzy sets: Low complexity (Low): The surface texture is smooth and uniform, with low complexity. Medium complexity (Medium): The surface has certain texture changes but is not complex. High complexity (High): The surface texture has many changes and rich high-frequency information.
[0066] The specific fuzzification method can be set according to experience in actual applications. For example, assuming the value range of CZ is [0, 1], then: CZ ≤ 0.3 is low complexity; 0.3 < CZ ≤ 0.7 is medium complexity; CZ > 0.7 is high complexity.
[0067] The surface defect similarity HG measures the degree of feature similarity between the area to be detected and the normal surface area. The higher the similarity value, the more similar the area to be detected is to the normal area, and the greater the possibility of misjudgment. Fuzzification: According to the level of the similarity value, HG is divided into the following fuzzy sets: Low similarity (Low): The area to be detected is significantly different from the normal surface, and the detection system can easily distinguish them. Medium similarity (Medium): The area to be detected has a certain similarity to the normal area. High similarity (High): The area to be detected is extremely similar to the normal area, which is likely to cause misjudgment. For example, assuming the value range of HG is [0, 1], then: HG ≤ 0.3 is low similarity; 0.3 < HG ≤ 0.7 is medium similarity; HG > 0.7 is high similarity.
[0068] The risk level L reflects the risk of misjudgment in each area to be detected, and is divided into three levels: low, medium, and high: Low risk (Low): The risk of misjudgment is small, and the detection is relatively reliable. Medium risk (Medium): There is a certain possibility of misjudgment, and the algorithm needs to be further adjusted. High risk (High): The risk of misjudgment is high, and the detection system needs to focus on processing.
[0069] Convert the input items CZ and HG into the corresponding fuzzy sets. Use the membership function to relate the input value to the membership degree of the fuzzy set. Common membership functions include triangular membership functions and trapezoidal membership functions.
[0070] For the surface texture complexity (CZ): Low: When CZ ∈ [0, 0.3], the membership degree is 1; when CZ ∈ (0.3, 0.5], the membership degree gradually decreases. Medium: When CZ ∈ [0.3, 0.7], the membership degree is 1. High: When CZ > 0.7, the membership degree is 1.
[0071] For the surface defect similarity (HG): Low: When HG ∈ [0, 0.3], the membership degree is 1; when HG ∈ (0.3, 0.5], the membership degree gradually decreases. Medium: When HG ∈ [0.3, 0.7], the membership degree is 1. High: When HG > 0.7, the membership degree is 1.
[0072] Based on the surface texture complexity (CZ) and the surface defect similarity (HG), fuzzy rules are set to derive the risk level (L). These rules are usually expressed in an "if-then" form. Rule example: If CZ is low complexity and HG is low similarity, then L is low risk. If CZ is low complexity and HG is high similarity, then L is medium risk. If CZ is high complexity and HG is high similarity, then L is high risk. If CZ is high complexity and HG is low similarity, then L is medium risk. If CZ is medium complexity and HG is medium similarity, then L is medium risk. These rules can be expanded according to specific applications, such as adding more fuzzy sets or more complex logical relationships.
[0073] Defuzzification converts the results of fuzzy inference into clear output values. Common defuzzification methods include the centroid method, which calculates the centroid of the fuzzy set to obtain the final output value.
[0074] By outputting the risk level of misjudgment, the high-risk area to be detected is divided into high-risk area to be detected, the medium-risk area to be detected is divided into medium-risk area to be detected, and the low-risk area to be detected is divided into low-risk area to be detected. The detection algorithm is optimized for the areas to be detected at different risk levels to improve the accuracy of the detection results. Specifically:
[0075] The surface texture of high-risk areas is complex, and it is easy to confuse the normal surface with the defective area, so it needs to be optimized. The optimization measures include:
[0076] Multi-angle and multi-light source detection: To reduce the impact of surface texture complexity on detection, increase shooting angles and light source conditions to ensure that surface features can be accurately captured under different conditions.
[0077] Multi-scale analysis: Use multi-scale feature extraction methods (such as scale-invariant feature transform (SIFT) and HOG features) to analyze images at different resolutions. Multi-scale analysis can capture defect information at different scales, avoiding missing subtle defects.
[0078] Adaptive threshold adjustment: In high-risk areas, the detection threshold should be dynamically adjusted based on the surface complexity within the area. Setting an adaptive threshold ensures that detection sensitivity is appropriately increased in high-complexity areas while avoiding oversensitivity.
[0079] Enhanced texture feature extraction algorithm: Introducing more powerful texture analysis algorithms, such as Gabor filters and advanced features of gray-level co-occurrence matrices (such as energy and entropy), to ensure better differentiation between complex textures and real defects.
[0080] Integrate multiple detection methods: Combine visual inspection with other detection methods, such as ultrasound and X-ray, to conduct multi-modal inspection of high-risk areas to ensure the reliability of detection results.
[0081] Detection goal: Improve the detection rate of real defects in complex areas and reduce the occurrence of false positives and missed negatives.
[0082] The risk of misjudgment in medium-risk areas is moderate and needs to be reduced through appropriate optimization. Optimization measures include:
[0083] Local enhancement detection: In medium-risk areas, surface features can be enhanced through selective local enhancement image processing (such as local contrast enhancement, edge detection) to more accurately distinguish between normal surfaces and potential defects.
[0084] Statistical classification algorithms: Use machine learning-based classification algorithms (such as support vector machines (SVMs) or random forests) to analyze the characteristics of medium-risk areas, thereby improving the ability to classify specific defect patterns. Models can be trained using existing labeled data.
[0085] Morphological operation optimization: Morphological dilation and erosion operations are used to further optimize the boundary identification of defect areas and enhance the detection effect of medium-complexity areas.
[0086] Flexible detection parameter adjustment: Algorithm optimization in medium-risk areas should remain flexible. It does not require extremely high sensitivity, but should be able to adapt to regional characteristics and improve detection efficiency by appropriately adjusting parameters.
[0087] Detection goal: Balance detection efficiency and accuracy in moderately complex areas, reducing false positives while maintaining detection speed.
[0088] Low-risk areas are relatively simple and easy to detect, but the accuracy of the basic algorithm must be ensured. Optimization measures include:
[0089] Standardized inspection process: In low-risk areas, a relatively standardized inspection process can be used. Overly complex algorithms are not required, but basic defect detection accuracy must be ensured.
[0090] Threshold detection: A relatively high detection threshold can be used to reduce sensitivity to small noises and slight textures, thereby reducing the possibility of false positives.
[0091] Accelerate detection algorithms: In low-risk areas, the algorithm can be simplified and use fast detection methods (such as region-based fast edge detection or simple binarization) to improve overall detection efficiency.
[0092] Low resource consumption: Because low-risk area detection tasks are relatively simple, they can reduce the consumption of computing resources and optimize overall system performance. This ensures detection accuracy in low-risk areas while improving detection efficiency and reducing resource consumption.
[0093] S5: Verify the optimized detection algorithm through test data and actual part inspection results, evaluate its performance on complex surfaces, and compare the changes in the false positive rate. If the false positive rate increases, limit the adjustment range of the detection algorithm parameters.
[0094] Collect images of parts with a variety of complex surfaces, including parts with actual defects and normal parts. These datasets should include highly complex surface features (such as polished, frosted, and curved surfaces) to fully evaluate the optimized inspection algorithm.
[0095] Use the optimized detection algorithm to detect the parts in the test data set and record the results of each detection, including: the area TP correctly detected as a defect, the part TN correctly detected as a normal area, the normal area FP incorrectly detected as a defect, and the defect area FN incorrectly ignored. According to the detection results, calculate the error rate of different areas , the expression is: ; Calculate the misjudgment rate for high-risk, medium-risk and low-risk areas respectively , in order to understand the performance of each risk area in more detail; by comparing the test data with the detection results of the previous unoptimized algorithm, the change value of the misjudgment rate of each risk level area is calculated, and the expression is: Where, is the change value of the misjudgment rate, is the optimized misjudgment rate, is the false positive rate before optimization. If ΔFPR>0, it means that the false positive rate of the optimized algorithm increases. If ΔFPR<0, it means that the false positive rate of the optimized algorithm decreases and the detection performance is improved.
[0096] When the misjudgment rate increases, it means that the parameter adjustments during the optimization process may have introduced new misjudgment risks. In this case, misjudgments can be reduced by limiting the adjustment range of certain key parameters.
[0097] Optimized detection algorithms often adaptively adjust certain parameters (such as grayscale threshold, edge detection threshold, feature extraction sensitivity, etc.). If these parameters are over-adjusted, the false positive rate may increase, so the adjustment range of these parameters needs to be limited.
[0098] The parameters that need to be adjusted during the detection process are marked as , limiting its adjustment range, the expression is: ; and are the lower and upper limits of the parameter, defining the allowable adjustment range. Is the currently calculated adaptive adjustment value. If If the value exceeds the preset range, the system will correct it to the preset upper and lower limits to avoid excessive parameter adjustment and increase in false positives. For example, in the grayscale threshold adjustment of the image, assuming that the grayscale threshold of the initial detection algorithm is =128, after optimization, it is adjusted to = 150. If the false positive rate increases, the threshold range can be set to [120, 140] so that the adaptive adjustment does not exceed this range, thereby preventing false positives caused by excessive adjustment.
[0099] When detecting complex surfaces, the surface texture complexity CZ has a significant impact on detection performance. Misjudgments can be reduced by limiting certain algorithm parameters when processing complex textures (such as the scale of feature extraction and the window size of texture analysis). The adjusted expression is: ; and is the allowed texture complexity processing range, is the adjusted surface texture complexity, is the currently calculated surface texture complexity. By limiting the value range of parameter CZ, we can avoid overly sensitive detection in areas with excessively complex surface textures, preventing the detection system from misjudging normal surfaces as defects. Surface defect similarity HG is a key indicator for measuring the similarity between the area to be inspected and the normal surface. As the misjudgment rate increases, it is necessary to constrain the similarity threshold to prevent the algorithm from being overly sensitive to similar features. The constraint expression is: Where, is the range allowed by the similarity threshold, is the adjusted surface defect similarity, It is the surface defect similarity currently calculated. By limiting the similarity threshold, the false alarms of the detection system in similar feature areas can be reduced, thereby reducing the misjudgment rate.
[0100] By limiting the adjustment range of key parameters, the risk of misjudgment introduced during the optimization process can be reduced. After limiting the parameter range, retest the test data and calculate the new misjudgment rate. , compare the changes in misjudgment rate: ; is the change in the error rate after adjustment. If ΔFPR′<0, it means that the error rate is effectively reduced by limiting the parameter adjustment range.
[0101] In this application, evaluating changes in the false positive rate using test data and actual part inspection results is a key step in optimizing the detection algorithm. If an increase in the false positive rate is detected, the adjustment range of key detection algorithm parameters (such as threshold, similarity, and texture complexity) can be limited to prevent false positives caused by excessive parameter adjustments. By adjusting and controlling these key parameters through formulas, the false positive rate can be effectively reduced, improving the accuracy of the detection algorithm on complex surfaces.
[0102] In this embodiment, the surface of the part is divided into multiple areas to be inspected, and images are collected under different angles and light source conditions, and the marked defects and normal texture data are used as references. Then, the eigenvalues of the grayscale co-occurrence matrix of each area are calculated, the distribution of its texture features is analyzed, and the surface texture complexity is obtained by spectral analysis. Next, the surface defect similarity value is calculated by comparing the surface protrusion features and grayscale differences between the area to be inspected and the normal area. Based on the surface texture complexity and defect similarity values, fuzzy logic is used to evaluate the misjudgment risk of each area, and it is divided into high, medium and low risk areas. For areas with different risk levels, the detection algorithm is optimized to improve the accuracy of detection. Finally, the optimization effect is verified by test data and actual detection results, the change in the misjudgment rate is evaluated, and the adjustment range of the algorithm parameters is limited when the misjudgment rate increases to ensure detection accuracy and system stability.
[0103] The above formulas are all dimensionless and numerical calculations. The formulas are obtained by collecting a large amount of data and performing software simulation to obtain the most recent real situation. The preset parameters in the formulas are set by technicians in this field according to actual conditions.
[0104] The above embodiments can be implemented in whole or in part by software, hardware, firmware or any other combination. When implemented using software, the above embodiments can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions or computer programs. When the computer instructions or computer program are loaded or executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center via wired or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that contains one or more available media sets. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium. The semiconductor medium can be a solid-state drive.
[0105] It should be understood that the term "and / or" herein is merely a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B may represent three situations: A exists alone, A and B exist at the same time, and B exists alone, where A and B may be singular or plural. In addition, the character " / " herein generally indicates that the objects associated with each other are in an "or" relationship, but it may also indicate an "and / or" relationship, which can be understood by referring to the context. A person of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0106] The above is only a specific implementation method of the present application, but the scope of protection of the present application is not limited thereto. Any technician familiar with this technical field can easily think of changes or replacements within the technical scope disclosed in this application, which should be covered by the scope of protection of the present application.
Claims
1. A method for visually detecting defects in precision and complex parts, characterized by: The following steps are included: S1: Divide the part surface into S areas to be inspected, and obtain part images under several angles and light source conditions in each area to be inspected, as well as sample data of actual defects and normal surface textures that have been annotated; S2: Calculate the eigenvalues of the gray-level co-occurrence matrix of each area to be detected in the part image, obtain the texture feature distribution of each area to be detected on the part surface, perform spectrum analysis on the entire part image, calculate the main frequency distribution, and obtain the surface texture complexity; S3: Compare the surface protrusion features and grayscale difference features of the normal texture area on the part surface and the area to be inspected, and calculate the surface defect similarity value in the area to be inspected; S4: Based on the surface texture complexity and surface defect similarity values calculated in each area to be inspected, a comprehensive analysis is performed using fuzzy logic to determine the risk of misjudgment in each area to be inspected; Based on the risk of misjudgment in each area to be inspected, each area to be inspected is divided into high-risk, medium-risk and low-risk areas to be inspected. The detection algorithm is optimized for areas with different risk levels to improve the accuracy of the detection results. S5: Verify the optimized detection algorithm through test data and actual part inspection results, evaluate its performance on complex surfaces, and compare the changes in the false positive rate. If the false positive rate increases, limit the adjustment range of the detection algorithm parameters.
2. The method for visually inspecting defects of precision and complex parts according to claim 1, wherein: In S2, the spectrum analysis of the image of the entire part is performed, and the main frequency distribution is calculated to obtain the surface texture complexity, which is specifically: Perform spectrum analysis on the image of the entire part and convert the image in the spatial domain to the frequency domain. The conversion expression is: Where f(x,y) is the pixel value of the image, F(u,v) is the Fourier coefficient in the frequency domain, M and N are the width and height of the area to be detected, u and v are the frequency coordinates, and j is the imaginary unit. The modulus value of the Fourier transform is calculated to obtain the spectrum information of the image. The expression is: Where, is the modulus of the Fourier transform, are the real and imaginary parts of the Fourier transform, respectively, and the logarithmic amplitude spectrum is calculated , the expression is: ; Calculate the frequency distribution of the highest peak in the spectrum and determine the main frequency by counting the peak position in the amplitude spectrum , the expression is: ; The surface texture complexity is measured by the proportion of high-frequency components in the spectrum, and the calculation expression is: Where, Indicates high-frequency components greater than the preset high-frequency threshold. is the surface texture complexity.
3. The method for visually inspecting defects of precision and complex parts according to claim 2, characterized in that: In S3, the surface defect similarity value in the area to be detected is calculated, specifically: Morphological operations are used to detect the shape features of surface protrusions. The expression is: Where I is the image, Dilation and Erosion represent dilation and erosion operations respectively. The edge detection algorithm is applied to detect the edge of the protrusion, extract the geometric parameters of the protrusion, and calculate the area to be detected pixel by pixel. and normal area Grayscale difference , the expression is: ; Then calculate the average grayscale difference of the entire area , the expression is: ; Where M and N are the width and height of the area to be detected, and H is the total number of pixels; the surface protrusion features are compared using cosine similarity, and the protrusion feature vectors are normal areas and the area to be detected , the expression is: Where, represents the dot product of the protrusion eigenvectors, 、 are the moduli of the protruding feature vectors of the normal area and the area to be detected; calculate the grayscale difference similarity , the similarity of grayscale difference is measured by cosine similarity, and the grayscale vectors are normal areas and the area to be detected , the expression is: ; The surface defect similarity value is obtained by performing weighted average calculation on the protrusion feature similarity and grayscale difference similarity.
4. The method for visually inspecting defects of precision and complex parts according to claim 3, wherein: In S4, based on the surface texture complexity and surface defect similarity values calculated in each area to be inspected, a comprehensive analysis is performed using fuzzy logic to determine the risk of misjudgment in each area to be inspected, specifically: The surface texture complexity and surface defect similarity values are used as input items of fuzzy logic, and the risk level of misjudgment of each area to be inspected is used as the output item of fuzzy logic; The input surface texture complexity and surface defect similarity values are converted into fuzzy sets, and the membership degree of each set is calculated; Reasoning is performed based on fuzzy rules, combining the membership of surface texture complexity and surface defect similarity values to derive the fuzzy output of risk level; The defuzzification method is used to calculate a clear risk level, that is, the risk of misjudgment in the area to be detected; Output the risk level of the detection misjudgment, divide the to-be-detected area with a high risk level into a high risk to-be-detected area, divide the to-be-detected area with a medium risk level into a medium risk to-be-detected area, and divide the to-be-detected area with a low risk level into a low risk to-be-detected area.
5. The method for visually inspecting defects of precision and complex parts according to claim 1, wherein: In S5, the optimized detection algorithm is verified using test data and actual part inspection results. Its performance on complex surfaces is evaluated and the change in the false positive rate is compared. If the false positive rate increases, the adjustment range of the detection algorithm parameters is limited. Specifically, Collect images of various complex surface parts, including parts with actual defects and normal parts, use the optimized detection algorithm to detect the parts in the test data set, and record the results of each detection, including: the area TP correctly detected as a defect, the part TN correctly detected as a normal area, the normal area FP incorrectly detected as a defect, and the defect area FN incorrectly ignored. Based on the detection results, calculate the error rate of different areas , the expression is: ; Calculate the misjudgment rate for high-risk, medium-risk and low-risk areas respectively By comparing the test data with the detection results of the previously unoptimized algorithm, the change in the misjudgment rate of each risk level area is calculated. The expression is: Where, is the change value of the misjudgment rate, is the optimized misjudgment rate, is the false positive rate before optimization. If ΔFPR>0, it means that the false positive rate of the optimized algorithm increases. If ΔFPR<0, it means that the false positive rate of the optimized algorithm decreases and the detection performance is improved.
6. The method for visually inspecting defects of precision and complex parts according to claim 5, characterized in that: In S5, when the misjudgment rate increases, the parameters that need to be adjusted during the detection process are marked as , limiting its adjustment range, the expression is: ; and are the lower and upper limits of the parameter, respectively. is the adaptive adjustment value currently calculated; if If it exceeds the preset range, the system will correct it to the preset upper and lower limits; When detecting complex surfaces, we can reduce misjudgment by limiting the algorithm parameters when processing complex textures. The expression is adjusted to: ; and is the allowed texture complexity processing range, is the adjusted surface texture complexity, is the currently calculated surface texture complexity; When the misjudgment rate increases, the similarity threshold needs to be constrained. The constraint expression is: ; Where, is the range allowed by the similarity threshold, is the adjusted surface defect similarity, is the surface defect similarity currently calculated; After limiting the parameter range, retest the test data and calculate the new error rate , compare the changes in misjudgment rate: ; is the change in the error rate after adjustment. If ΔFPR′<0, it means that the error rate is reduced by limiting the parameter adjustment range.
Citation Information
Patent Citations
Part surface quality detection method and system based on machine vision
CN118608504A
Visual inspection method for surface quality of precise injection mold base
CN119985484A