A method and system for detecting component surface quality based on machine vision

Through machine vision technology, combined with Gaussian filtering, histogram equalization and deep learning models, the surface defects of parts are identified, solving the problems of low efficiency and high maintenance costs of existing detection methods, and achieving efficient and accurate automated detection.

CN118608504BActive Publication Date: 2024-12-13GUANGZHOU HONGJIANG INTELLIGENT EQUIP CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410793478.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-19
Publication Date
2024-12-13
Estimated Expiration
2044-06-19

AI Technical Summary

Technical Problem

The existing surface quality detection methods for parts are inefficient, prone to missed inspection and error inspection, and have high maintenance costs and cannot be flexibly customized, which limits the flexibility and scalability of inspection.

Method used

Using machine vision-based detection methods, the parts images are acquired through image acquisition equipment, Gaussian filtering denoising, histogram equalization, and edge sharpening are performed, surface texture features are extracted in combination with grayscale symbiosis matrix, and defects are identified using deep learning models. , automatically mark defect areas.

Benefits of technology

It improves detection efficiency and accuracy, enhances the automation and intelligence of detection, adapts to different parts and environments, reduces manual intervention, meets a wider range of industrial application needs, and optimizes cost and time efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118608504B_ABST
    Figure CN118608504B_ABST
Patent Text Reader

Abstract

The present invention discloses a component surface quality detection method and system based on machine vision, and the method steps include: S1, acquiring an image of a component to be detected; S2, preprocessing the image of the component to be detected, and extracting contour features by using an edge detection algorithm, extracting surface texture features by using a grayscale co-occurrence matrix, and converting them into feature vectors to input into a clustering algorithm; S3, comparing the extracted features with a predefined model to identify whether there are surface defects, and training and identifying different types of defect patterns through a deep learning algorithm; S4, automatically marking defective areas based on the comparison results between the features and the model; the present invention uses an advanced image preprocessing technology, and uses an edge detection algorithm and a grayscale co-occurrence matrix to extract features, comprehensively captures the surface characteristics of components, and improves the accuracy of feature vector construction; quickly and accurately identifies tiny defects through a deep learning model, and improves recognition accuracy and efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the technical field of image processing, and in particular to a component surface quality detection method and system based on machine vision. Background Art

[0002] At present, there are two main ways to inspect the surface quality of parts after production, namely manual visual inspection and special visual inspection system. Both methods have obvious shortcomings. Manual visual inspection has high requirements for personnel, is easy to fatigue, has low efficiency, and is prone to missed inspections and wrong inspections. The visual inspection system has high maintenance costs, low degrees of freedom for change, cannot be flexibly customized, and is not conducive to expansion. Therefore, a method and system for surface quality inspection of parts based on machine vision are proposed. By setting an image acquisition device at a preset position, the recognition image is compared with the set model, and the judgment result is obtained to complete the online quality inspection of parts, thereby improving the inspection efficiency. Summary of the invention

[0003] In order to solve the problems existing in the above background technology, the present invention adopts the following technical solutions:

[0004] The present application provides a component surface quality detection method based on machine vision, comprising the following steps:

[0005] S1. Obtain an image of the component to be inspected, including the contour shape and surface processing texture of the component;

[0006] S2. Preprocess the images of the parts to be inspected, including denoising, contrast adjustment, color balance, and edge sharpening. At the same time, use the edge detection algorithm to extract contour features, use the gray level co-occurrence matrix to extract surface texture features, and convert them into feature vectors to input into the clustering algorithm;

[0007] S3, compare the extracted features with the predefined model to identify whether there are surface defects, train and identify different types of defect patterns through deep learning algorithms, and distinguish different types of defects;

[0008] S4. According to the comparison results between the features and the model, the defective area will be automatically marked.

[0009] Furthermore, the image of the component to be inspected is obtained by installing an image acquisition device at a preset position, adjusting the viewing angle and position of the device according to the position and size of the component to be inspected, so as to capture the image of the component from multiple angles, including the contour shape and surface processing texture of the component.

[0010] Furthermore, the image of the component to be inspected is preprocessed, and the noise in the image is removed using the Gaussian filter method, which specifically includes:

[0011] S201, selecting a Gaussian kernel of an odd size in the image of the component and determining a center point;

[0012] S202, calculating the weight of each position in the kernel by using a Gaussian function and performing normalization processing;

[0013] S203, sliding the Gaussian kernel to each point of the image, and calculating a new pixel value;

[0014] The formula for calculating the new pixel value is expressed as:

[0015]

[0016] in, is the original image at coordinates ( , ), is the normalized Gaussian kernel in ( , ) weight, ( , ) relative to the center point The weight of is the filtered image at the center point The pixel value of is the sum of all x and y coordinates in the region covered by the Gaussian kernel.

[0017] Furthermore, the image contrast is enhanced by using the histogram equalization method to make the surface features of the parts more obvious. The specific contents include:

[0018] S211, calculating the histogram of the original image. The histogram is a statistic of the number of pixels at each gray level in the image, and displays the distribution of the intensity value of each pixel in the image. Specifically, it is expressed as:

[0019]

