Visual inspection method and system based on multi-dimension gray scale statistics and adaptive discrimination
Patent Information
- Application Number
- CN202610892346.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-19
- Publication Date
- 2026-10-27
AI Technical Summary
[0037]本发明实施例提供的技术方案带来的有益效果至少包括:
Smart Images

Figure CN122990140A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of visual inspection technology, and in particular to a visual inspection method and system based on multi-dimensional grayscale statistics and adaptive discrimination. Background Technology
[0002] In many fields such as industrial automation, product quality inspection, printing inspection, agricultural sorting, and biomedical image analysis, "density and presence detection" is a fundamental and crucial task. Its core objective is to determine whether a target object exists ("present" or "absent") within a specific region of an image, and further assess the object's salience or "density," such as the ink density of printed materials, the brightness of spots on an LCD screen, missing pieces on pill packaging, or the contrast of surface defects on agricultural products. Here, "density" is a broad concept, typically directly representing the brightness (grayscale value) of pixels in grayscale images. High density corresponds to darker colors (lower grayscale values) or lighter colors (higher grayscale values), depending on the specific application.
[0003] Traditional contact-based or dedicated sensor detection methods suffer from limitations such as poor adaptability, susceptibility to wear, and complex installation when dealing with complex patterns, flexible objects, or high-speed production lines. Machine vision technology, with its non-contact, high-speed, high-precision, and highly flexible characteristics, has become the preferred solution for these problems. Its basic principle is to acquire digital images of the target object using an industrial camera, then extract features using image processing algorithms, and finally make a judgment based on preset logic or models.
[0004] In the detection of the presence or absence of objects, the core challenge lies in how to robustly and stably separate the "object" from the "background" from images that may be affected by uneven lighting, background texture interference, object variations, and image noise, and quantify their differences. A direct and widely adopted approach is to utilize the gray-level difference (i.e., density difference) between the object and the background. When an object is present, the gray-level distribution within the detection area changes due to the object's presence; when the object is absent, the gray-level distribution in that area is mainly determined by the background. Therefore, scientifically describing and utilizing this change in gray-level distribution is key to achieving highly reliable detection. Summary of the Invention
[0005] To address the technical problems existing in the prior art, embodiments of the present invention provide a visual detection method and system based on multi-dimensional grayscale statistics and adaptive discrimination. The technical solution is as follows:
[0006] A visual detection method based on multi-dimensional grayscale statistics and adaptive discrimination includes the following steps:
[0007] S1. Image Grayscale Acquisition: The image of the target to be tested is acquired through the image acquisition module of the vision inspection system, and the target image is converted into a grayscale image before being output.
[0008] S2. Image region localization: Preprocess the acquired image and then determine the detection region;
[0009] S3. Gray-level feature extraction of the detection area: Multi-dimensional gray-level feature extraction is performed on the detection area to obtain a multi-dimensional feature vector of the gray-level distribution characteristics of the detection area. The multi-dimensional feature vector includes gray-level mean, gray-level variance, normalized minimum gray-level feature and normalized maximum gray-level feature.
[0010] S4. Background Modeling and Update: After the visual inspection system is started or reset, it enters the background learning stage. For the multi-dimensional feature vectors of the detection area without the test object in multiple consecutive frames, the background mean and background standard deviation of each feature dimension in the background learning samples are calculated, and a background feature statistical model and the normal fluctuation range of each feature dimension are established accordingly. In the model update stage, the background feature statistical model is dynamically updated online.
[0011] S5. Region Deviation Fusion and Concentration Output: The visual detection system performs online detection of the detection region in the currently acquired image, extracts the multi-dimensional feature vector of the detection region, calculates the standardized deviation of each feature dimension relative to the background model, and then fuses the standardized deviations of each feature dimension with their corresponding weights to obtain the comprehensive confidence score. Finally, based on the comprehensive confidence score and the preset comprehensive threshold, it is determined whether there is a target object in the current detection region, and the concentration quantification result of the target object is output according to the relationship between the comprehensive confidence score and the preset low threshold and high threshold.
[0012] Preferably, in step S1, the image acquisition module includes an industrial camera, a lens, and a light source, and the target to be measured includes at least one of printed matter, packaging, screen, pill packaging, agricultural product surface, or industrial part surface.
[0013] In step S2, the detection area after image processing is manually specified by the user based on the location of the target to be tested, or automatically generated by the system based on template matching, edge positioning, target contour recognition, or preset coordinates.
[0014] Preferably, in step S3, a four-dimensional feature vector is extracted for each region to be detected during the background learning stage or the online detection stage.
[0015] Preferably, the background feature statistical model learning stage in step S4 includes the following sub-steps:
[0016] S401. After the visual inspection system is started or reset, select a series of consecutive frames of detection areas that do not contain the object to be tested as background samples. The number of consecutive frames is a preset number of frames.
[0017] S402. Extract four-dimensional feature vectors from the detection regions in each frame of background samples. Based on the four-dimensional feature vectors of background samples from multiple consecutive frames, calculate the background mean and background standard deviation in each feature dimension to obtain a background feature statistical model.
[0018] S403. Based on the background mean, background standard deviation and confidence coefficient of each feature dimension, establish the normal fluctuation range of each feature dimension, and form the four-dimensional hypercube boundary of the background feature by the normal fluctuation range of each feature dimension.
[0019] Preferably, in step S4, the background feature statistical model update stage, when the current detection area is determined to have no target object, or the overall confidence level is lower than the preset update threshold, the background mean and background standard deviation in the background feature statistical model are updated online using an exponential moving average method.
[0020] Preferably, step S5 includes the following sub-steps:
[0021] S501. In the online detection stage, a four-dimensional feature vector is extracted from the detection region in each frame of the current image. The four-dimensional feature vector of the current image is compared with the background feature statistical model, and the standardized deviation of each feature dimension relative to the background model is calculated.
[0022] S502. Weighted fusion is performed based on the standardized deviation of each feature dimension and the corresponding weight coefficient to obtain the comprehensive confidence level. The weight coefficient is configured according to the importance of each gray-level feature in different application scenarios. When detecting dark spots, the weight corresponding to the normalized minimum gray-level feature is increased, and when detecting texture loss, the weight corresponding to the gray-level variance is increased.
[0023] S503. Compare the overall confidence level with the preset overall threshold, and output the concentration quantification result based on the relationship between the overall confidence level and the preset low threshold and high threshold.
[0024] The output results include binary judgments, ternary judgments, or continuous concentration indices.
[0025] A visual detection system based on multi-dimensional grayscale statistics and adaptive discrimination, the system being used in the visual detection method based on multi-dimensional grayscale statistics and adaptive discrimination as described in any one of claims 1-6, the system comprising:
[0026] The image acquisition and grayscale output module acquires the target image to be tested, converts the target image to grayscale, and then outputs it.
[0027] The image preprocessing and ROI determination module receives a grayscale image, preprocesses the grayscale image, and determines the detection area of the preprocessed image.
[0028] The multi-dimensional gray-level feature extraction module extracts multi-dimensional gray-level features based on the image detection area to obtain a multi-dimensional feature vector that characterizes the gray-level distribution characteristics of the detection area. The multi-dimensional feature vector includes gray-level mean, gray-level variance, normalized minimum gray-level feature, and normalized maximum gray-level feature.
[0029] The background model learning and adaptive update module obtains multi-dimensional feature vectors. During the background learning stage of the visual detection system, based on the multi-dimensional feature vectors of the detection area without the test object in multiple consecutive frames, it calculates the background mean and background standard deviation of each feature dimension in the background learning samples, and establishes a background feature statistical model and the normal fluctuation range of each feature dimension.
[0030] The integrated decision and result output module acquires the multi-dimensional feature vector of the detection area in the currently acquired image during the online detection stage, compares the multi-dimensional feature vector of the current detection area with the background feature statistical model, calculates the standardized deviation of each feature dimension relative to the background feature statistical model, and integrates each standardized deviation into a comprehensive confidence score. Based on the comprehensive confidence score, it outputs the presence or absence judgment result or concentration quantification result of the object to be tested.
[0031] Preferably, the image acquisition and grayscale output module includes an industrial camera, a lens and a light source, and the target to be measured includes at least one of printed matter, packaging, screen, pill packaging, agricultural product surface or industrial part surface;
[0032] The detection area of the image preprocessing and ROI determination module is manually specified by the user based on the location of the target to be tested, or automatically generated by the system based on template matching, edge localization, target contour recognition, or preset coordinates.
[0033] Preferably, the background model learning and adaptive update module selects multiple consecutive frames of detection area images without the test object as background samples during the background learning stage, extracts multidimensional feature vectors of the detection area of each frame, calculates the mean and standard deviation of each feature dimension, and determines the normal fluctuation range of each feature dimension based on the mean, standard deviation and confidence coefficient, so that the normal fluctuation range of multiple feature dimensions together constitutes the multidimensional background boundary.
[0034] During the model update phase, the mean and standard deviation in the background feature statistical model are updated online using an exponential moving average method.
[0035] Preferably, during the online detection phase, the integrated decision-making and result output module calculates the standardized deviation of each feature component in the multidimensional feature vector of the current detection region relative to the background feature statistical model, and performs weighted fusion of the standardized deviation according to the weight of each feature dimension to obtain the comprehensive confidence level.
[0036] Based on the relationship between the overall confidence level and the low and high thresholds, a concentration index is output to represent the concentration or significance of the object.
[0037] The beneficial effects of the technical solutions provided in the embodiments of the present invention include at least the following:
[0038] 1. This invention constructs a more comprehensive description of the grayscale distribution of the detection area by extracting multi-dimensional grayscale statistical features such as grayscale mean, grayscale variance, normalized minimum grayscale value, and normalized maximum grayscale value. Among these features, the normalized extreme value feature combines extreme values with the overall grayscale level and grayscale fluctuations, which can reduce the impact of overall illumination changes and enhance the ability to identify local anomalies.
[0039] 2. This invention employs a dynamic background statistical model, adaptive deviation calculation, and multi-feature fusion discrimination mechanism to comprehensively judge the degree of deviation of the current detection area from the normal fluctuation range of the background, and further generate a concentration quantification result. At the same time, through the slow online update of the background model, the system can adapt to long-term changes such as light source aging and material background color drift, reducing the need for repeated manual parameter adjustments. Attached Figure Description
[0040] Figure 1 This is a block diagram of the overall hardware and processing flow of the system of the present invention;
[0041] Figure 2 This is a flowchart illustrating the background model learning and adaptive update module of this invention. Detailed Implementation
[0042] The technical solution of the present invention will now be described with reference to the accompanying drawings.
[0043] In embodiments of the present invention, words such as "exemplarily," "for example," etc., are used to indicate that something is an example, illustration, or description. Any embodiment or design described as "exemplary" in the present invention should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of the word "exemplary" is intended to present the concept in a concrete manner. Furthermore, in embodiments of the present invention, the meaning expressed by "and / or" can be both, or either one.
[0044] To make the technical problems, technical solutions and advantages of the present invention clearer, a detailed description will be given below in conjunction with the accompanying drawings and specific embodiments.
[0045] Example 1: Please refer to Figure 1 This invention provides a visual detection method based on multi-dimensional grayscale statistics and adaptive discrimination, comprising the following steps:
[0046] S1: Acquire images of the target to be tested (such as printed materials, packaging, screens, pill packaging, agricultural product surfaces, industrial parts surfaces, etc.) through the image acquisition module (which includes an industrial camera, lens, and light source) in the vision inspection system, and output the images after converting them to grayscale.
[0047] S2: Perform preprocessing on the acquired image, such as filtering, denoising, and illumination correction, and then determine the ROI for detection;
[0048] The ROI can be manually specified by the user based on the location of the target to be measured, or it can be automatically generated by the system based on template matching, edge positioning, target contour recognition, or preset coordinates.
[0049] S3: Perform multi-dimensional feature extraction on the detection region ROI (four features: gray-level mean, gray-level variance, normalized minimum gray-level feature, and normalized maximum gray-level feature), compressing the gray-level distribution of the detection region ROI into a multi-dimensional feature vector. ;
[0050] For each ROI to be detected (either during the background learning phase or the online detection phase), we extract a four-dimensional feature vector. To comprehensively describe its grayscale distribution characteristics:
[0051]
[0052] Gray mean The calculation formula is:
[0053]
[0054] in, The grayscale mean is... This represents the total number of pixels within the ROI. The gray value of the i-th pixel (typically ranging from 0 to 255) represents the overall brightness level of the region.
[0055] Gray variance The calculation formula is:
[0056]
[0057] in, For grayscale variance, This represents the total number of pixels within the ROI. Let be the grayscale value of the i-th pixel, representing the fluctuation of grayscale values or the intensity of texture within the region.
[0058] Normalized grayscale minimum value The calculation formula is:
[0059]
[0060] in The minimum grayscale value within the ROI. It is a very small constant (e.g.) To prevent division by zero, The grayscale mean is... The gray variance describes the degree of deviation of the left tail (dark area) of the distribution from the center of the distribution. It is normalized in units of standard deviation to make it scale-independent.
[0061] Normalized grayscale maximum value The calculation formula is:
[0062]
[0063] in It is the maximum grayscale value within the ROI. The minimum grayscale value within the ROI. The grayscale mean is... For grayscale variance, It is a very small constant (e.g.) This feature describes the degree of deviation of the right tail (bright part) of the distribution from the center of the distribution;
[0064] By introducing and This not only includes extreme value information, but also links extreme values to the overall location and distribution of the distribution by subtracting the mean and dividing by the standard deviation, making this feature influential on overall illumination changes (and simultaneously affecting...). It is not sensitive to local anomalies (such as a particularly dark pixel), but it will... Significantly reduced, but and The changes are relatively small, thus leading to (It is very sensitive to changes in absolute value);
[0065] Please see Figure 2 S4: Employs a dynamically updated background feature statistical model, entering the model background learning phase after system startup or reset.
[0066] Assuming in continuous Frame (e.g.) Within 50), the ROI does not contain the object to be tested;
[0067] S401: For the first Frame image ( Extract the feature vector of its ROI:
[0068]
[0069] in, For the first The four-dimensional feature vector of the ROI corresponding to the frame image. The first The corresponding grayscale mean, grayscale variance, minimum grayscale value within the ROI, and maximum grayscale value within the ROI in the frame; T is the transpose operation (used to represent a row vector composed of four feature quantities as a column vector).
[0070] S402: Calculate this The mean of each background sample in each feature dimension and standard deviation ;
[0071] The formula for calculating the mean of each background sample in each feature dimension is:
[0072]
[0073] in, for The mean of each background sample in each feature dimension for The mean of the background samples in terms of grayscale mean, grayscale variance, minimum grayscale value within the ROI, and maximum grayscale value within the ROI. The calculation formulas are as follows:
[0074]
[0075]
[0076]
[0077]
[0078] in, They are respectively The mean of the grayscale value, grayscale variance, minimum grayscale value within the ROI, and maximum grayscale value within the ROI for each background sample, where K represents the background sample. , , , for The mean gray level of each background sample;
[0079] The formula for calculating the standard deviation of each background sample in each feature dimension is:
[0080]
[0081] in, for The standard deviation of each background sample on each feature dimension for The standard deviations of the background samples in terms of mean gray level, variance gray level, minimum gray level within the ROI, and maximum gray level within the ROI. , The calculation formulas are as follows:
[0082]
[0083]
[0084]
[0085]
[0086] in, , They are respectively The standard deviations of the mean gray value, variance gray value, minimum gray value within the ROI, and maximum gray value within the ROI for each background sample, where K is the background sample size. , , , They are respectively The mean of the background samples in terms of grayscale mean, grayscale variance, minimum grayscale value within the ROI, and maximum grayscale value within the ROI. , , , for The mean gray level of each background sample;
[0087] S403: Establish the tolerance range for background features;
[0088] For each dimension (correspond Its normal fluctuation range is defined as:
[0089]
[0090] in It is a configurable confidence coefficient (usually set to 23, corresponding to a confidence interval of 95%-99.7%). for The mean across each dimension for Standard deviation in each dimension;
[0091] A four-dimensional hypercube boundary is formed by the normal fluctuation range;
[0092] Model update phase:
[0093] To address very slow background changes in the production environment (such as light source aging and slow drift of material background color), a background model was developed. and Online updates are performed, using an exponential moving average strategy. :
[0094]
[0095]
[0096] in, It is a decay factor close to 1 (e.g., 0.995). , These are the mean and standard deviation of the updated K background samples in each feature dimension. , The mean and standard deviation of the K background samples before the update in each feature dimension. This is the feature vector of the ROI extracted for each frame of the current image;
[0097] Ensure the model can track the slow drift of the background without being swayed by accidental objects or noise.
[0098] By introducing the aforementioned exponential moving average update mechanism, the system gains long-term self-adaptive capabilities, eliminating the need for frequent manual recalibration and significantly reducing maintenance costs.
[0099] S5: Perform calculations and decisions on the collected vectors.
[0100] S501: In the online detection phase, for each frame of the current image, extract the feature vector of its ROI:
[0101]
[0102] in, For each frame of the current image, the feature vector of the ROI is extracted. These are the mean gray level, gray level variance, minimum gray level within the ROI, and maximum gray level within the ROI extracted from the current image for each frame, respectively, and T is the transpose operation;
[0103] For each component of the feature vector, calculate its standardized deviation relative to the background model. :
[0104]
[0105] in, Let i be the standardized deviation of i relative to the background model. The absolute value of the value directly reflects the degree to which the current feature deviates from the normal range of the background in that dimension, and the unit is the standard deviation of the background itself in that dimension. It is a very small smoothing constant, preventing Too small a value leads to unstable values. Let i be the feature value of the current image in the i-th feature dimension. Let i be the mean of each feature dimension. Let i be the standard deviation of i in each feature dimension.
[0106] S502: Calculate the overall confidence level ;
[0107] Will This is combined with a fixed threshold to form a comprehensive index, defining the comprehensive confidence level. Weighted Euclidean distance for deviation in each dimension:
[0108]
[0109] in, To assess the overall confidence level, , , , These represent the grayscale mean, grayscale variance, normalized minimum grayscale feature, and normalized maximum grayscale feature, respectively, as standard scores relative to the background model. These are the weight coefficients for each feature dimension, satisfying:
[0110]
[0111] The weights can be configured according to the importance of each feature in different application scenarios;
[0112] For example, when detecting dark spots, it can be given Greater weight; when detecting texture loss, it can be assigned Greater weight.
[0113] S503: Adaptive Decision Making and Concentration Quantification;
[0114] Set a comprehensive threshold ,like If the condition is met, the object is considered to exist; otherwise, it is considered to not exist.
[0115] Furthermore, utilizing The concentration index is defined by quantifying the "concentration" or significance of an object using its own value. for:
[0116]
[0117] in, Concentration index To assess the overall confidence level, and There are two thresholds ( );
[0118] when hour, , indicating no object or negligible concentration;
[0119] when hour, This indicates that the concentration is saturated.
[0120] when In between, A linear mapping between 0 and 1 provides a continuous concentration measure;
[0121] The output can be a binary judgment (present / absent), a ternary judgment with concentration (absent / low concentration / high concentration), or even a continuous concentration index. ;
[0122] Standardized deviation Features with different dimensions and ranges are unified to a comparable standard deviation scale. Then, a comprehensive confidence level is obtained through fusion using configurable weights. This achieves adaptive comprehensive decision-making based on multiple features. Concentration index The introduction of this method makes the test results more informative.
[0123] Example 2: A visual detection system based on multi-dimensional grayscale statistics and adaptive discrimination, the system includes:
[0124] The image acquisition and grayscale output module acquires the image of the target under test through the image acquisition device, and outputs the image after converting it into a grayscale image;
[0125] This module acquires images of the target object through an industrial camera, lens, and light source. The target object can be printed materials, packaging, screens, pill packaging, agricultural product surfaces, industrial parts surfaces, etc. After grayscale processing, the acquired images are output as grayscale images for subsequent detection and analysis.
[0126] The image preprocessing and ROI determination module performs preprocessing on the acquired image, including filtering, noise reduction, and illumination correction, and then determines the detection region (ROI).
[0127] The grayscale image output by the image acquisition and grayscale output module is preprocessed, including filtering, denoising and illumination correction, in order to reduce the impact of image noise, local interference and uneven illumination on the detection results. After the preprocessing is completed, the ROI of the detection area that needs to be judged for density and presence is determined.
[0128] The ROI can be manually specified by the user based on the location of the target to be measured, or it can be automatically generated by the system based on template matching, edge positioning, target contour recognition, or preset coordinates.
[0129] The multi-dimensional grayscale feature extraction module performs multi-dimensional feature extraction on the detection area, including grayscale mean, grayscale variance, normalized minimum grayscale feature, and normalized maximum grayscale feature, compressing the grayscale distribution of the detection area (ROI) into a multi-dimensional feature vector. .
[0130] For each ROI to be detected, whether in the background learning stage or the online detection stage, a four-dimensional feature vector is extracted. This is used to comprehensively describe the grayscale distribution characteristics of the region.
[0131]
[0132] Gray mean The calculation formula is:
[0133]
[0134] in, The grayscale mean is... This represents the total number of pixels within the ROI. The gray value of the i-th pixel (typically ranging from 0 to 255) represents the overall brightness level of the region.
[0135] Gray variance The calculation formula is:
[0136]
[0137] in, For grayscale variance, This represents the total number of pixels within the ROI. Let be the grayscale value of the i-th pixel, representing the fluctuation of grayscale values or the intensity of texture within the region.
[0138] Normalized grayscale minimum value The calculation formula is:
[0139]
[0140] in The minimum grayscale value within the ROI. It is a very small constant (e.g.) To prevent division by zero, The grayscale mean is... The gray variance describes the degree of deviation of the left tail (dark area) of the distribution from the center of the distribution. It is normalized in units of standard deviation to make it scale-independent.
[0141] Normalized grayscale maximum value The calculation formula is:
[0142]
[0143] in It is the maximum grayscale value within the ROI. The minimum grayscale value within the ROI. The grayscale mean is... For grayscale variance, It is a very small constant (e.g.) This feature describes the degree of deviation of the right tail (bright part) of the distribution from the center of the distribution;
[0144] By introducing and This not only includes extreme value information, but also links extreme values to the overall location and distribution of the distribution by subtracting the mean and dividing by the standard deviation, making this feature influential on overall illumination changes (and simultaneously affecting...). It is not sensitive to local anomalies (such as a particularly dark pixel), but it will... Significantly reduced, but and The changes are relatively small, thus leading to (It is very sensitive to changes in absolute value);
[0145] The background model learning and adaptive update module, in the model background learning phase, assumes that in continuous... Frame (e.g.) Within a range of K frames (K = 50), the ROI does not contain the object to be tested. For example, K = 50. The system extracts multi-dimensional grayscale features from these K frames and establishes a statistical model of background features.
[0146] First, regarding the first Frame image ( Extract the feature vector of its ROI:
[0147]
[0148] in, For the first The four-dimensional feature vector of the ROI corresponding to the frame image. The first The corresponding grayscale mean, grayscale variance, minimum grayscale value within the ROI, and maximum grayscale value within the ROI in the frame; T is the transpose operation (used to represent a row vector composed of four feature quantities as a column vector).
[0149] Secondly, calculate this The mean of each background sample in each feature dimension and standard deviation ;
[0150] The formula for calculating the mean of each background sample in each feature dimension is:
[0151]
[0152] in, for The mean of each background sample in each feature dimension for The mean of the background samples in terms of grayscale mean, grayscale variance, minimum grayscale value within the ROI, and maximum grayscale value within the ROI. The calculation formulas are as follows:
[0153]
[0154]
[0155]
[0156]
[0157] in, They are respectively The mean of the grayscale value, grayscale variance, minimum grayscale value within the ROI, and maximum grayscale value within the ROI for each background sample, where K represents the background sample. , , , for The mean gray level of each background sample;
[0158] The formula for calculating the standard deviation of each background sample in each feature dimension is:
[0159]
[0160] in, for The standard deviation of each background sample on each feature dimension for The standard deviations of the background samples in terms of mean gray level, variance gray level, minimum gray level within the ROI, and maximum gray level within the ROI. , The calculation formulas are as follows:
[0161]
[0162]
[0163]
[0164]
[0165] in, , They are respectively The standard deviations of the mean gray value, variance gray value, minimum gray value within the ROI, and maximum gray value within the ROI for each background sample, where K is the background sample size. , , , They are respectively The mean of the background samples in terms of grayscale mean, grayscale variance, minimum grayscale value within the ROI, and maximum grayscale value within the ROI. , , , for The mean gray level of each background sample;
[0166] Finally, establish the tolerance range for background features. For each dimension... (correspond Its normal fluctuation range is defined as:
[0167]
[0168] in It is a configurable confidence coefficient (usually set to 23, corresponding to a confidence interval of 95%-99.7%). for The mean across each dimension for Standard deviation in each dimension;
[0169] A four-dimensional hypercube boundary is formed by the normal fluctuation range.
[0170] To address very slow background changes in the production environment (such as light source aging and slow drift of material background color), a background model was developed. and Online updates are performed, using an exponential moving average strategy. :
[0171]
[0172]
[0173] in, It is a decay factor close to 1 (e.g., 0.995). , These are the mean and standard deviation of the updated K background samples in each feature dimension. , The mean and standard deviation of the K background samples before the update in each feature dimension. This is the feature vector of the ROI extracted for each frame of the current image;
[0174] Ensure the model can track the slow drift of the background without being swayed by accidental objects or noise.
[0175] By introducing the aforementioned exponential moving average update mechanism, the system gains long-term self-adaptive capabilities, eliminating the need for frequent manual recalibration and significantly reducing maintenance costs.
[0176] The integrated decision-making and result output module performs deviation calculation, comprehensive confidence calculation, adaptive judgment, and concentration quantization output on the feature vector obtained from the currently acquired image.
[0177] During the online detection phase, for each frame of the current image, the feature vector of its ROI is extracted:
[0178]
[0179] in, For each frame of the current image, the feature vector of the ROI is extracted. These are the mean gray level, gray level variance, minimum gray level within the ROI, and maximum gray level within the ROI extracted from the current image for each frame, respectively, and T is the transpose operation;
[0180] First, for each component of the feature vector, calculate its standard score relative to the background model:
[0181]
[0182] in, Let i be the standardized deviation of i relative to the background model. The absolute value of the value directly reflects the degree to which the current feature deviates from the normal range of the background in that dimension, and the unit is the standard deviation of the background itself in that dimension. It is a very small smoothing constant, preventing Too small a value leads to unstable values. Let i be the feature value of the current image in the i-th feature dimension. Let i be the mean of each feature dimension. Let i be the standard deviation of i in each feature dimension.
[0183] Secondly, calculate the overall confidence level C, and then... This is combined with a fixed threshold to form a comprehensive index, defining the comprehensive confidence level. Weighted Euclidean distance for deviation in each dimension:
[0184]
[0185] in, To assess the overall confidence level, , , , These represent the grayscale mean, grayscale variance, normalized minimum grayscale feature, and normalized maximum grayscale feature, respectively, as standard scores relative to the background model. These are the weight coefficients for each feature dimension, satisfying:
[0186]
[0187] The weights can be configured according to the importance of each feature in different application scenarios;
[0188] For example, when detecting dark spots, it can be given Greater weight; when detecting texture loss, it can be assigned Greater weight;
[0189] Finally, adaptive decision-making and concentration quantification are performed, and a comprehensive threshold is set. ,like If the condition is met, the object is considered to exist; otherwise, it is considered to not exist.
[0190] Furthermore, utilizing The concentration index is defined by quantifying the "concentration" or significance of an object using its own value. for:
[0191]
[0192] in, Concentration index To assess the overall confidence level, and There are two thresholds ( );
[0193] when hour, , indicating no object or negligible concentration;
[0194] when hour, This indicates that the concentration is saturated.
[0195] when In between, A linear mapping between 0 and 1 provides a continuous concentration measure;
[0196] The output can be a binary judgment (present / absent), a ternary judgment with concentration (absent / low concentration / high concentration), or even a continuous concentration index. ;
[0197] The multidimensional grayscale features of the current detection area (including grayscale mean, grayscale variance, normalized minimum grayscale feature, and normalized maximum grayscale feature) are compared with the background model, and the deviation is standardized. The influence of different feature units and value ranges is eliminated, and then a weighted fusion is used to obtain the comprehensive confidence level. Ultimately, this enables the determination of whether an object exists and the quantitative output of its concentration.
[0198] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A visual detection method based on multi-dimensional grayscale statistics and adaptive discrimination, characterized in that, Includes the following steps: S1. Image Grayscale Acquisition: The image of the target to be tested is acquired through the image acquisition module of the vision inspection system, and the target image is converted into a grayscale image before being output. S2. Image region localization: Preprocess the acquired image and then determine the detection region; S3. Gray-level feature extraction of the detection area: Multi-dimensional gray-level feature extraction is performed on the detection area to obtain a multi-dimensional feature vector of the gray-level distribution characteristics of the detection area. The multi-dimensional feature vector includes gray-level mean, gray-level variance, normalized minimum gray-level feature and normalized maximum gray-level feature. S4. Background Modeling and Update: After the visual inspection system is started or reset, it enters the background learning stage. For the multi-dimensional feature vectors of the detection area without the test object in multiple consecutive frames, the background mean and background standard deviation of each feature dimension in the background learning samples are calculated, and a background feature statistical model and the normal fluctuation range of each feature dimension are established accordingly. In the model update stage, the background feature statistical model is dynamically updated online. S5. Region Deviation Fusion and Concentration Output: The visual detection system performs online detection of the detection region in the currently acquired image, extracts the multi-dimensional feature vector of the detection region, calculates the standardized deviation of each feature dimension relative to the background model, and then fuses the standardized deviations of each feature dimension with their corresponding weights to obtain the comprehensive confidence score. Finally, based on the comprehensive confidence score and the preset comprehensive threshold, it is determined whether there is a target object in the current detection region, and the concentration quantification result of the target object is output according to the relationship between the comprehensive confidence score and the preset low threshold and high threshold.
2. The visual detection method based on multi-dimensional grayscale statistics and adaptive discrimination according to claim 1, characterized in that: In step S1, the image acquisition module includes an industrial camera, a lens, and a light source, and the target to be measured includes at least one of printed matter, packaging, screen, pill packaging, agricultural product surface, or industrial part surface. In step S2, the detection area after image processing is manually specified by the user based on the location of the target to be tested, or automatically generated by the system based on template matching, edge positioning, target contour recognition, or preset coordinates.
3. The visual detection method based on multi-dimensional grayscale statistics and adaptive discrimination according to claim 1, characterized in that: In step S3, a four-dimensional feature vector is extracted for each region to be detected during either the background learning stage or the online detection stage.
4. The visual detection method based on multi-dimensional grayscale statistics and adaptive discrimination according to claim 1, characterized in that, The background feature statistical model learning stage in step S4 includes the following sub-steps: S401. After the visual inspection system is started or reset, select a series of consecutive frames of detection areas that do not contain the object to be tested as background samples. The number of consecutive frames is a preset number of frames. S402. Extract four-dimensional feature vectors from the detection regions in each frame of background samples. Based on the four-dimensional feature vectors of background samples from multiple consecutive frames, calculate the background mean and background standard deviation in each feature dimension to obtain a background feature statistical model. S403. Based on the background mean, background standard deviation and confidence coefficient of each feature dimension, establish the normal fluctuation range of each feature dimension, and form the four-dimensional hypercube boundary of the background feature by the normal fluctuation range of each feature dimension.
5. The visual detection method based on multi-dimensional grayscale statistics and adaptive discrimination according to claim 1, characterized in that: In step S4, the background feature statistical model update stage, when the current detection area is determined to have no target object or the overall confidence level is lower than the preset update threshold, the background mean and background standard deviation in the background feature statistical model are updated online using the exponential moving average method.
6. The visual detection method based on multi-dimensional grayscale statistics and adaptive discrimination according to claim 1, characterized in that, Step S5 includes the following sub-steps: S501. In the online detection stage, a four-dimensional feature vector is extracted from the detection region in each frame of the current image. The four-dimensional feature vector of the current image is compared with the background feature statistical model, and the standardized deviation of each feature dimension relative to the background model is calculated. S502. Weighted fusion is performed based on the standardized deviation of each feature dimension and the corresponding weight coefficient to obtain the comprehensive confidence level. The weight coefficient is configured according to the importance of each gray-level feature in different application scenarios. When detecting dark spots, the weight corresponding to the normalized minimum gray-level feature is increased, and when detecting texture loss, the weight corresponding to the gray-level variance is increased. S503. Compare the overall confidence level with the preset overall threshold, and output the concentration quantification result based on the relationship between the overall confidence level and the preset low threshold and high threshold. The output results include binary judgments, ternary judgments, or continuous concentration indices.
7. A visual detection system based on multi-dimensional grayscale statistics and adaptive discrimination, characterized in that, The system is used in the visual detection method based on multi-dimensional grayscale statistics and adaptive discrimination as described in any one of claims 1-6, the system comprising: The image acquisition and grayscale output module acquires the target image to be tested, converts the target image to grayscale, and then outputs it. The image preprocessing and ROI determination module receives a grayscale image, preprocesses the grayscale image, and determines the detection area of the preprocessed image. The multi-dimensional gray-level feature extraction module extracts multi-dimensional gray-level features based on the image detection area to obtain a multi-dimensional feature vector that characterizes the gray-level distribution characteristics of the detection area. The multi-dimensional feature vector includes gray-level mean, gray-level variance, normalized minimum gray-level feature, and normalized maximum gray-level feature. The background model learning and adaptive update module obtains multi-dimensional feature vectors. During the background learning stage of the visual detection system, based on the multi-dimensional feature vectors of the detection area without the test object in multiple consecutive frames, it calculates the background mean and background standard deviation of each feature dimension in the background learning samples, and establishes a background feature statistical model and the normal fluctuation range of each feature dimension. The integrated decision and result output module acquires the multi-dimensional feature vector of the detection area in the currently acquired image during the online detection stage, compares the multi-dimensional feature vector of the current detection area with the background feature statistical model, calculates the standardized deviation of each feature dimension relative to the background feature statistical model, and integrates each standardized deviation into a comprehensive confidence score. Based on the comprehensive confidence score, it outputs the presence or absence judgment result or concentration quantification result of the object to be tested.
8. The visual detection system based on multi-dimensional grayscale statistics and adaptive discrimination according to claim 7, characterized in that: The image acquisition and grayscale output module includes an industrial camera, a lens, and a light source. The target to be measured includes at least one of printed matter, packaging, screen, pill packaging, agricultural product surface, or industrial part surface. The detection area of the image preprocessing and ROI determination module is manually specified by the user based on the location of the target to be tested, or automatically generated by the system based on template matching, edge localization, target contour recognition, or preset coordinates.
9. The visual detection system based on multi-dimensional grayscale statistics and adaptive discrimination according to claim 7, characterized in that: The background model learning and adaptive update module selects multiple consecutive frames of detection area images without the test object as background samples during the background learning stage. It extracts the multidimensional feature vectors of the detection area in each frame, calculates the mean and standard deviation of each feature dimension, and determines the normal fluctuation range of each feature dimension based on the mean, standard deviation and confidence coefficient, so that the normal fluctuation range of multiple feature dimensions together constitutes the multidimensional background boundary. During the model update phase, the mean and standard deviation in the background feature statistical model are updated online using an exponential moving average method.
10. The visual detection system based on multi-dimensional grayscale statistics and adaptive discrimination according to claim 7, characterized in that: During the online detection phase, the integrated decision-making and result output module calculates the standardized deviation of each feature component in the multidimensional feature vector of the current detection area relative to the background feature statistical model, and performs weighted fusion of the standardized deviation according to the weight of each feature dimension to obtain the comprehensive confidence level. Based on the relationship between the overall confidence level and the low and high thresholds, a concentration index is output to represent the concentration or significance of the object.