Method for detecting appearance defects of electric energy meter based on machine vision
By constructing a local window to obtain the illumination interference index, adaptively selecting the Gaussian filter scale, extracting the reflection component and calculating the entropy value, the problem of reduced accuracy caused by illumination interference in the appearance inspection of electricity meters is solved, and more accurate defect detection is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANDONG DEYUAN ELECTRICITY TECH CO LTD
- Filing Date
- 2025-08-06
- Publication Date
- 2026-06-05
AI Technical Summary
In existing technologies, defect detection of the appearance image of an electricity meter is affected by light interference, resulting in reduced detection accuracy, especially as weak or low-contrast defect features are submerged or blurred by the light background.
By constructing a local window, a weighted gray value variance sequence is obtained and linearly fitted to obtain an indicator of the probability of illumination interference. The Gaussian filter scale is adaptively selected, the reflection component is extracted, a gradient histogram is constructed, and the entropy value is calculated for defect detection.
It improves the accuracy of detecting appearance defects in electricity meters, avoids the influence of light interference on the detection results, and enhances the ability to identify minor defects.
Smart Images

Figure CN120931617B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of defect detection technology, and in particular to a method for detecting appearance defects in electricity meters based on machine vision. Background Technology
[0002] As an important metering device, the appearance quality of electricity meters directly affects product image and user trust. Therefore, it is crucial to conduct automated detection of appearance defects (such as scratches, dents, stains, etc.) in sub-areas such as the casing, display screen, buttons, and wiring terminals of electricity meters during the production process.
[0003] In existing technologies, the detection of appearance defects in the casing of electricity meters typically involves acquiring an image of the meter's exterior and identifying defects based on that image. However, electricity meter casings are usually composed of composite materials (such as engineering plastics, metals, and glass), and their surfaces have complex reflective properties. When subjected to lighting interference, this interference is amplified, causing weak or low-contrast defect features (such as shallow scratches or minor dents) in the appearance image to be submerged by uneven lighting backgrounds or covered by highlight or shadow areas. This obscures the true texture and defects in the electricity meter's appearance image. Even with a fixed light source, slight changes in ambient light or minor vibrations of the device itself can cause fluctuations in lighting conditions, blurring the defect features in the original image and thus limiting the accuracy of defect detection. Summary of the Invention
[0004] In view of this, embodiments of the present invention provide a machine vision-based method for detecting defects in the appearance of electricity meters, in order to solve the problem that light interference masks the true texture and defects in the appearance image of electricity meters, thereby reducing the accuracy of defect detection.
[0005] This invention provides a machine vision-based method for detecting appearance defects in electricity meters, the method comprising the following steps:
[0006] Acquire an external image of the electricity meter, and convert the external image to grayscale to obtain a corresponding grayscale image;
[0007] For any pixel in the grayscale image, at least two local windows of different sizes are constructed in the grayscale image with the pixel as the center. Based on the distance between each pixel in each local window and the pixel and the local grayscale correlation, the weighted grayscale variance of each local window is obtained to form a weighted grayscale variance sequence of the pixel.
[0008] Linear fitting is performed on the weighted gray value variance sequence to obtain a weighted variance change function. The slope of the weighted variance change function is recorded as the probability index of any pixel being affected by illumination interference. The probability index of each pixel in the grayscale image being affected by illumination interference is obtained.
[0009] Based on the probability index of each pixel in the grayscale image being affected by illumination, the adaptive Gaussian scale of each pixel is obtained when Gaussian filtering is applied to the grayscale image, and the reflection component of the grayscale image is obtained based on the adaptive Gaussian scale of each pixel.
[0010] Construct a gradient histogram of the reflection component, calculate the entropy value of the gradient histogram, obtain a defect entropy threshold, and perform appearance defect detection on the energy meter based on the entropy value and the defect entropy threshold.
[0011] Preferably, the step of obtaining the weighted grayscale variance of each local window based on the distance between each pixel in each local window and any other pixel, and the local grayscale correlation, includes:
[0012] For any local window, any pixel in the local window other than the specified pixel is taken as the target pixel. The Euclidean distance between the target pixel and the specified pixel is calculated, and the Euclidean distance is quantized using a preset Gaussian weight function to obtain the first weight of the target pixel. The preset Gaussian weight function is: , Indicates the first weight. This represents an exponential function with the natural constant as its base. This represents the Euclidean distance between the target pixel and any of the aforementioned pixels. This indicates the preset attenuation weight;
[0013] Based on a preset size, target pixels and target windows for any pixel are constructed respectively. Pearson correlation coefficients are calculated based on the gray values in the two target windows. The Pearson correlation coefficients are then normalized to obtain the second weight of the target pixel.
[0014] Obtain the first weight and the second weight of each target pixel in any local window, and obtain the weighted gray value variance of any local window based on the first weight and the second weight of each target pixel in any local window.
[0015] Preferably, obtaining the weighted grayscale variance of any local window based on the first weight and the second weight of each target pixel in any local window includes:
[0016] The product of the first weight and the second weight of each target pixel in any local window is used as the final weight of each target pixel. The mean gray value of all target pixels is calculated. The squared difference between the gray value of each target pixel and the mean gray value is calculated. Based on the final weight of each target pixel, the squared differences are summed in a weighted manner to obtain a weighted sum. The ratio between the weighted sum and the number of all target pixels is used as the weighted gray value variance of any local window.
[0017] Preferably, the weighted variance change function is:
[0018] ;
[0019] in, Indicate size The weighted variance of the grayscale values of the corresponding local window. Indicates the slope. Indicates the size of a local window. This represents the intercept.
[0020] Preferably, the step of obtaining the adaptive Gaussian scale for each pixel when performing Gaussian filtering on the grayscale image based on the probability index of each pixel being affected by illumination interference in the grayscale image includes:
[0021] The pixels in the grayscale image are divided into a first type of pixel and a second type of pixel based on the probability index of each pixel being affected by illumination. The adaptive Gaussian scale of each first type of pixel is set to a preset basic Gaussian scale. For any second type of pixel, the adaptive Gaussian scale is obtained based on the probability index of any second type of pixel being affected by illumination.
[0022] Preferably, the step of dividing the pixels in the grayscale image into a first category of pixels and a second category of pixels based on the probability index of each pixel being affected by illumination interference includes:
[0023] Based on the probability index of each pixel in the grayscale image being affected by illumination, the probability index corresponding to the preset percentile of all probability indices is used as a threshold. Pixels with probability indices less than the threshold are classified as first-class pixels, and pixels with probability indices greater than or equal to the threshold are classified as second-class pixels.
[0024] Preferably, obtaining the adaptive Gaussian scale based on the probability index of any second-type pixel being affected by illumination interference includes:
[0025] ;
[0026] in, Indicates the first The adaptive Gaussian scale corresponding to each second type of pixel. This represents the preset scaling factor used to control Gaussian scale sensitivity. Represents the maximum value function. Indicates the first An indicator of the probability that a second type of pixel is affected by illumination interference. This represents the threshold value, where 0 represents a constant. This indicates the preset base Gaussian scale.
[0027] Preferably, obtaining the reflection component of the grayscale image based on an adaptive Gaussian scale for each pixel includes:
[0028] Based on the adaptive Gaussian scale of each pixel, the grayscale image is subjected to Gaussian filtering to obtain the illumination component in the grayscale image. The illumination component is then removed to obtain the reflection component in the grayscale image.
[0029] Preferably, obtaining the defect entropy threshold includes:
[0030] Acquire grayscale images of at least two electricity meters without visible defects, obtain the entropy values of the gradient histograms of the corresponding reflection components, form an entropy value set, obtain the mean and standard deviation of the entropy value set, and subtract three times the standard deviation from the mean as the defect entropy threshold.
[0031] The beneficial effects of the embodiments of the present invention compared with the prior art are as follows:
[0032] This invention quantifies the probability of each pixel being affected by illumination interference by using the linear change of the weighted grayscale variance of each local window. This avoids interference caused by defects on the surface of the electricity meter (such as scratches, stains), multi-material boundaries, and sharp edges such as digital markings, which lead to large local variances in pixels in these areas. Furthermore, based on the probability of each pixel being affected by illumination interference in the grayscale image, an adaptive Gaussian scale is obtained for each pixel when performing Gaussian filtering on the grayscale image. This ensures that pixels without illumination interference, even if their local variance is large within a certain window, will not be misclassified as pixels with strong illumination interference. Simultaneously, pixels with strong illumination interference will have their filtering scale enhanced by the probability of illumination interference, thereby improving the accuracy of obtaining the reflection component of the grayscale image based on the adaptive Gaussian scale of each pixel. This makes the detection of appearance defects in electricity meters using the entropy value of the gradient histogram more accurate. Attached Figure Description
[0033] To more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0034] Figure 1 This is a flowchart of a method for detecting appearance defects in electricity meters based on machine vision, provided in Embodiment 1 of the present invention. Detailed Implementation
[0035] Embodiments of this disclosure are described in detail below, with examples of these embodiments illustrated in the accompanying drawings. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain this disclosure, and should not be construed as limiting it.
[0036] It should be noted that the terms "first," "second," etc., used in this disclosure and the accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this disclosure described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure.
[0037] To illustrate the technical solution of the present invention, specific embodiments are described below.
[0038] See Figure 1 This is a flowchart of a method for detecting appearance defects in electricity meters based on machine vision, as provided in Embodiment 1 of the present invention. Figure 1 As shown, the method may include:
[0039] Step S101: Obtain an image of the electricity meter's appearance, and convert the appearance image to grayscale to obtain the corresponding grayscale image.
[0040] Because the surface of an electricity meter has complex reflective properties, light interference can obscure the true texture and defects in the meter's appearance image. Therefore, embodiments of the present invention need to accurately separate the reflective component in the appearance image, eliminate light interference, and enhance defect features to improve the accuracy of electricity meter appearance defect detection.
[0041] First, an image of the electricity meter's appearance is acquired using an imaging device. Then, considering that the image can be decomposed into illumination and reflection components, and that illumination variations are typically low-frequency components, a Gaussian low-pass filter can be used to extract the illumination component. However, a fixed-scale filter cannot adapt to the non-uniformity of illumination interference in the image. For example, in areas with strong illumination interference, there are significant brightness variations in the image, which are usually large-scale (low-frequency components). To effectively smooth such large-scale illumination variations, a large-scale Gaussian kernel is needed because it has a wider support domain, covering a larger range of pixels and thus better smoothing low-frequency brightness gradients. Conversely, if the illumination interference is weak (i.e., the image brightness is relatively uniform), only a small amount of smoothing or even no smoothing is needed to avoid blurring details; in this case, a smaller-scale Gaussian kernel should be used. Therefore, this embodiment of the invention requires adaptive filtering scale selection based on the characteristics of each pixel in the appearance image. Even when the appearance image is subject to illumination interference, the illumination component in the image can still be accurately extracted. The appearance image is then grayscaled to obtain the corresponding grayscale image, which is used to subsequently obtain the adaptive filtering scale for each pixel.
[0042] Step S102: For any pixel in the grayscale image, construct at least two local windows of different sizes in the grayscale image with the pixel as the center. Based on the distance between each pixel in each local window and any pixel and the local grayscale correlation, obtain the weighted grayscale variance of each local window and form a weighted grayscale variance sequence for any pixel.
[0043] When selecting the filtering scale for each pixel in a grayscale image, it is necessary to choose an appropriate filtering scale based on the degree of local illumination interference of the pixel, thereby smoothing illumination changes (such as shadows or brightness gradients) while preserving material boundaries and defect details. Local grayscale variance reflects the dispersion of grayscale values. When the degree of illumination interference of a pixel is high, the local grayscale variance of the pixel will be relatively large. However, due to defects on the surface of the electricity meter (such as scratches and stains), multi-material boundaries, and sharp edges such as digital markings, the local grayscale variance of pixels in these areas will also be large. Therefore, the local grayscale variance of a pixel cannot be directly used as a quantitative indicator of illumination interference. Therefore, in this embodiment of the invention, for any pixel in the grayscale image, at least two local windows of different sizes are constructed in the grayscale image centered on that pixel, and the size of the local window is defined. ,in, ,For example, There are no restrictions here. Then, based on the distance between each pixel and any other pixel in each local window and the local grayscale correlation, the weighted grayscale variance of each local window is obtained, forming a weighted grayscale variance sequence for any pixel, which is used to quantify the light interference of any pixel.
[0044] The weighted grayscale variance of each local window is calculated based on the distance between each pixel and any other pixel and the local grayscale correlation, as follows:
[0045] (1) For any pixel, as the local window increases, the correlation between the pixels surrounding the local window and any pixel becomes weaker and weaker. Furthermore, the farther the pixels surrounding the local window are from any pixel, the weaker their correlation, and the lower their value in analyzing the degree of illumination interference for any pixel. Therefore, for any local window, any pixel in the local window other than the pixel itself is taken as the target pixel. The Euclidean distance between the target pixel and the pixel is calculated, and the Euclidean distance is quantized using a preset Gaussian weighting function to obtain the first weight of the target pixel. The preset Gaussian weighting function is: , Indicates the first weight. This represents an exponential function with the natural constant as its base. This represents the Euclidean distance between the target pixel and any of the aforementioned pixels. This indicates the preset attenuation weight.
[0046] It should be noted that, Smaller ones used to control the decay rate This makes the weights more concentrated on the nearest pixels with the center intensity, resulting in larger... To make the weights more even, this is done based on the image characteristics of the electricity meter. (Unit: pixels).
[0047] (2) Since it is necessary to extract the illumination component, the influence of the illumination component is global, that is, the gray value of some pixels affected by the illumination shows an increasing or decreasing trend, and the gray value change is uniform. However, local defects or other reasons can cause the gray value change to show an uneven effect. Therefore, the preset size of the target window is set to 7×7. Then, based on the preset size, the target pixel and the target window of the target pixel are constructed respectively. The Pearson correlation coefficient is calculated according to the gray value in the two target windows. The Pearson correlation coefficient is normalized to obtain the second weight of the target pixel. The value of the Pearson correlation coefficient is 7×7. The calculated Pearson correlation coefficient was normalized to The interval is used as the second weight, denoted as The larger the second weight, the greater the local grayscale similarity between any pixel and the target pixel. This indicates a lower probability that the target pixel is affected by other influencing factors, and the grayscale value calculated is more consistent with reality. Pearson correlation coefficient and normalization are existing technologies and will not be elaborated upon here.
[0048] (3) Similarly, obtain the first weight and the second weight of each target pixel in any local window, and obtain the weighted gray value variance of any local window based on the first weight and the second weight of each target pixel in any local window.
[0049] Specifically, the product of the first weight and the second weight of each target pixel in any local window is taken as the final weight of each target pixel. The mean gray value of all target pixels is calculated. The squared difference between the gray value of each target pixel and the mean gray value is calculated. Based on the final weight of each target pixel, the squared differences are summed in a weighted manner to obtain a weighted sum. The ratio between the weighted sum and the number of all target pixels is taken as the weighted gray value variance of any local window.
[0050] The formula for calculating the weighted gray value variance of any local window is as follows:
[0051]
[0052] in, Represents any pixel point The size is The weighted gray value variance of the local window. Represents the target pixel. The product of the first weight and the second weight, Represents the target pixel. grayscale value, This represents the average grayscale value of all target pixels within the local window. This indicates the number of pixels within a local window. This indicates the number of target pixels within the local window.
[0053] Similarly, the weighted gray value variance corresponding to each local window of any pixel is obtained, and then a weighted gray value variance sequence is formed.
[0054] Step S103: Perform linear fitting on the weighted gray value variance sequence to obtain the weighted variance change function, and record the slope of the weighted variance change function as the probability index of any pixel being affected by illumination interference; obtain the probability index of each pixel in the grayscale image being affected by illumination interference.
[0055] After obtaining the weighted gray value variance sequence for any pixel, in order to accurately quantify the degree of illumination interference, the least squares method is used to linearly fit the weighted gray value variance sequence to obtain the weighted variance change function, wherein the weighted variance change function is:
[0056]
[0057] in, Indicate size The weighted variance of the grayscale values of the corresponding local window. Indicates the slope. Indicates the size of a local window. This represents the intercept.
[0058] It should be noted that, This is used to quantify the growth rate of the weighted gray value variance as the local window size increases. When the weighted gray value variance increases linearly with the size of the local window, ... And the larger the value, the faster the linear growth rate, then... The larger, This refers to the size of a local window. The intercept is used to capture the size of a local window. The theoretical weighted gray value variance when it approaches 0 reflects the weighted gray value variance when the window size is small.
[0059] When the slope of any pixel This indicates that the local variance (weighted gray value variance) of that pixel does not increase with the size of the local window. The essence of illumination interference is the spatial gradual change of gray values; this gradual change accumulates more differences over a larger area, causing the weighted gray value variance to increase approximately linearly. Since there are multiple uniform regions in the image, i.e., without illumination interference or structural changes, the weighted gray value variance changes very little with the size of the local window, i.e., the slope is small. Since the slope is close to 0, in this embodiment of the invention, the slope of the weighted variance change function is recorded as the probability index of any pixel being affected by illumination interference. Similarly, the probability index of each pixel in the grayscale image being affected by illumination interference is obtained.
[0060] Step S104: Based on the probability index of each pixel in the grayscale image being affected by illumination interference, obtain the adaptive Gaussian scale of each pixel when performing Gaussian filtering on the grayscale image, and obtain the reflection component of the grayscale image based on the adaptive Gaussian scale of each pixel.
[0061] When the slope Grayscale images, with a value close to 0, possess complex characteristics, including defects (such as scratches and blemishes), multi-material boundaries, and sharp edges such as digital identifiers. These areas may also lead to large local variance, but are not caused by illumination interference. Therefore, after obtaining the probability index of each pixel in the grayscale image being affected by illumination interference, the probability index corresponding to the 10th percentile of all probability indices is selected as the threshold to divide the pixels in the grayscale image into first-class pixels and second-class pixels. This method can adapt to the complexity of images to a certain extent, avoid misjudging some non-illumination interference but large local variance areas as illumination interference areas, and improve the robustness of the algorithm.
[0062] It should be noted that, due to the slope of the uniform region The slope is close to 0, while the slope of the area affected by illumination interference is... Furthermore, since the slope is relatively large, choosing an appropriate threshold can effectively distinguish between these two types of regions. The 10th percentile represents the slope across all pixels. In the sorting process, if 10% of the pixels have a slope less than the threshold and 90% have a slope greater than the threshold, choosing the 10th percentile as the threshold can effectively ensure that those pixels with slopes are sorted. Pixels in uniform regions with a probability index close to 0 are selected because they are considered to have an extremely low probability of being affected by illumination. Therefore, in this embodiment of the invention, pixels with a probability index less than the threshold are classified as first-class pixels, and pixels with a probability index greater than or equal to the threshold are classified as second-class pixels.
[0063] Furthermore, based on the classified pixels, an adaptive Gaussian scale for each pixel is obtained when performing Gaussian filtering on the grayscale image, maintaining the accuracy of the subsequently extracted illumination components. Specifically, for the first type of pixels, the possibility of these pixels being affected by illumination interference is extremely low, so a smaller filter scale should be assigned to these pixels, with very small smoothing or even no smoothing, to avoid blurring details. Therefore, in this embodiment of the invention, the adaptive Gaussian scale for each first type of pixel is set to a preset base Gaussian scale. ,and For any second-class pixel, then The larger the value, the greater the illumination interference at that pixel, and the larger the required filter size. This effectively smooths out such large-scale illumination changes. Therefore, based on the probability index of illumination interference for any second-type pixel, an adaptive Gaussian scale is obtained, where the calculation formula for the adaptive Gaussian scale is:
[0064]
[0065] in, Indicates the first The adaptive Gaussian scale corresponding to each second type of pixel. This represents the preset scaling factor used to control Gaussian scale sensitivity. Represents the maximum value function. Indicates the first An indicator of the probability that a second type of pixel is affected by illumination interference. This represents the threshold value, where 0 represents a constant. This indicates the preset base Gaussian scale.
[0066] It should be noted that, A threshold is used to filter noise, for example when When there is no light interference, it is considered as no light interference in this solution. Take the slope of all pixels The 10th percentile is used as the threshold. It serves as the base scale to ensure minimal smoothness. Used to ensure that adjustments at the base scale are non-negative. The larger, the better The larger the value, the more likely it is to be the first. The greater the illumination interference of a second-type pixel, the larger it needs to be on the base scale. And when... hour, A value of 0 indicates that the first... The illumination interference of the second type of pixel is extremely small and can be ignored, thus making the second type of pixel... The scale of each second-type pixel is set as the base scale. Base scale The size of the basic scale is directly proportional to the resolution and size of the acquired image of the electricity meter's appearance. Higher resolution and larger size images contain more image details. To ensure minimum smoothness, the base scale in this scheme should be appropriately increased. Take 1.5.
[0067] Therefore, for pixels in the image of an electricity meter that are not affected by illumination interference, even if the local variance of the pixel is large within a certain local window, the pixel will not be misclassified as a pixel with strong illumination interference, and the filtering scale for that pixel will remain at a relatively small base scale. However, for pixels in the image of an electricity meter that are affected by strong illumination interference, the slope of the weighted variance change function of that pixel will be used to represent the intensity of the illumination interference, thereby increasing the base scale; the stronger the illumination interference, the greater the increase.
[0068] Thus, the adaptive Gaussian scale for each pixel when performing Gaussian filtering on a grayscale image is obtained. Then, based on the adaptive Gaussian scale for each pixel, Gaussian filtering is performed on the grayscale image to obtain the illumination component. According to Retinex theory, the illumination component is removed to obtain the reflection component. The extraction of the illumination component using Gaussian filtering is a prior art technique, and the extraction of the reflection component from the illumination component is also a prior art technique, which will not be elaborated upon here.
[0069] Step S105: Construct the gradient histogram of the reflection component, calculate the entropy value of the gradient histogram, obtain the defect entropy threshold, and perform appearance defect detection on the energy meter based on the entropy value and the defect entropy threshold.
[0070] Since this embodiment of the invention aims to construct a gradient histogram using the gradients of all pixels, and then use the entropy value of the gradient histogram to detect appearance defects in the electricity meter, the accuracy of the gradient of each pixel directly affects the accuracy of the entropy value, and thus the accuracy of appearance defect detection. Therefore, this embodiment of the invention first calculates the gradient of each pixel on the reflection component using the Sobel operator, and then constructs a gradient histogram of the reflection component based on the gradient of each pixel. In this gradient histogram, the horizontal axis is the gradient and the vertical axis is the frequency. The entropy value of the gradient histogram is calculated. It is worth noting that the reflection component has been excluded from illumination interference. By calculating the entropy value of the gradient histogram of the reflection component, the distortion of the entropy value due to illumination interference is avoided.
[0071] A higher entropy value indicates a more uniform distribution and a lower probability of defects. Conversely, a lower entropy value indicates a more concentrated distribution in a certain area and a higher probability of defects. Therefore, the entropy value is used to detect visual defects in electricity meters, as detailed below:
[0072] Acquire grayscale images of at least two electricity meters without visible defects. Following the method described above for acquiring reflection components, acquire the reflection component of each grayscale image, and then obtain the entropy value of the gradient histogram of the corresponding reflection component. Form an entropy value set, and obtain the mean and standard deviation of the entropy value set. Based on the Laida criterion, subtract three times the standard deviation from the mean as the defect entropy threshold. If the entropy value is less than the defect entropy threshold, the electricity meter is determined to have a visible defect.
[0073] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.
Claims
1. A machine vision-based method for detecting appearance defects in electricity meters, characterized in that, The method includes: Acquire an external image of the electricity meter, and convert the external image to grayscale to obtain a corresponding grayscale image; For any pixel in the grayscale image, at least two local windows of different sizes are constructed in the grayscale image with the pixel as the center. Based on the distance between each pixel in each local window and the pixel and the local grayscale correlation, the weighted grayscale variance of each local window is obtained to form a weighted grayscale variance sequence of the pixel. Linear fitting is performed on the weighted gray value variance sequence to obtain a weighted variance change function. The slope of the weighted variance change function is recorded as the probability index of any pixel being affected by illumination interference. The probability index of each pixel in the grayscale image being affected by illumination interference is obtained. Based on the probability index of each pixel in the grayscale image being affected by illumination, the adaptive Gaussian scale of each pixel is obtained when Gaussian filtering is applied to the grayscale image, and the reflection component of the grayscale image is obtained based on the adaptive Gaussian scale of each pixel. Construct a gradient histogram of the reflection component, calculate the entropy value of the gradient histogram, obtain a defect entropy threshold, and perform appearance defect detection on the energy meter based on the entropy value and the defect entropy threshold.
2. The method for detecting appearance defects in electricity meters based on machine vision according to claim 1, characterized in that, The step of obtaining the weighted grayscale variance of each local window based on the distance between each pixel in each local window and any other pixel, and the local grayscale correlation, includes: For any local window, any pixel in the local window other than the specified pixel is taken as the target pixel. The Euclidean distance between the target pixel and the specified pixel is calculated, and the Euclidean distance is quantized using a preset Gaussian weight function to obtain the first weight of the target pixel. The preset Gaussian weight function is: , Indicates the first weight. This represents an exponential function with the natural constant as its base. This represents the Euclidean distance between the target pixel and any of the aforementioned pixels. This indicates the preset attenuation weight; Based on a preset size, target pixels and target windows for any pixel are constructed respectively. Pearson correlation coefficients are calculated based on the gray values in the two target windows. The Pearson correlation coefficients are then normalized to obtain the second weight of the target pixel. Obtain the first weight and the second weight of each target pixel in any local window, and obtain the weighted gray value variance of any local window based on the first weight and the second weight of each target pixel in any local window.
3. The method for detecting appearance defects in electricity meters based on machine vision according to claim 2, characterized in that, The step of obtaining the weighted grayscale variance of any local window based on the first weight and the second weight of each target pixel in any local window includes: The product of the first weight and the second weight of each target pixel in any local window is used as the final weight of each target pixel. The mean gray value of all target pixels is calculated. The squared difference between the gray value of each target pixel and the mean gray value is calculated. Based on the final weight of each target pixel, the squared differences are summed in a weighted manner to obtain a weighted sum. The ratio between the weighted sum and the number of all target pixels is used as the weighted gray value variance of any local window.
4. The method for detecting appearance defects in electricity meters based on machine vision according to claim 1, characterized in that, The weighted variance change function is: ; in, Indicate size The weighted variance of the grayscale values of the corresponding local window. Indicates the slope. Indicates the size of a local window. This represents the intercept.
5. The method for detecting appearance defects in electricity meters based on machine vision according to claim 1, characterized in that, The step of obtaining the adaptive Gaussian scale for each pixel when performing Gaussian filtering on the grayscale image based on the probability index of each pixel being affected by illumination interference includes: The pixels in the grayscale image are divided into a first type of pixel and a second type of pixel based on the probability index of each pixel being affected by illumination. The adaptive Gaussian scale of each first type of pixel is set to a preset basic Gaussian scale. For any second type of pixel, the adaptive Gaussian scale is obtained based on the probability index of any second type of pixel being affected by illumination.
6. The method for detecting appearance defects in electricity meters based on machine vision according to claim 5, characterized in that, The step of dividing the pixels in the grayscale image into a first category and a second category based on the probability index of each pixel being affected by illumination interference includes: Based on the probability index of each pixel in the grayscale image being affected by illumination, the probability index corresponding to the preset percentile of all probability indices is used as a threshold. Pixels with probability indices less than the threshold are classified as first-class pixels, and pixels with probability indices greater than or equal to the threshold are classified as second-class pixels.
7. The method for detecting appearance defects in electricity meters based on machine vision according to claim 6, characterized in that, The step of obtaining the adaptive Gaussian scale based on the probability index of any second-type pixel being affected by illumination interference includes: ; in, Indicates the first The adaptive Gaussian scale corresponding to each second type of pixel. This represents the preset scaling factor used to control Gaussian scale sensitivity. Represents the maximum value function. Indicates the first An indicator of the probability that a second type of pixel is affected by illumination interference. This represents the threshold value, where 0 represents a constant. This indicates the preset base Gaussian scale.
8. The method for detecting appearance defects in electricity meters based on machine vision according to claim 1, characterized in that, The step of obtaining the reflection component of the grayscale image based on an adaptive Gaussian scale for each pixel includes: Based on the adaptive Gaussian scale of each pixel, the grayscale image is subjected to Gaussian filtering to obtain the illumination component in the grayscale image. The illumination component is then removed to obtain the reflection component in the grayscale image.
9. The method for detecting appearance defects in electricity meters based on machine vision according to claim 1, characterized in that, The process of obtaining the defect entropy threshold includes: Acquire grayscale images of at least two electricity meters without visible defects, obtain the entropy values of the gradient histograms of the corresponding reflection components, form an entropy value set, obtain the mean and standard deviation of the entropy value set, and subtract three times the standard deviation from the mean as the defect entropy threshold.