[0020] in, is the Kronecker function (1 if the pixel value is equal to i, 0 otherwise), and H are the width and height of the image respectively;

[0021] S212, determine the cumulative distribution function, calculate the cumulative distribution function of the histogram, and represent the pixel ratio of each gray level and the gray levels below it in the image. The specific cumulative distribution function is expressed as:

[0022]

[0023] in, is the cumulative probability of occurrence of gray level i and all gray levels below it, is the probability that gray level i appears in the image;

[0024] S213, normalizing CDF, normalizing the cumulative distribution function so that its maximum value is 1;

[0025] S214, mapping grayscale, using normalized CDF to map each pixel intensity value of the original image to a new grayscale;

[0026] S215, mapping function, replacing each pixel value in the original image with its corresponding new grayscale value to obtain an image with enhanced contrast;

[0027] Ensure that the colors in the image truly reflect the actual colors of the parts by correcting color deviations;

[0028] Use the gradient sharpening method to highlight the edge information of the image and make the contour clearer.

[0029] Furthermore, the contour feature extraction uses the Canny edge detection algorithm to identify edge information in the image while performing preprocessing, performs non-maximum suppression on the Canny edge detection result, and then performs an edge connection operation to connect the broken edge fragments into a complete contour; according to the edge detection result, the contour feature of the component is extracted, the coordinate information of the edge pixel is obtained, and the shape contour of the component is described;

[0030] Specifically, the Canny algorithm uses a pair of convolution kernels to calculate the gradient magnitude and direction of the image in the horizontal and vertical directions. The gradient magnitude is expressed as: ;direction ;

[0031] in, represents the horizontal gradient kernel ; Vertical gradient kernel

[0032] ;

[0033] Then use the double threshold strategy to connect strong edges and set a high threshold and low threshold , forming a strong edge and weak edge ;

[0034] when > When = ;

[0035] when When = , starting from the strong edge, trace the connected weak edges to form a complete edge chain.

[0036] Furthermore, the gray level co-occurrence matrix is ​​used to extract surface texture features and describe the texture information of the surface of the component, and the specific contents include:

[0037] Construct a gray-level co-occurrence matrix, using gradient magnitude and direction information to determine the spatial relationship between pixels;

[0038] Construct a co-occurrence matrix at a specific direction and distance;

[0039] The texture complexity of the image is described by calculating the entropy, energy, and contrast of the gray-level co-occurrence matrix;

[0040] Surface texture features are extracted through gray-level co-occurrence matrix analysis.

[0041] Furthermore, the extracted features are organized into vectors and input into a clustering algorithm, wherein the extracted features are organized into vectors including fusing all calculated eigenvalues ​​into a single eigenvector with each eigenvalue being a dimension of the vector, and then constructing a eigenvector for each data point as input to the clustering algorithm, and using the clustering algorithm to divide the data points into different groups according to the eigenvectors.

[0042] Furthermore, the predefined model is various trained neural network models used for surface defect detection in deep learning, which are used to identify and classify different surface defects. The establishment process includes:

[0043] S31. Collect images of parts to be inspected, including normal samples and samples containing various defects;

[0044] S32, annotating the collected images to clarify the type, location and severity of the defects. For pixel-level defect detection, pixel-level annotation is performed to determine the specific location of each defective pixel;

[0045] S33, designing an input layer according to the feature vector of the selected image or the group divided by clustering, and determining the same data format;

[0046] S34, use the convolution layer to extract image features and capture local features;

[0047] S35. Use activation functions such as ReLU to increase nonlinearity. For multi-class classification tasks, the output layer usually uses the softmax activation function to output probabilities of multiple categories.

[0048] Among them, the extracted features are compared with the predefined model, the feature vector or the clustered group is input into the trained deep learning model for prediction, and the output features of the model are compared to see if there are surface defects.

[0049] Furthermore, when the output result has surface defects, the original score is converted into probability through the softmax activation function to distinguish different types of defects. The specific calculation formula is expressed as:

[0050]

[0051] in, is the probability that the model predicts that the image belongs to the i-th class, is the raw score of the i-th unit in the model output layer, and n represents all categories. The output of the softmax function is the probability that the model predicts that the input image belongs to each category.

[0052] Furthermore, the defect area is automatically marked by comparing the input image with the model, and for an area in the image, the defect probability is output by the softmax function, and a threshold T is set. When the obtained probability is greater than the threshold T, the area is determined to be a defect area and marked.

[0053] Traverse the entire image area and perform the above probability calculation and marking operations on each area;

[0054] The marked defect areas are visualized on the image.

[0055] A component surface quality inspection system based on machine vision, including a data acquisition module, a data preprocessing module, a feature analysis module, and an automatic marking module.

[0056] The data acquisition module installs a high-precision image acquisition device at a preset position, and adjusts the viewing angle and position of the device according to the position and size of the parts to capture the contour shape and surface processing texture of the parts at multiple angles;

[0057] The data preprocessing module performs necessary preprocessing operations on the image of the component to be inspected, including denoising, contrast adjustment, color balance and edge sharpening, extracts contour features using an edge detection algorithm, and extracts surface texture features using a gray level co-occurrence matrix;

