A machine vision based defect detection system
By incorporating modules for image acquisition, feature extraction, defect assessment, and key area screening, the system addresses the issues of low detection efficiency and insufficient accuracy in existing technologies, achieving efficient and accurate defect detection that meets the testing needs of different production batches and product types.
Patent Information
- Application Number
- CN202511524833.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-24
- Publication Date
- 2026-02-17
- Estimated Expiration
- 2045-10-24
AI Technical Summary
Existing machine vision-based defect detection solutions lack specificity in feature region selection, resulting in low detection efficiency and insufficient accuracy, failing to meet the demand for high-precision and high-efficiency product quality inspection in industrial production.
The system employs an image acquisition module, a feature extraction module, a defect assessment module, a correlation calculation module, and a key area screening module. By uniformly selecting the areas to be tested and combining the defect degree of the product sample with image features, the system calculates the defect correlation degree and screens out key detection areas to construct a defect detection model.
It improves the accuracy and efficiency of defect detection, enabling more accurate identification of defects on the product surface and meeting the actual needs of product quality inspection in industrial production.
Smart Images

Figure CN120997217B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of machine vision detection, in particular to a defect detection system based on machine vision. BACKGROUND
[0002] In modern industrial production processes, product surface defect detection is an important link to ensure product quality, especially in the manufacturing fields of electronic components, automobile parts, and mechanical parts, etc. The tiny defects on the product surface can directly affect the performance, service life, and even the safety of use of the product. With the continuous improvement of production automation level, the traditional manual visual defect detection method gradually exposes many shortcomings. Manual detection not only requires the detection personnel to have rich experience and high concentration, but also is easily affected by the subjective judgment of the detection personnel, physiological fatigue, emotional fluctuations, and other factors, making it difficult to guarantee the consistency and accuracy of the detection results. At the same time, manual detection is low in efficiency and difficult to meet the detection needs of large-scale and high-speed production lines. When the production batch is large, manual detection often requires a large amount of human cost, and is prone to miss detection and false detection, thereby affecting the overall quality control of the product.
[0003] To solve the drawbacks of manual detection, machine vision technology has been gradually introduced into the industry for defect detection. Existing machine vision-based defect detection schemes mostly directly perform simple feature extraction and defect recognition on the product surface images obtained by image acquisition devices, lacking in-depth analysis of the correlation between image features and defects. Although some schemes attempt to calculate the correlation between features and defects, they lack pertinence in feature region selection, often taking all extracted feature regions in the image as detection objects, resulting in excessive data processing in the detection process, reduced detection efficiency, and being easily disturbed by non-defect region features, affecting the accuracy of defect detection. In addition, existing schemes mostly rely on single product sample defect information for defect evaluation, without considering the defect distribution law and feature correlation among samples of the same batch, making the evaluation results lack comprehensiveness, and making it difficult to accurately reflect the actual contribution of different feature regions to defect detection, thereby leading to insufficient generalization ability of the constructed defect detection model, poor adaptability when facing defect detection of different production batches or different types of products, and inability to stably and reliably complete the defect detection task, making it difficult to meet the actual needs of high-precision and high-efficiency product quality detection in industrial production. SUMMARY
[0004] The present application aims to provide a defect detection system based on machine vision to solve the problems raised in the background.
[0005] To achieve the above-mentioned purpose, the present application provides a defect detection system based on machine vision, which comprises:
[0006] The image acquisition module, the feature extraction module, the defect evaluation module, the correlation calculation module, the key area screening module, and the defect detection module;
[0007] The image acquisition module is configured to acquire surface images of each product sample of the same production batch; the feature extraction module is configured to extract a plurality of image features from the surface images of each product sample and uniformly select a plurality of to-be-tested areas on each image feature; the defect evaluation module is configured to calculate a defect evaluation capability of each product sample in each to-be-tested area according to the defect degree and the image feature of each product sample; the correlation calculation module is configured to calculate an initial defect correlation of each to-be-tested area according to the feature value distribution of the image features of all product samples in each to-be-tested area and the defect degree distribution of all product samples, and further adjust to obtain a real defect correlation; the key area screening module is configured to screen a key detection area from all to-be-tested areas according to the non-defect feature possibility and the real defect correlation of each to-be-tested area; and the defect detection module is configured to construct a defect detection model based on the feature value of the image feature of each product sample in the key detection area and the defect degree of each product sample, and perform defect detection on a product sample to be tested using the defect detection model.
[0008] Preferably, the defect evaluation module is further configured to, for each product sample, determine a reference product sample set of the product sample according to the defect degree of the product sample; for each to-be-tested area, calculate a defect evaluation index of the image feature of the product sample in the to-be-tested area according to the feature value distribution of the image features of all reference product samples of the product sample in the to-be-tested area and the defect degree distribution of all reference product samples; and multiply the defect evaluation index by a defect evaluation weight of the to-be-tested area to obtain the defect evaluation capability of the image feature of the product sample in the to-be-tested area.
[0009] Preferably, the defect evaluation module is further configured to calculate a standard deviation of the feature values of the image features of all reference product samples of each product sample in a target to-be-tested area, and perform negative correlation normalization processing on the standard deviation to obtain a defect evaluation index of the image feature of the product sample in the target to-be-tested area; calculate a standard deviation of the defect degrees of all reference product samples of each product sample as a defect fluctuation degree of the product sample; and calculate a defect evaluation weight of the target to-be-tested area according to a correlation coefficient between a sequence of defect evaluation indexes of all product samples and a sequence of defect fluctuation degrees.
[0010] Preferably, the correlation degree calculation module is further configured to obtain a probability distribution of the feature values of the image features of all product samples in the target to-be-tested region, and arrange the probability values in an order from small to large of the feature values to form a first probability sequence; obtain a probability distribution of the defect degrees of all product samples, and arrange the probability values in an order from small to large of the defect degrees to form a second probability sequence; process the first probability sequence and the second probability sequence using a dynamic time warping algorithm, and perform negative correlation mapping on the output result to obtain an initial defect correlation degree of the target to-be-tested region.
[0011] Preferably, the correlation degree calculation module is further configured to number all product samples to obtain a serial number of each product sample; sort the serial numbers in an order from large to small of the defect degrees of the product samples to form a first serial number sequence; sort the serial numbers in an order from small to large of the feature values of the image features of the product samples in the target to-be-tested region to form a second serial number sequence; calculate a proportion of the serial numbers that are the same at the same positions in the first serial number sequence and the second serial number sequence as a first similarity degree; replace the serial numbers that are not matched in the first serial number sequence and the second serial number sequence with defect evaluation abilities of the image features of the corresponding product samples in the target to-be-tested region to form a first ability sequence and a second ability sequence; calculate a cosine similarity between the first ability sequence and the second ability sequence as a second similarity degree; calculate a defect correlation degree weight of the target to-be-tested region according to the first similarity degree and the second similarity degree; and multiply the defect correlation degree weight by the initial defect correlation degree to obtain a real defect correlation degree of the target to-be-tested region.
[0012] Preferably, the key region screening module is further configured to, for each product sample, obtain a third probability sequence according to a defect degree distribution of all reference product samples of the product sample; input the third probability sequence and the second probability sequence into a dynamic time warping algorithm to obtain a defect distribution error of the product sample; and perform negative correlation mapping on an average value of the defect distribution errors of all product samples to obtain a non-defect feature possibility of the target to-be-tested region.
[0013] Preferably, the key region screening module is further configured to calculate a ratio of the real defect correlation degree to the non-defect feature possibility of each to-be-tested region, and perform normalization processing on the ratio to obtain a defect evaluation importance of each to-be-tested region; and take a to-be-tested region with a defect evaluation importance greater than a preset threshold as a key detection region.
[0014] Preferably, the defect detection module is further configured to use a partial least squares algorithm to train, using the feature values of the image features of the product samples in the key detection region as input data and using the defect degrees of the product samples as output data, to construct a defect detection model.
[0015] Preferably, the defect detection module is further configured to acquire a surface image of the product sample to be inspected, extract image feature values of the surface image in the key detection area, input the image feature values into the defect detection model, and output the degree of defect of the product sample to be inspected.
[0016] Preferably, the defect assessment module is further configured to set a defect similarity range for each product sample, the defect similarity range being centered on the defect degree of the product sample and having a preset tolerance value as the radius; and to use other product samples other than the product sample whose defect degree is within the defect similarity range as a reference product sample set for the product sample.
[0017] Compared with the prior art, the beneficial effects of the present invention are:
[0018] This machine vision-based defect detection system comprises an image acquisition module, a feature extraction module, a defect assessment module, a correlation calculation module, a key area screening module, and a defect detection module, forming a complete and logically coherent defect detection process. The image acquisition module accurately acquires surface images of each product sample from the same production batch, providing a unified and comprehensive image data source for subsequent inspection work. This avoids detection deviations caused by inconsistent image acquisition and ensures the reliability of data processed by subsequent modules.
[0019] The feature extraction module extracts multiple image features from the surface image of each product sample and uniformly selects multiple test areas on each image feature. This design not only achieves comprehensive mining of product surface image features, but also lays the foundation for subsequent accurate analysis of the correlation between different areas and defects by uniformly selecting test areas. This enables the detection process to cover more areas on the product surface that may have defects, reducing the risk of missed detection due to incomplete feature extraction or unreasonable area selection.
[0020] The defect assessment module calculates the defect assessment capability of each product sample in each test area based on the defect severity and image features of each product sample. This module is no longer limited to a single-dimensional defect judgment, but combines the defect severity of the product sample itself with the corresponding image features to quantitatively analyze the defect assessment capability of different test areas. It can clearly reflect the actual role of different test areas in defect detection, providing an important basis for the subsequent selection of key detection areas, so that subsequent detection work can be more targeted to areas that are more valuable for defect detection.
[0021] The correlation calculation module calculates the initial defect correlation degree for each test area based on the feature value distribution of all product samples in each test area and the defect degree distribution of all product samples. It then further adjusts the initial correlation degree to obtain the true defect correlation degree. This process fully considers the characteristics and defect distribution patterns of all product samples in the same batch. By adjusting the initial correlation degree, it effectively reduces the impact of single sample data deviation on the correlation degree calculation results, making the final true defect correlation degree more accurate in reflecting the actual correlation between the test area and the defect, thus providing precise data support for the selection of key areas.
[0022] The critical area screening module selects critical detection areas from all test areas based on the probability of non-defect features and the correlation with actual defects in each test area. By comprehensively considering the probability of non-defect features and the correlation with actual defects in the test areas, this module can eliminate areas with a high proportion of non-defect features and a low correlation with defects, focusing the detection efforts on critical detection areas. This significantly reduces the amount of data processing in the subsequent defect detection process, avoids interference from non-critical area features on the detection results, and improves detection efficiency while further ensuring the accuracy of the detection results.
[0023] The defect detection module constructs a defect detection model based on the feature values of image features of each product sample in the key detection area and the defect degree of each product sample. The defect detection model is then used to detect defects in the product samples to be inspected. Since the data on which the model is built comes from the key detection area and fully incorporates the defect degree information of the same batch of product samples, the constructed defect detection model can more accurately capture the correspondence between defect features and defect degree. The model has stronger adaptability and stability. When inspecting the product samples to be inspected, it can more accurately identify defects on the product surface, meet the actual needs of product quality inspection in industrial production, and promote the wider application of machine vision defect detection technology in the industrial field. Attached Figure Description
[0024] Figure 1 This is a schematic diagram illustrating the working principle of the machine vision-based defect detection system described in this invention.
[0025] Figure 2 A flowchart illustrating the workflow for calculating the defect assessment capability of the defect assessment module;
[0026] Figure 3 A flowchart illustrating the workflow for calculating defect assessment metrics and weights for the defect assessment module. Detailed Implementation
[0027] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0028] Please see Figure 1 This invention provides a machine vision-based defect detection system, which integrates a multi-functional module to automate the detection of surface defects in products. The system includes modules for image acquisition, feature extraction, defect assessment, correlation calculation, key area screening, and defect detection, all connected sequentially and working collaboratively. The image acquisition module uses a high-resolution industrial camera to acquire surface images of the same batch of product samples under standard lighting conditions, ensuring consistent quality. The feature extraction module extracts texture, color, and other features from the images and uniformly selects the test area for subsequent analysis. The defect assessment module calculates the defect assessment capability of each sample in the test area based on the known defect severity and image features of the samples. Defect severity refers to a comprehensive quantitative index of defects identified in the product surface images acquired through machine vision technology, such as scratches, dents, stains, and color differences, reflecting the local sensitivity to defects. The correlation calculation module calculates the initial defect correlation based on feature values and defect severity distribution and adjusts it to the true defect correlation. The former measures overall correlation, while the latter considers local assessment capability. The key area screening module combines the probability of non-defect features and the true defect correlation to screen key detection areas, ensuring strong defect correlation and low interference. The defect detection module uses machine learning algorithms to build a model based on the feature values of key detection areas and the degree of defects, which is used to detect product samples and output a defect degree score.
[0029] Example 1: See Figure 2 In the overall process of the defect detection system, the defect assessment module is responsible for the refined evaluation of each test area of the product sample. Its core function is to calculate a quantitative indicator for each local area that reflects its sensitivity to defects, i.e., defect assessment capability. The operation of this module begins by defining a valuable comparative sample group for the currently processed product sample. This group is defined as the reference product sample set, and the basis for determining this set is the similarity of defect severity among the samples. Using the known defect severity value of the current sample as the center point and a pre-set allowable fluctuation value as the radius, a range of defect severity is drawn. All other product samples whose defect severity falls within this range (excluding the current sample itself) are included in this reference set. This method ensures that the reference samples are comparable to the current samples in terms of defect level.
[0030] After successfully constructing a set of reference product samples, the defect assessment module focuses on each test area. For the current product sample and the current test area, the module extracts the image feature values of all reference product samples in that specific test area. These feature values constitute a data sequence. Analyzing the dispersion of this data sequence is the first step in calculating the defect assessment index, usually achieved by calculating the standard deviation of the sequence. The magnitude of the standard deviation directly reflects the fluctuation range of the reference sample's feature values in that area. A higher standard deviation means that the reference sample's feature performance varies significantly in that area. This variation may originate from the defect itself or from noise or other interference. Therefore, a reverse transformation of the standard deviation is needed so that an increase in the value indicates better assessment capability. This transformation is accomplished through a negative correlation normalization method. For example, the original standard deviation is mapped to a zero-to-one interval, such that the largest standard deviation corresponds to the smallest assessment index value, and the smallest standard deviation corresponds to the largest assessment index value. The value obtained after this transformation is the defect assessment index of the product sample in the test area, which initially characterizes the stability of the feature values and the defect indication potential of this area.
[0031] Defect assessment metrics only reflect the local situation of a single sample in a single region. To measure the relative importance of the tested area within the entire defect detection system from a global perspective, a correction factor, namely the defect assessment weight, needs to be introduced. The calculation of this weight requires more macroscopic data support, involving two data sequences for all product samples: one sequence is composed of the defect assessment metric values calculated for each product sample in the current target tested area, arranged in order; the other sequence is composed of the defect volatility values for each product sample, arranged in the same order. Defect volatility is a measure describing the consistency of defect conditions in the surrounding area of a specific product sample. It is obtained by calculating the standard deviation of the defect severity of all reference product samples; high volatility means that the defect levels of the reference samples are uneven, while low volatility means that their defect levels are similar. Calculating the statistical correlation coefficient between the two sequences can reveal whether there is a trend of coordinated change between the defect assessment indicators and the defect volatility. The absolute value of the correlation coefficient reveals the strength of this association, which can then serve as the basis for weight setting. The stronger the association, the closer the assessment indicators in that region are to the fluctuations in the defect background, and the higher their importance. They should be given a larger weight. Finally, normalization is performed to ensure that the sum of all weights is within a reasonable range.
[0032] For the current product sample in the current test area, its defect assessment capability is calculated by multiplying the previously obtained defect assessment index with the calculated defect assessment weight. This product integrates information on both local feature stability and global correlation importance. This defect assessment capability value will serve as a key attribute output for this area, providing crucial input data for subsequent correlation calculations and key area selection modules. The entire calculation process requires traversing every product sample and every test area. This is a computationally intensive but fine-grained step, ensuring the comprehensiveness and accuracy of the assessment and laying a reliable foundation for the subsequent model construction of the entire defect detection system. In the initial step of determining the reference product sample set, the preset tolerance value is an adjustable parameter that directly affects the size and homogeneity of the reference set. A larger tolerance value results in a larger number of reference samples, but the difference in defect severity between samples may also increase, potentially introducing more noise. A smaller tolerance value results in a purer reference set, but the sample size may be too small, leading to a decrease in statistical significance. Therefore, the tolerance value usually needs to be optimized and determined based on the overall distribution of defect severity in a specific production batch and prior knowledge. For example, it can be set as a certain percentage of the standard deviation of historical defect severity data to achieve a balance between sample representativeness and computational stability. Once the tolerance value is determined, the system will automatically generate a unique set of reference product samples for each product sample. This process ensures that the evaluation of each sample is carried out in its defect context, enhancing the accuracy of personalized evaluation.
[0033] When calculating defect assessment metrics, there are various algorithms for negatively correlated normalization of the standard deviation. The core objective is to map the raw standard deviation linearly or non-linearly to a fixed, consistent assessment scale. A common approach is to find the maximum and minimum standard deviations of all tested regions across all samples, then use these extreme values to scale the current standard deviation so that the output value falls between zero and one and changes inversely to the original standard deviation. Another approach is to use a Gaussian function transformation, taking the standard deviation as input and outputting a function value that monotonically decreases as the input increases. Regardless of the specific algorithm used, the guiding principle remains the same: the more consistent the feature values of a region are in the reference samples (lower standard deviation), the higher its reliability as a potential defect indicator, and therefore, the higher the defect assessment metric score should be.
[0034] The calculation of defect assessment weights relies on the analysis of correlations between sequences. The type of correlation coefficient chosen can be selected based on the data distribution characteristics. If a linear relationship is expected, the Pearson correlation coefficient is a suitable choice; if the relationship may be monotonic but non-linear, the Spearman rank correlation coefficient is more robust. The calculated correlation coefficient is a numerical value with positive and negative values, but its absolute value truly reflects the strength of the association. Therefore, the absolute value is usually used for weight calculation. Subsequently, to ensure the comparability of weights for different test regions and to avoid some weights being too large or too small, the absolute values calculated for all test regions need to be normalized. For example, the softmax function can be used to transform them into a probability distribution with a sum of one, or min-max normalization can be performed to map them to another specified interval. The values after this processing are the final defect assessment weights, which allow test regions with stronger overall correlation to receive higher weights in subsequent calculations, thereby amplifying their contribution.
[0035] Multiplying the defect assessment index by the defect assessment weight yields the defect assessment capability. This step is a simple scalar multiplication operation, but its significance lies in completing the fusion from local assessment to global weighting. The defect assessment index is a local measure derived from the perspective of a single sample's reference set, while the defect assessment weight is a global measure derived from the macroscopic perspective of all samples. Their product achieves information complementarity. The final defect assessment capability value is a comprehensive score that considers both the region's performance in the specific context of the current sample and its correlation with defect fluctuations in the entire dataset. This value is more comprehensive and robust. This calculation process is repeated for each test region, ultimately generating a defect assessment capability map for all test regions for each product sample. This map clearly indicates which regions are valuable for defect detection to what extent, providing a quantitative basis for subsequent module decisions. The execution of the entire defect assessment module, through this meticulous, hierarchical calculation strategy, significantly improves the accuracy and reliability of the system's identification of surface defect regions on products.
[0036] Example 2: See Figure 3In the defect assessment module's processing flow, calculating the defect assessment index for each product sample in a specific test area is a fundamental and meticulous step. This index aims to reflect the consistency of the image feature values in that area within its reference sample group. The module first obtains a pre-determined set of reference product samples for the current target product sample, and then extracts the image feature values of these reference samples in the target test area. These values constitute a feature value sequence. Analyzing the dispersion of this sequence is the core task, achieved by calculating its standard deviation. The standard deviation is a statistic that measures how much a data point deviates from its mean; a larger value indicates more drastic fluctuations in the feature values of the reference sample in that area. This fluctuation may originate from various factors, including real defect signals, inherent variations in the production process, or random noise introduced during image acquisition. To transform the standard deviation into a clearly directional assessment index, a special transformation process is required. This transformation is called negative correlation normalization, and its purpose is to establish an inverse mapping relationship, such that a higher standard deviation corresponds to a lower assessment index score, and a lower standard deviation corresponds to a higher score. The processing typically requires first determining a reasonable numerical range. For example, finding the maximum and minimum standard deviations of all tested areas in the current batch as boundaries, and then using linear or nonlinear mathematical functions to map the original standard deviations to a range of zero to one. The mapping function is designed to ensure that the output value monotonically decreases as the input value increases. After this transformation, the resulting defect assessment index value carries new meaning: an index value close to one means that the characteristic values of that area are very stable in the reference sample, less affected by interference, and may have good indicative significance for defects; an index value close to zero suggests that the characteristic values of that area themselves fluctuate greatly, and their reliability is low. This index value provides a quantitative basis for the preliminary assessment of the area. The defect assessment module also calculates another important parameter—defect volatility—which describes the inconsistency in the degree of defects within the reference sample set of the current product sample.
[0037] The calculation method involves obtaining the known defect severity values of all reference product samples and calculating the standard deviation of these defect severity values. A higher defect volatility value indicates a greater difference in defect levels among the reference samples surrounding the current sample. This background environment may interfere with the assessment of local areas, increasing the uncertainty of the assessment results. Defect volatility itself is an independent measure that characterizes the degree of disorder in the local defect environment of the current sample. The calculation of defect assessment weights needs to be performed from a global perspective. It relies on the data sequences of all product samples in two dimensions. The first sequence is the defect assessment index value calculated for each product sample in the target test area, arranged in order of sample number to form the defect assessment index sequence. The second sequence is the defect volatility value corresponding to each product sample, arranged in the same sample order to form the defect volatility sequence. Calculating the statistical correlation between these two sequences is crucial for determining the weights. Correlation calculations typically employ methods such as the Spearman rank correlation coefficient to explore whether there is a systematic and monotonic correlation between the level of the defect assessment index and the magnitude of defect volatility. The absolute value of the calculated correlation coefficient reflects the strength of this correlation.
[0038] The absolute value of the correlation coefficient is used as the basis for weight calculation because it represents the strength of the association without directionality. A strong association means that the evaluation index value of the tested area is closely related to the degree of fluctuation of the defect background, thus suggesting that the area may contain more important information. This absolute value needs to be normalized to compare and coordinate with the weights of other tested areas. Normalization ensures that all weight values are within a controllable and relatively balanced range, avoiding excessively large or small weights for individual areas that could unduly affect the overall result. The final defect evaluation weight is a value between zero and one, representing the relative importance of the tested area among all tested areas. In the correlation calculation module, the core task is to quantify the overall correlation strength between the image feature values of each tested area and the degree of product defects. This module adopts a method based on probability distribution sequence alignment. The module first needs to obtain the image feature values of all product samples on the target tested area, and then construct its probability distribution based on these feature values. The probability distribution can be approximated by drawing a histogram and calculating the probability density of each interval, or a smoother method such as kernel density estimation can be used to obtain a continuous probability distribution curve. After obtaining the probability distribution, all feature values are arranged in ascending order, and their corresponding probability values are extracted in the same order to form an ordered probability value sequence, namely the first probability sequence. This sequence describes the cumulative situation of the probability changes of feature values from small to large.
[0039] The module acquires defect severity data for all product samples and constructs their probability distributions. It arranges the defect severity values in ascending order and extracts their corresponding probability values sequentially, forming a second probability sequence. This sequence describes the cumulative probability of defect severity occurring from mild to severe. We obtain two sequences representing the feature value distribution and the defect severity distribution, respectively. The core of the correlation calculation is to measure the similarity between the forms of these two sequences. The Dynamic Time Warping algorithm is used to process these two probability sequences. Essentially, this algorithm finds the optimal non-linear alignment path between the two sequences. Even if the two sequences are not exactly the same in length or have different rates of change, the algorithm can effectively calculate the minimum cumulative distance between them. After inputting the first and second probability sequences into the algorithm, it outputs a distance value. This value quantifies the minimum cost required to align the two sequences. The larger the distance value, the greater the difference in the forms of the two probability distributions, i.e., the less similar the feature value distribution and the defect severity distribution are. Since a larger distance value indicates a weaker correlation, a negative correlation mapping is needed to transform it into an indicator representing the strength of the correlation, i.e., the initial defect correlation degree. Mapping functions are typically designed to map distance values to a range of zero to one, and the output value decreases as the input distance value increases. A common approach is to use an exponential decay function or a simple linear inverse scaling. The closer the initial defect correlation score obtained after mapping is to one, the higher the similarity between the image features of the tested area and the overall distribution of product defect severity, indicating a stronger potential correlation; conversely, the closer the score is to zero, the weaker the correlation.
[0040] Example 3: After obtaining the serial numbers of all samples, the module sorts them according to the defect severity value of each product sample, arranging these serial numbers in descending order to form the first serial number sequence. This sequence reflects the ranking of product samples based on defect severity; samples with greater defect severity rank higher in the sequence. The module then sorts the image features of each product sample according to the feature values in the target test area, arranging the serial numbers in ascending order to form the second serial number sequence. This sequence reflects the ranking of product samples based on feature value magnitude; samples with smaller feature values rank higher in the sequence. The proportion of identical serial number values at the same index position in the first and second serial number sequences is calculated as the first similarity. This proportion is obtained by dividing the number of identical serial numbers at corresponding positions in the two sequences by the total length of the sequences. A higher proportion indicates stronger consistency between the defect severity ranking and the feature value ranking.
[0041] For the serial numbers in the first and second serial number sequences that fail to match at the same position (i.e., samples with inconsistent rankings), the module performs a replacement operation, replacing these serial numbers with the defect assessment capability values of the corresponding product sample's image features in the target test region. These defect assessment capability values are derived from previous calculations by the defect assessment module and characterize the reliability of the region in local assessment. After the replacement, the original serial number sequences are converted into two new numerical sequences: the first capability sequence and the second capability sequence. The element `now` in these two sequences represents the defect assessment capability value, not the serial number, and carries the local assessment information of the unmatched samples. To quantify the similarity between these two capability sequences, the module calculates their cosine similarity as a second degree of similarity. Cosine similarity measures the proximity of two vectors in a direction, with a value range between -1 and +1. However, in this context, since the capability values are non-negative, the similarity is usually positive.
[0042] The cosine similarity is calculated using the following formula:
[0043]
[0044] Where: Ф represents the cosine similarity value, i.e., the second degree of similarity, U k It is the k-th element in the first capability sequence, representing the defect assessment capability value of the k-th unmatched sample at the corresponding position in the original first sequence number, V. k is the k-th element in the second capability sequence, representing the defect assessment capability value of the k-th unmatched sample at its corresponding position in the original second sequence number. m is the length of the two capability sequences, i.e., the number of unmatched samples. This formula calculates the ratio of the sum of the products of corresponding elements in the two sequences to the product of their norms. The closer the result is to one, the more consistent the directions of the two capability sequences are. Based on the first and second similarity levels, the module calculates the defect correlation weight of the target region to be tested. The weight calculation usually adopts a weighted average or similar fusion strategy. For example, the first similarity level is given a higher weight because it is directly based on the hard indicator of sequence number matching, while the second similarity level provides a supplement as a soft indicator. The specific weight value can be determined by linear combination or parameters adjusted based on experience. Then, the calculated defect correlation weight is multiplied by the previously obtained initial defect correlation. The product is the true defect correlation of the target region to be tested. The true defect correlation combines ranking consistency and capability distribution similarity, providing a more accurate correlation measure.
[0045] In the key area screening module, for calculating the probability of non-defect features, the module first processes the defect severity data of its reference product sample set for each product sample. The reference sample set is determined in the same way as in the defect assessment module, based on the similarity range of defect severity. For each product sample, the module obtains the defect severity values of all its reference product samples and constructs the probability distribution of these defect severity values. The probability distribution can be obtained through histogram statistics or kernel density estimation. Then, the probability values are arranged in ascending order of defect severity to form a third probability sequence. This sequence describes the cumulative distribution pattern of defect severity within the reference sample group. The module calls the probability distribution sequence of defect severity of all product samples, i.e., the second probability sequence, which has been pre-constructed in the correlation calculation module. The third probability sequence and the second probability sequence are used as inputs and fed into the dynamic time warping algorithm for processing. The dynamic time warping algorithm calculates the minimum alignment path distance between the two sequences and outputs a distance value, which is the defect distribution error of the product sample. The defect distribution error quantifies the degree of difference between the defect distribution of the reference sample and the overall sample defect distribution. The larger the error value, the further the defect pattern around the product sample deviates from the global pattern. The arithmetic mean of the defect distribution error calculated for all product samples is obtained. This mean reflects the overall impact of the inconsistency in the distribution of the target area under test across all samples.
[0046] The average value is negatively correlated to convert it into a non-defect feature probability. The mapping function is typically designed to inversely scale the error value to between zero and one, for example, by subtracting the normalized error value from one. This ensures that a larger average error corresponds to a smaller probability value, and a smaller average error corresponds to a larger probability value. A higher non-defect feature probability value indicates a lower likelihood that the tested area is affected by non-defect factors (such as environmental changes or measurement noise), making it more suitable for selection as a key detection area. The sequence sorting and capability replacement strategy of the correlation calculation module effectively captures the local characteristics of inconsistently ranked samples, while the distribution error analysis of the key area screening module evaluates the region's anti-interference capability from a probabilistic perspective. These steps collectively enhance the system's detection accuracy. During implementation, attention must be paid to the stability of the sequence sorting and the parameter settings of the dynamic time warping algorithm to ensure the robustness of the calculation results. Furthermore, the defect assessment capability value needs to be pre-calculated and stored for real-time retrieval. Through this hierarchical processing, the system can more precisely identify image regions that are truly related to defects and less affected by interference, optimizing the performance of subsequent detection models.
[0047] Example 4: The true defect correlation degree is provided by the correlation calculation module, which quantifies the statistical correlation strength between the image features of the region and the degree of product defects. The higher the value, the closer the correlation. The non-defect feature probability characterizes the degree to which the region is interfered with by non-defect factors (such as uneven lighting and background noise). The higher the value, the more stable and pure the features of the region. The screening logic is based on a comprehensive consideration: the ideal key region should have both high defect correlation and low interference sensitivity. The module calculates a comprehensive index called defect assessment importance for each region to be tested. This index is obtained by calculating the ratio of true defect correlation degree to non-defect feature probability. This ratio initially reflects the balance between "effectiveness" and "reliability" of the region. A high ratio means that the region has a strong defect indication ability while maintaining relatively high anti-interference ability. However, the original ratio may vary greatly between different regions and is not directly comparable. Therefore, normalization processing is required to scale it to a uniform range with an easily set threshold, such as between zero and one. The normalization process employs a min-max scaling method. This method first iterates through all test areas to find the maximum and minimum values of the original ratios. Then, it uses these two extreme values to linearly map the original ratio of each area to a closed interval between zero and one. The value obtained after mapping is the normalized defect assessment importance of that area. The closer the value is to one, the higher the relative comprehensive value of that area among all test areas, and the more likely it is to be selected as a key detection area (see Table 1).
[0048] Table 1: Calculation of the Importance of Defect Assessment in the Test Area
[0049] Region number to be tested True defect correlation Non-defect feature possibility Original ratio (correlation / possibility) Defect evaluation importance (after normalization) R01 0.85 0.92 0.924 0.587 R02 0.78 0.88 0.886 0.555 R03 0.45 0.76 0.592 0.238 R04 0.92 0.65 1.415 0.845 R05 0.61 0.90 0.678 0.345 R06 0.33 0.82 0.402 0.000 R07 0.95 0.70 1.357 0.798 R08 0.50 0.60 0.833 0.430 R09 0.88 0.55 1.600 1.000 R10 0.40 0.50 0.800 0.398
[0050] The calculation process is as follows: For region R09, its original ratio is 0.88 / 0.55 = 1.600. Among all regions, the maximum original ratio is 1.600 for R09, and the minimum is 0.402 for R06. The normalization process is: the importance of defect assessment for each region = (original ratio of the region - 0.402) / (1.600 - 0.402). For R06, importance = (0.402 - 0.402) / 1.198 = 0.000. For R09, importance = (1.600 - 0.402) / 1.198 ≈ 1.000. For R04, importance = (1.415 - 0.402) / 1.198 ≈ 0.845. After obtaining the normalized defect assessment importance of all regions, the module completes the final screening by setting a preset threshold. This threshold is an empirical value between zero and one, and its specific value needs to be adjusted according to the actual application scenario, the requirements for detection accuracy and recall, and historical experience. The screening rule is straightforward: any region whose defect assessment importance score is higher than the preset threshold is identified as a key detection region. Assuming the threshold is set to 0.70 in this example, observing the last column of the table, regions R04 (importance 0.845), R07 (importance 0.798), and R09 (importance 1.000) all score above 0.70. Therefore, these three regions are officially identified by the system as key detection regions for this batch of products. The coordinate information and corresponding image feature types of these regions, as well as other metadata, will be saved and transmitted to the defect detection module as the sole basis for subsequent model construction and online detection.
[0051] In the implementation phase of the defect detection module, its task is to build a predictive model using the selected key detection areas. The module collects image feature values extracted from all key detection areas for each product sample in the training batch. These feature values constitute the input variable matrix of the model, with each row representing a sample and each column representing a feature of a key area. The known true defect severity value for each sample constitutes the output variable vector. Partial least squares (PLS) algorithm is used to establish a regression model between the input and output variables. This algorithm can effectively handle the multicollinearity problem between features and capture the main direction of variation in the data by extracting latent variables. After the model training is completed, it enters the application phase. When a new product sample to be inspected enters the system, the image acquisition module first acquires its surface image. The feature extraction module then quickly locates and calculates the corresponding feature values from the image based on the stored key detection area coordinates, forming a feature vector. This feature vector, after undergoing the same standardization process as the training data, is input into the trained PLS regression model. The model performs calculations and outputs a continuous predicted value, which is the defect severity score of the sample to be inspected. The entire process, from the selection of key areas to the construction and application of models, forms a closed-loop automated detection chain. By focusing on the most informative image regions, it significantly improves the efficiency and targeting of detection.
[0052] Example 5: Once a production batch completes system training and generates a defect detection model, the system enters the practical application stage, judging defects in products produced online or awaiting inspection. The defect detection module first needs to acquire a surface image of the product sample to be inspected. This task is performed by the image acquisition module. The acquisition process must strictly reproduce the environmental conditions of the training stage, including parameters such as light intensity, camera angle, product placement, and image resolution, to minimize variations introduced by differences in acquisition conditions. The acquired surface image is a digital image. Subsequently, the feature extraction module is activated. This module loads the spatial coordinate information of the key detection areas previously determined by the key area screening module. These coordinates define the local range on the image where feature calculations need to be performed.
[0053] For each key detection region, the feature extraction module calculates the feature value of that region based on predefined image feature types (such as the contrast of the gray-level co-occurrence matrix, the variance of local binary patterns, etc.). The feature values of all key detection regions are sequentially combined into a feature vector, the dimension of which is equal to the number of key detection regions. This feature vector represents the comprehensive performance of the sample to be detected in the most discriminative local image, forming the standardized data for model input. Before this, the feature vector usually undergoes a preprocessing step, namely, standardization using the mean and standard deviation saved during the training phase to ensure consistency with the data distribution used during model training. The preprocessed feature vector is input into the trained defect detection model, which is essentially a mathematical function containing a series of weight coefficients learned through partial least squares regression. The model performs linear or nonlinear transformations on the input feature vector, ultimately outputting a continuous numerical value or a classification label. This output value is the predicted defect level of the product sample to be detected. The predicted defect level can be interpreted as a score; a higher score indicates a greater likelihood of a defect or a more severe defect. Quality control personnel can preset one or more thresholds to classify the predicted score into different levels such as "qualified," "questionable," and "unqualified," thereby achieving automated quality sorting. The entire inspection process is extremely fast, meeting the high real-time requirements of industrial production lines.
[0054] In the initial steps of the defect assessment module, determining the reference product sample set for each product sample forms the basis for subsequent calculations. The definition of this set relies on a clearly defined quantitative rule. The module sets a defect similarity range for the currently processed product sample. This range is a numerical interval centered on the known defect severity value of the sample, with the radius determined by a preset tolerance value. The tolerance value is a key system parameter, and its setting requires a trade-off between the homogeneity and size of the reference sample set. For example, it can be set based on the dispersion of the distribution of defect severity data from historical batches, such as taking 0.2 times the standard deviation of the defect severity of all samples in the batch as a reasonable tolerance value. Thus, for a sample with defect severity D, its defect similarity range is [D-δ, D+δ], where δ represents the tolerance value. The system then iterates through all other product samples in the training batch except for the current sample itself, checking whether the defect severity value of each sample falls within the aforementioned interval [D-δ, D+δ]. All samples that meet the condition are included in the reference product sample set for the current sample. This set forms a "neighborhood" group whose defect levels are highly similar to the current sample, providing an appropriate, localized contrastive background for evaluating the current sample's feature performance in a specific image region. In this way, each product sample has a tailor-made reference set, enabling subsequent calculations of defect assessment metrics and defect volatility to more accurately reflect local feature behavior at a specific defect level, avoiding potential biases from global statistics.
[0055] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A defect detection system based on machine vision, characterized in that, The system includes an image acquisition module, a feature extraction module, a defect assessment module, a correlation calculation module, a key region screening module, and a defect detection module. The image acquisition module is used to acquire surface images of each product sample in the same production batch; the feature extraction module is used to extract multiple image features from the surface image of each product sample, and uniformly select multiple test areas on each image feature; The defect assessment module is used to calculate the defect assessment capability of each product sample in each test area based on the defect severity and image features of each product sample; the correlation calculation module is used to calculate the initial defect correlation of each test area based on the feature value distribution of the image features of all product samples in each test area and the defect severity distribution of all product samples, and further adjust it to obtain the true defect correlation; the key area screening module is used to screen out key detection areas from all test areas based on the probability of non-defect features and the true defect correlation of each test area. The defect detection module is used to construct a defect detection model based on the feature values of the image features of each product sample in the key detection area and the degree of defect of each product sample, and to use the defect detection model to detect defects in the product samples to be detected. The defect assessment module is also used to determine a set of reference product samples for each product sample based on the degree of defect of the product sample; for each area to be tested, it calculates a defect assessment index of the image features of the product sample in the area to be tested based on the feature value distribution of the image features of all reference product samples in the area to be tested and the defect degree distribution of all reference product samples in the area to be tested; and multiplies the defect assessment index by the defect assessment weight of the area to be tested to obtain the defect assessment capability of the image features of the product sample in the area to be tested. The defect assessment module is also used to calculate the standard deviation of the feature values of the image features of all reference product samples of each product sample in the target test area, and to perform negative correlation normalization processing on the standard deviation to obtain the defect assessment index of the image features of the product sample in the target test area. Calculate the standard deviation of the defect severity of all reference product samples for each product sample as the defect volatility of that product sample; calculate the defect assessment weight of the target test area based on the correlation coefficient between the defect assessment index sequence and the defect volatility sequence of all product samples. The correlation calculation module is also used to obtain the probability distribution of the feature values of the image features of all product samples in the target test area, and arrange the probability values in ascending order of feature values to form a first probability sequence; obtain the probability distribution of the defect degree of all product samples, and arrange the probability values in ascending order of defect degree to form a second probability sequence; use the dynamic time warping algorithm to process the first probability sequence and the second probability sequence, and perform negative correlation mapping on the output results to obtain the initial defect correlation degree of the target test area; The key area screening module is also used to calculate the ratio of the true defect correlation degree to the probability of non-defect features for each area to be tested, and to normalize the ratio to obtain the defect assessment importance of each area to be tested. Areas to be tested that have a defect assessment importance greater than a preset threshold are designated as key detection areas.
2. The defect detection system based on machine vision according to claim 1, characterized in that, The correlation calculation module is also used to number all product samples to obtain the serial number of each product sample; sort the serial numbers in descending order of the defect severity of the product samples to form a first serial number sequence; sort the serial numbers in ascending order of the feature values of the image features of the product samples in the target test area to form a second serial number sequence; calculate the proportion of the first serial number sequence and the second serial number sequence with the same serial number at the same position, as the first similarity degree; replace the unmatched serial numbers in the first serial number sequence and the second serial number sequence with the defect assessment capability of the corresponding product sample's image features in the target test area to form a first capability sequence and a second capability sequence; calculate the cosine similarity between the first capability sequence and the second capability sequence as the second similarity degree; and calculate the defect correlation weight of the target test area based on the first similarity degree and the second similarity degree. Multiply the defect correlation weight by the initial defect correlation to obtain the true defect correlation of the target area to be tested.
3. The defect detection system based on machine vision according to claim 2, characterized in that, The key area screening module is also used to obtain a third probability sequence for each product sample based on the defect severity distribution of all reference product samples; input the third probability sequence and the second probability sequence into a dynamic time warping algorithm to obtain the defect distribution error of the product sample; and perform a negative correlation mapping on the average defect distribution error of all product samples to obtain the non-defect feature probability of the target area to be tested.
4. The defect detection system based on machine vision according to claim 1, characterized in that, The defect detection module is also used to take the feature values of the image features of each product sample in the key detection area as input data, take the defect degree of each product sample as output data, and use the partial least squares algorithm for training to build a defect detection model.
5. A defect detection system based on machine vision according to claim 1, characterized in that, The defect detection module is also used to acquire a surface image of the product sample to be inspected, extract the image feature values of the surface image in the key detection area, input the image feature values into the defect detection model, and output the degree of defect of the product sample to be inspected.
6. The defect detection system based on machine vision according to claim 1, characterized in that, The defect assessment module is also used to set the defect similarity range for each product sample, with the defect similarity range centered on the defect degree of the product sample and a preset tolerance value as the radius; and to use other product samples other than the product sample whose defect degree is within the defect similarity range as the reference product sample set for the product sample.
Citation Information
Patent Citations
Lipstick product surface defect data augmentation method based on small sample feature migration
CN116229205A
Pipeline internal detection system based on double fisheye lenses
CN118817694A