[0058] The feature analysis module organizes the extracted contour features and surface texture features into vectors, compares them with the established predefined model, and identifies whether there are surface defects;

[0059] The automatic marking module, when the model identifies surface defects, calculates the probability of each category of defects through the softmax activation function, and then sets a threshold T. When the probability is greater than the threshold T, the defect area is automatically marked according to the output of the model.

[0060] The beneficial effects of the present invention are:

[0061] (1) Combining advanced image preprocessing technology and deep learning models, through sophisticated preprocessing steps such as Gaussian filtering for denoising and histogram equalization for contrast adjustment, the image data input into the deep learning model is ensured to be of high quality. In addition, the application of deep learning models makes it possible to quickly and accurately identify tiny defects from complex image data, further enhancing the automation and intelligence level of the inspection process. While improving the accuracy of component surface defect detection, it also significantly improves the efficiency of the inspection process.

[0062] (2) Through the non-maximum suppression and dual threshold strategy of the Canny edge detection algorithm, as well as the texture feature extraction of the gray-level co-occurrence matrix, the system can adapt to a variety of different parts and application scenarios. This adaptability ensures that the system can work effectively in a variety of environments, whether for parts of different shapes, sizes or materials, or under different lighting and background conditions, it can maintain a high level of detection performance, making the system more versatile and reliable, and able to meet a wider range of industrial application needs;

[0063] (3) By automatically marking defective areas, quality control and subsequent analysis are greatly facilitated. The softmax activation function is used to convert the original scores into probabilities, which enables the distinction of different types of defects and automatically marks the defective areas. This not only improves the efficiency and accuracy of surface defect detection, but also intuitively displays the location, shape and probability information of the defects in a visual way, providing strong support for quality assessment and decision-making, helping the manufacturing industry to optimize cost and time efficiency while maintaining product quality, and improving the overall production quality control level. BRIEF DESCRIPTION OF THE DRAWINGS

[0064] For better understanding and implementation, the technical solution of the present application is described in detail below with reference to the accompanying drawings.

[0065] Figure 1 A schematic diagram of a process flow of a component surface quality detection method based on machine vision provided in Example 1 of the present application;

[0066] Figure 2 A schematic diagram of a process of removing noise in an image using a Gaussian filter method in a method for detecting surface quality of a component based on machine vision provided in Example 1 of the present application;

[0067] Figure 3 A schematic flow chart of enhancing image contrast using a histogram equalization method of a component surface quality detection method based on machine vision provided in Example 1 of the present application;

[0068] Figure 4A schematic diagram of a predefined model flow chart for establishing a component surface quality detection method based on machine vision provided in Example 1 of the present application;

[0069] Figure 5 A schematic diagram of the structure of a component surface quality inspection system based on machine vision provided in Example 1 of the present application. DETAILED DESCRIPTION

[0070] In order to further explain the technical means and effects taken by the present invention to achieve the predetermined invention purpose, exemplary embodiments will be described in detail here, and examples thereof are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are only examples of methods and systems consistent with some aspects of the present application as detailed in the attached claims.

[0071] The terms used in this application are for the purpose of describing specific embodiments only and are not intended to limit this application. The singular forms of "a", "said" and "the" used in this application and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0072] The specific implementation methods, features and effects of the present invention are described in detail below in conjunction with the accompanying drawings and preferred embodiments.

[0073] Example 1

[0074] See also Figure 1-Figure 5 , this embodiment provides a method for detecting the surface quality of parts based on machine vision. Through advanced image preprocessing techniques, including denoising, contrast adjustment, color balance and edge sharpening, the highest quality of image data is ensured, and clear and accurate images are provided for subsequent analysis. In particular, the edge detection algorithm is used to extract contour features and the gray-level co-occurrence matrix is ​​used to extract surface texture features, which comprehensively captures the surface characteristics of parts and improves the accuracy of feature vector construction. In addition, the customized deep learning model design takes into account the defect types and patterns unique to parts, so that the model shows higher recognition accuracy and efficiency in this application scenario. Finally, the system's automatic defect automatic marking uses probability thresholds to automatically mark defective areas, and combines the probability value output by the softmax activation function to evaluate the severity of defects, providing quantitative evaluation results and realizing an end-to-end automated inspection process. It has significant effects in improving production efficiency, reducing costs, and improving product quality.

[0075] The present invention provides a component surface quality detection method based on machine vision, comprising the following steps:

[0076] S1. Obtain an image of the component to be inspected, including the contour shape and surface processing texture of the component;

[0077] Furthermore, the image of the component to be inspected is obtained by installing an image acquisition device at a preset position, adjusting the viewing angle and position of the device according to the position and size of the component to be inspected, so as to capture the image of the component from multiple angles, including the contour shape and surface processing texture of the component.

[0078] S2. Preprocess the images of the parts to be inspected, including denoising, contrast adjustment, color balance, and edge sharpening. At the same time, extract key features, use edge detection algorithm to extract contour features, use gray-level co-occurrence matrix to extract surface texture features, and convert them into feature vectors to be input into the clustering algorithm;

[0079] Furthermore, the image of the component to be inspected is preprocessed, and the noise in the image is removed using the Gaussian filter method, which specifically includes:

[0080] S201, selecting a Gaussian kernel of an odd size in the image of the component and determining a center point;

[0081] S202, calculating the weight of each position in the kernel by using a Gaussian function and performing normalization processing;

[0082] S203, sliding the Gaussian kernel to each point of the image, and calculating a new pixel value;

[0083] The formula for calculating the new pixel value is expressed as:

[0084]

[0085] in, is the original image at coordinates ( , ), is the normalized Gaussian kernel in ( , ) weight, ( , ) relative to the center point The weight of is the filtered image at the center point The pixel value of is the sum of all x and y coordinates in the region covered by the Gaussian kernel.

[0086] The histogram equalization method is used to enhance the contrast of the image and make the surface features of the parts more obvious. The specific contents include:

[0087] S211, calculating the histogram of the original image. The histogram is a statistic of the number of pixels at each gray level in the image, and displays the distribution of the intensity value of each pixel in the image. Specifically, it is expressed as:

[0088]

[0089] in, is the Kronecker function (1 if the pixel value is equal to i, 0 otherwise), and H are the width and height of the image respectively;

[0090] S212, determine the cumulative distribution function, calculate the cumulative distribution function of the histogram, and represent the pixel ratio of each gray level and the gray levels below it in the image. The specific cumulative distribution function is expressed as:

[0091]

[0092] in, is the cumulative probability of occurrence of gray level i and all gray levels below it, is the probability that gray level i appears in the image;

[0093] S213, normalizing CDF, normalizing the cumulative distribution function so that its maximum value is 1;

[0094] S214, mapping grayscale, using normalized CDF to map each pixel intensity value of the original image to a new grayscale, ensuring a more uniform distribution of pixel intensity;

[0095] S215, mapping function, replacing each pixel value in the original image with its corresponding new grayscale value to obtain an image with enhanced contrast.

[0096] Ensure that the colors in the image truly reflect the actual colors of the parts by correcting color deviations;

[0097] Use the gradient sharpening method to highlight the edge information of the image and make the contour clearer.

[0098] Specifically, the preprocessing of the image of the inspected parts includes using the Gaussian filter method to remove noise in the image, including selecting a Gaussian kernel of odd size and determining the center point, calculating the weight of each position in the kernel through the Gaussian function and normalizing it, and then sliding the Gaussian kernel to each point of the image to calculate the new pixel value. In addition, the contrast of the image is enhanced by the histogram equalization method to make the surface features of the parts more obvious, including calculating the histogram of the original image, determining the cumulative distribution function, normalizing the cumulative distribution function, using the normalized CDF to map each pixel intensity value of the original image to a new grayscale, and finally replacing each pixel value in the original image with its corresponding new grayscale value to obtain an image with enhanced contrast. At the same time, by correcting the color deviation, ensure that the color in the image truly reflects the actual color of the parts; use the gradient sharpening method to highlight the edge information of the image and make the outline clearer. This series of preprocessing steps not only removes noise from the image and enhances the image contrast, making the surface features of parts more obvious, but also corrects color deviation and uses gradient sharpening methods to make the contours clearer, providing high-quality and accurate image data for subsequent feature extraction and defect identification. While improving image quality, it lays the foundation for accurate surface defect detection, thereby improving the efficiency and reliability of the entire system.

[0099] Furthermore, the contour feature extraction uses the Canny edge detection algorithm while performing preprocessing to identify edge information in the image, performs non-maximum suppression on the Canny edge detection result, retains the local maximum of the edge pixels, refines the edge lines, and then performs an edge connection operation to connect the broken edge fragments into a complete contour; according to the edge detection result, the contour feature of the component is extracted, that is, the coordinate information of the edge pixels is obtained to describe the shape contour of the component;

[0100] Specifically, the Canny algorithm uses a pair of convolution kernels to calculate the gradient magnitude and direction of the image in the horizontal and vertical directions. The gradient magnitude is expressed as: ;direction ;

[0101] in, represents the horizontal gradient kernel ; Vertical gradient kernel

[0102] ;

[0103] Then, a double threshold strategy is used to connect strong edges. The weak edges in the connection path are considered valid edges, and a high threshold is set. and low threshold , forming a strong edge and weak edge ;

[0104] when > When = ;

[0105] when When = , starting from the strong edge, trace the connected weak edges to form a complete edge chain.

[0106] Furthermore, the gray level co-occurrence matrix is ​​used to extract surface texture features and describe the texture information of the surface of the component, and the specific contents include:

[0107] Construct a gray-level co-occurrence matrix, using gradient magnitude and direction information to determine the spatial relationship between pixels;

[0108] In a specific direction and distance d, construct the co-occurrence matrix P, where the element P (i, j) represents the The probability of grayscale values ​​i and j appearing at the same time under the distance d, where d represents the distance between the two pixels;

[0109] The texture complexity of the image is described by calculating the entropy, energy, and contrast of the gray-level co-occurrence matrix;

[0110] Among them, entropy measures the randomness of the grayscale distribution in the image. The higher the entropy value, the more random and complex the texture of the image is. The calculation formula is:

[0111]

[0112] Energy reflects the uniformity of the grayscale distribution of the image. The higher the energy value, the more uniform the texture of the image. The calculation formula is:

[0113]

[0114] Contrast quantifies the degree of local grayscale change in an image. The higher the contrast value, the more significant the grayscale change in the image and the clearer the texture. The calculation formula is:

[0115]

[0116] Through gray-level co-occurrence matrix analysis, surface texture features such as roughness, granularity and other information are extracted.

[0117] The Canny edge detection algorithm combined with the feature extraction of the gray-level co-occurrence matrix can flexibly adapt to the detection needs of different parts and application scenarios. It realizes in-depth analysis of the parts image and significantly improves the accuracy and reliability of the defect detection system. The non-maximum suppression and dual threshold strategy of the Canny algorithm ensure the clarity of the edge and the integrity of the contour, and can accurately extract the contour of the parts even in complex backgrounds. At the same time, the texture features provided by the gray-level co-occurrence matrix, such as entropy, energy, contrast, etc., comprehensively describe the texture complexity and uniformity of the surface of the parts, and provide key information for identifying surface defects such as scratches and wear. Automated edge detection and texture analysis reduce manual intervention, improve detection speed and production efficiency, reduce human errors, and improve the overall quality control level, providing strong technical support for quality control in the manufacturing industry.

[0118] Furthermore, the extracted features are organized into vectors and input into a clustering algorithm, wherein the clustering algorithm is used here to conduct preliminary exploration of the data and understand the relationship and grouping of different feature vectors.

[0119] Among them, extracting features and organizing them into vectors includes fusing all calculated eigenvalues ​​into a single eigenvector, with each eigenvalue being a dimension of the vector, and then constructing a eigenvector for each data point. These vectors constitute the input of the clustering algorithm. Then, using the clustering algorithm, the data points are divided into different groups according to the eigenvectors, which can more intuitively understand the relationship between the features of the data.

[0120] S3, comparing the extracted features with the predefined model to identify whether there are surface defects, training and identifying different types of defect patterns through deep learning algorithms, including distinguishing different types of defects;

[0121] Furthermore, the predefined model is various trained neural network models used for surface defect detection in deep learning, which are used to identify and classify different surface defects. The establishment process includes:

[0122] S31. Collect images of parts to be inspected, including normal samples and samples containing various defects;

[0123] S32, annotating the collected images to clarify the type, location and severity of the defects. For pixel-level defect detection, pixel-level annotation is performed, that is, the specific location of each defective pixel is determined;

[0124] S33, designing the input layer according to the feature vector of the selected image or the group of clustering division, ensuring that the network can accept the appropriate data format;

[0125] S34, use convolutional layers to extract image features, capture local features and reduce the number of parameters of fully connected layers;

[0126] S35. Use activation functions such as ReLU to increase nonlinearity. For multi-class classification tasks, the output layer usually uses the softmax activation function to output multi-class probabilities.

[0127] Specifically, the extracted features are compared with the predefined model, features are extracted from the image of the component to be inspected, including contour, surface texture and other information, the feature vectors or the groups divided by clusters are divided, ensuring that the format matches the input layer of the deep learning model, the feature vectors or the groups divided by clusters are input into the trained deep learning model for prediction, and the output features of the model are compared to see if there are surface defects.

[0128] Furthermore, when the output result has surface defects, the original score is converted into probability through the softmax activation function to distinguish different types of defects and obtain the probability of different types of defects. The sum of the probabilities output by the softmax function is 1. The specific calculation formula is expressed as:

[0129]

[0130] in, is the probability that the model predicts that the image belongs to the i-th class, is the raw score of the i-th unit in the model output layer, and n represents all categories. The output of the softmax function is the probability that the model predicts that the input image belongs to each category.

[0131] S4. According to the comparison results between the features and the model, the defective area will be automatically marked.

[0132] Furthermore, the defect area is automatically marked by comparing the input image with the model, and for an area in the image, the defect probability is output by the softmax function, and a threshold T is set. When the obtained probability is greater than the threshold T, the area is determined to be a defect area and marked.

[0133] Traverse the entire image area and perform the above probability calculation and marking operations on each area;

[0134] The marked defect areas are visualized on the image for easy viewing and analysis, including information such as the location, shape, and probability of the marked defect areas.

[0135] The contents of steps S3-S4 are specifically expressed as follows: through the predefined deep learning model, efficient recognition and accurate classification of component surface defects are achieved. First, by collecting and annotating component images containing various defects, a neural network model that can recognize and classify different surface defects is trained. The ReLU and softmax activation functions are combined to increase nonlinearity and perform multi-category probability output, thereby ensuring efficient learning and recognition of defect features.

[0136] During the detection phase, the feature vectors extracted from the image to be detected are input into the trained model. The model effectively identifies areas with surface defects by comparing these features with the learned defect features. Finally, the softmax activation function is used to convert the original scores into probabilities, which enables the distinction between different types of defects and automatically marks the defective areas. This process not only improves the efficiency and accuracy of surface defect detection, but also intuitively displays the location, shape and probability information of the defects in a visual way, greatly facilitating quality control and subsequent analysis; this method greatly improves the speed and reliability of parts inspection in the manufacturing industry, while reducing dependence on manual inspection, ensuring product quality while optimizing cost and time efficiency.

[0137] Example 2

[0138] This embodiment is applied to a component surface quality detection method based on machine vision in Embodiment 1, specifically a component surface quality detection system based on machine vision, including a data acquisition module, a data preprocessing module, a feature analysis module, and an automatic marking module.

[0139] The data acquisition module installs a high-precision image acquisition device at a preset position, and adjusts the viewing angle and position of the device according to the position and size of the parts to capture the contour shape and surface processing texture of the parts at multiple angles;

[0140] The data preprocessing module performs necessary preprocessing operations on the image of the component to be inspected, including denoising, contrast adjustment, color balance and edge sharpening, extracts contour features using an edge detection algorithm, and extracts surface texture features using a gray level co-occurrence matrix;

[0141] Specifically, the Gaussian filter method is used to remove noise in the image, including:

[0142] A Gaussian kernel of odd size is selected in the image of the component to determine the center point;

[0143] The weight of each position in the kernel is calculated by Gaussian function and normalized;

[0144] Slide the Gaussian kernel to each point of the image and calculate the new pixel value;

[0145] The formula for calculating the new pixel value is expressed as:

[0146]

[0147] in, is the original image at coordinates ( , ), is the normalized Gaussian kernel in ( , ) weight, ( , ) relative to the center point The weight of is the filtered image at the center point The pixel value of is the sum of all x and y coordinates in the region covered by the Gaussian kernel.

[0148] The histogram equalization method is used to enhance the contrast of the image and make the surface features of the parts more obvious. The specific contents include:

[0149] Calculate the histogram of the original image. The histogram is a statistic of the number of pixels at each gray level in the image, showing the distribution of the intensity value of each pixel in the image. It is specifically expressed as:

[0150]

[0151] in, is the Kronecker function (1 if the pixel value is equal to i, 0 otherwise), and H are the width and height of the image respectively;

[0152] Determine the cumulative distribution function and calculate the cumulative distribution function of the histogram to represent the pixel ratio of each gray level and the gray levels below it in the image. The specific cumulative distribution function is expressed as:

[0153]

[0154] in, is the cumulative probability of occurrence of gray level i and all gray levels below it, is the probability that gray level i appears in the image;

[0155] Normalized CDF, normalize the cumulative distribution function so that its maximum value is 1;

[0156] Mapping grayscale, using normalized CDF to map each pixel intensity value of the original image to a new grayscale, ensuring a more uniform distribution of pixel intensity;

[0157] The mapping function replaces each pixel value in the original image with its corresponding new grayscale value to obtain an image with enhanced contrast.

[0158] Ensure that the colors in the image truly reflect the actual colors of the parts by correcting color deviations;

[0159] Use the gradient sharpening method to highlight the edge information of the image and make the contour clearer.

[0160] Specifically, the Canny edge detection algorithm is used during preprocessing to identify edge information in the image, non-maximum suppression is performed on the Canny edge detection result, the local maximum of edge pixels is retained, the edge lines are refined, and then the edge connection operation is performed to connect the broken edge fragments into a complete contour; according to the edge detection result, the contour features of the parts are extracted, that is, the coordinate information of the edge pixels is obtained to describe the shape contour of the parts;

[0161] The gray-level co-occurrence matrix is ​​used to extract surface texture features and describe the texture information of the surface of parts. The specific contents include:

[0162] Construct a gray-level co-occurrence matrix, using gradient magnitude and direction information to determine the spatial relationship between pixels;

[0163] In a specific direction and distance d, construct the co-occurrence matrix P, where the element P (i, j) represents the The probability of grayscale values ​​i and j appearing at the same time under the distance d, where d represents the distance between the two pixels;

[0164] The texture complexity of the image is described by calculating the entropy, energy, and contrast of the gray-level co-occurrence matrix;

[0165] Among them, entropy measures the randomness of grayscale distribution in an image. The higher the entropy value, the more random and complex the texture of the image.

[0166] Energy reflects the uniformity of the grayscale distribution of the image. The higher the energy value, the more uniform the texture of the image.

[0167] Contrast quantifies the degree of local grayscale change in an image. The higher the contrast value, the more significant the grayscale change in the image and the clearer the texture.

[0168] Through gray-level co-occurrence matrix analysis, surface texture features such as roughness, granularity and other information are extracted.

[0169] The feature analysis module organizes the extracted contour features and surface texture features into vectors, and compares them with the established predefined model to identify whether there are surface defects.

[0170] Specifically, all calculated eigenvalues ​​are merged into a single eigenvector, and each eigenvalue is a dimension of the vector. Then a eigenvector is constructed for each data point. These vectors constitute the input of the clustering algorithm. The clustering algorithm is then used to divide the data points into different groups according to the eigenvectors, which can more intuitively understand the relationship between the characteristics of the data.

[0171] Compare the extracted features with the predefined model, extract features from the image of the component to be inspected, including contours, surface texture and other information, divide the feature vectors or clusters into groups, ensure that the format matches the input layer of the deep learning model, input the feature vectors or clusters into the trained deep learning model for prediction, and compare the output features of the model for surface defects.

[0172] The automatic marking module, when the model identifies surface defects, calculates the probability of each category of defects through the softmax activation function, and then sets a threshold T. When the probability is greater than the threshold T, the defect area is automatically marked according to the output of the model.

[0173] Specifically, when there are surface defects in the output results, the original scores are converted into probabilities through the softmax activation function, different types of defects are distinguished, and the probabilities of different types of defects are obtained.

[0174] Then, the defect probability is output by the softmax function and the threshold T is set. When the probability is greater than the threshold T, the area is determined to be a defect area and marked. Then, the entire image area is traversed and the above probability calculation and marking operations are performed on each area; the marked defect area is visualized on the image.

[0175] This embodiment achieves efficient recognition and accurate classification of surface defects through preprocessing, feature extraction and comparison of deep learning models, and uses Gaussian filter denoising, histogram equalization to enhance contrast, Canny edge detection algorithm to extract contour features, and grayscale co-occurrence matrix to describe surface texture information, ensuring the highest quality of image data. The predefined deep learning model can distinguish different types of defects and automatically mark defective areas, thereby improving production efficiency, reducing costs, and improving product quality. Furthermore, the clustering algorithm is used to preliminarily explore data relationships and provide intuitive understanding for subsequent analysis. This method greatly improves the speed and reliability of component inspection in the manufacturing industry, while reducing reliance on manual inspection, ensuring product quality while optimizing cost and time efficiency.

[0176] Example 3

[0177] Another embodiment of the present application provides a method for detecting the surface quality of components based on machine vision, which is applied in the manufacturing process of network chains. In order to ensure that each product can meet high quality requirements, the factory needs to conduct strict surface quality inspection on the produced network chains. The method of the present application greatly improves the speed and accuracy of network chain surface defect detection, reduces the dependence on manual inspection, and reduces production costs and improves production efficiency through automated and intelligent inspection processes.

[0178] S1. Obtain images of the network chain to be inspected. On the production line, the completed network chain will be automatically transported to a special preset inspection position. A high-resolution camera will shoot the network chain from multiple angles to capture detailed information including contour shape and surface texture.

[0179] S2, image preprocessing and feature extraction, preprocess the collected network chain image, use Gaussian filter to remove random noise in the image, enhance contrast through histogram equalization, color balance correction to ensure color accuracy, and finally enhance edge information through gradient sharpening method, use Canny edge detection algorithm to extract the outline features of the network chain, and identify the edge information of each mesh;

[0180] At the same time, the gray-level co-occurrence matrix is ​​used to analyze the surface texture features of the network chain, such as entropy, energy, contrast, etc., to fully describe the periodicity and uniformity of the texture. These features are organized into feature vectors and input into the clustering algorithm for preliminary analysis to understand the relationship and grouping between different features;

[0181] S3. Defect Identification, the extracted feature vectors are fed into a predefined deep learning model that has been trained to identify and classify different types of surface defects on the network chain;

[0182] The model compares the extracted features with known defect patterns to identify whether surface defects exist and distinguish defect types such as fracture, deformation, wear, etc. The output is converted into probability using a softmax activation function to quantify the probability of the presence of different types of defects.

[0183] S4. Automatic defect marking: According to the probability output by the model, the defect area is automatically marked on the network chain image, and visual marks (e.g., color coding or bounding box) are set to facilitate quick identification by the operator.

[0184] The above description is only a preferred embodiment of the present invention and does not limit the present invention in any form. Although the present invention has been disclosed as a preferred embodiment as above, it is not used to limit the present invention. Any technical personnel in this field can make some changes or modify the technical contents disclosed above into equivalent embodiments without departing from the scope of the technical solution of the present invention. However, any brief modifications, equivalent changes and modifications made to the above embodiments based on the technical essence of the present invention without departing from the content of the technical solution of the present invention are still within the scope of the technical solution of the present invention.

Claims

1. A method for detecting the surface quality of parts based on machine vision, characterized in that: The steps include: Acquire images of parts to be inspected, including the contour shape and surface processing texture of the parts; Preprocess the images of the parts to be inspected, including denoising, contrast adjustment, color balance, and edge sharpening. Use edge detection algorithms to extract contour features, use gray-level co-occurrence matrices to extract surface texture features, and convert them into feature vectors for input into clustering algorithms. Compare the extracted features with the predefined model to identify whether there are surface defects, and use deep learning algorithms to train and identify different types of defect patterns and distinguish different types of defects; Automatically mark defective areas based on the comparison results between features and models; The image of the component to be inspected is obtained by installing an image acquisition device at a preset position, adjusting the viewing angle and position of the device according to the position and size of the component to be inspected, and capturing the image of the component from multiple angles; The image of the component to be inspected is preprocessed. The denoising method is to remove noise points in the image using a Gaussian filter method, which specifically includes: S201, selecting a Gaussian kernel of an odd size in the image of the component and determining a center point; S202, calculating the weight of each position in the kernel by using a Gaussian function and performing normalization processing; S203, sliding the Gaussian kernel to each point of the image, and calculating a new pixel value; The formula for calculating the new pixel value is expressed as: ; in, is the original image at coordinates The pixel value at is the normalized Gaussian kernel. Relative to the center point The weight of is the filtered image at the center point The pixel value of is the sum of all x and y coordinates in the area covered by the Gaussian kernel; The image of the component to be inspected is preprocessed. The contrast adjustment includes enhancing the contrast of the image by a histogram equalization method to make the surface features of the component obvious, specifically including: S211, calculating the histogram of the original image. The histogram is a statistic of the number of pixels at each gray level in the image, and displays the distribution of the intensity value of each pixel in the image. Specifically, it is expressed as: ; in, is the Kronecker function, and H are the width and height of the image respectively; S212, determine the cumulative distribution function, calculate the cumulative distribution function of the histogram, and represent the pixel ratio of each gray level and the gray levels below it in the image. The cumulative distribution function is expressed as: ; in, is the cumulative probability of occurrence of gray level i and all gray levels below it, is the probability that gray level j appears in the image; S213, normalizing the cumulative distribution function, normalizing the cumulative distribution function so that its maximum value is 1; S214, mapping gray levels, using a normalized cumulative distribution function to map each pixel intensity value of the original image to a new gray level; S215, mapping function, replacing each pixel value in the original image with its corresponding new grayscale value to obtain an image with enhanced contrast; The contour feature extraction uses the Canny edge detection algorithm during preprocessing to identify edge information in the image, performs non-maximum suppression on the Canny edge detection result, and then performs an edge connection operation to connect the broken edge fragments into a complete contour; based on the edge detection result, the contour feature of the component is extracted, the coordinate information of the edge pixel is obtained, and the shape contour of the component is described; The Canny edge detection algorithm uses a pair of convolution kernels to calculate the gradient magnitude and direction of the image in the horizontal and vertical directions. The gradient magnitude is expressed as: ;direction ; in, represents the horizontal gradient kernel, ; represents the vertical gradient kernel, ; Then use the double threshold strategy to connect strong edges and set a high threshold and low threshold , forming a strong edge and weak edge ; when When ; when When , starting from the strong edge, trace the connected weak edges to form a complete edge chain; The method of extracting surface texture features by using a gray level co-occurrence matrix specifically includes: Construct a gray-level co-occurrence matrix, using gradient magnitude and direction information to determine the spatial relationship between pixels; Construct a co-occurrence matrix at a specific direction and distance; The texture complexity of the image is described by calculating the entropy, energy, and contrast of the gray-level co-occurrence matrix; Surface texture features are extracted through gray-level co-occurrence matrix analysis; The extracted features are organized into vectors and input into the clustering algorithm, wherein the extracted features are organized into vectors, wherein all calculated eigenvalues ​​are merged into a single eigenvector, and each eigenvalue is a dimension of the vector, and then a eigenvector is constructed for each data point and used as the input of the clustering algorithm, and the clustering algorithm is used to divide the data points into different groups according to the eigenvectors; The predefined models are various trained neural network models used for surface defect detection in deep learning, which are used to identify and classify different surface defects. The establishment process includes: Collect images of parts to be inspected, including normal samples and samples containing various defects; Annotate the collected images to identify the type, location, and severity of defects. For pixel-level defect detection, perform pixel-level annotation to determine the specific location of each defective pixel. Designing the input layer according to the feature vector of the selected image or the group divided by clustering, and determining the same data format; Use convolutional layers to extract image features and capture local features; Use the ReLU activation function to increase nonlinearity. For multi-class classification tasks, the output layer usually uses the softmax activation function to output probabilities of multiple categories. Among them, the extracted features are compared with the predefined model, the feature vectors or clustered groups are input into the trained deep learning model for prediction, and the output features of the model are compared to see if there are surface defects; When the output result has surface defects, the original score is converted into probability through the softmax activation function to distinguish different types of defects. The specific calculation formula is expressed as: ; in, is the probability that the model predicts that the image belongs to the i-th class, is the raw score of the i-th unit in the model output layer, and n represents all categories; the output of the softmax function is the probability that the model predicts that the input image belongs to each category; The automatic marking of defective areas is performed by comparing the input image with the model, and for an area in the image, the output defect probability of the softmax function is used to set a threshold T. When the obtained probability is greater than the threshold T, the area is determined to be a defective area and marked. Traverse the entire image area, calculate the probability and mark each area; The marked defect areas are visualized on the image.

2. A component surface quality detection system based on machine vision, using the component surface quality detection method based on machine vision as claimed in claim 1, characterized in that: It includes data acquisition module, data preprocessing module, feature analysis module and automatic labeling module. The data acquisition module installs a high-precision image acquisition device at a preset position, and adjusts the viewing angle and position of the device according to the position and size of the parts to capture the contour shape and surface processing texture of the parts at multiple angles; The data preprocessing module performs necessary preprocessing operations on the image of the component to be inspected, including denoising, contrast adjustment, color balance and edge sharpening, extracts contour features using an edge detection algorithm, and extracts surface texture features using a gray level co-occurrence matrix; The feature analysis module organizes the extracted contour features and surface texture features into vectors, compares them with the established predefined model, and identifies whether there are surface defects; The automatic marking module, when the model identifies surface defects, calculates the probability of each category of defects through the softmax activation function, and then sets a threshold T. When the probability is greater than the threshold T, the defect area is automatically marked according to the output of the model.