Lens detection method and device, computer equipment and storage medium
By enhancing the brightness feature and analyzing the texture feature of the surveillance camera image, we can accurately determine whether the lens is dirty, which solves the problem of inaccurate detection of the lens in the prior art and improves the monitoring quality.
Patent Information
- Application Number
- CN202510237670.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-28
- Publication Date
- 2025-05-30
AI Technical Summary
In the prior art, the lens is inaccurately detected by dirty lenses and lack of effective solutions, resulting in a decrease in the picture clarity of the surveillance camera and affecting the monitoring quality.
By acquiring and enhancing the region of interest based on the brightness characteristics of the image, determining the texture feature image, calculating the difference in the texture feature value, and comparing the number of pixels with the preset number to determine whether the lens is dirty.
It improves the recognizability of dirty areas of the lens, and adaptively adjusts the texture feature difference value, improving the accuracy and applicability of lens detection.
Smart Images

Figure CN120070406A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing, and particularly to a lens detection method, apparatus, computer device, and storage medium. Background Art
[0002] Surveillance cameras are gradually spreading all over the streets and alleys. With the popularization of the surveillance and security system, the safety index of the living environment has become very high. When there are tens of thousands of cameras in a city, the lenses of the surveillance cameras installed outdoors are often covered with mud, muddy water, and dust over time, resulting in a deterioration of the picture clarity and thus affecting the surveillance quality. Manually inspecting and maintaining a large number of cameras regularly will consume a lot of manpower and material resources. How to accurately detect the lens and realize the maintenance of the surveillance system has become an urgent problem that needs attention.
[0003] Regarding the problem of inaccurate detection of lens dirt in the related art, no effective solution has been proposed yet. Summary of the Invention
[0004] Based on this, in view of the above technical problems, it is necessary to provide a lens detection method, apparatus, computer device, and storage medium that can solve the problem of inaccurate detection of lens dirt.
[0005] In a first aspect, in the present embodiment, a lens detection method is provided, and the method includes:
[0006] Obtain and enhance the region of interest in the first image according to the brightness feature of the first image;
[0007] Determine a first texture feature image based on the enhanced first image;
[0008] Calculate a first difference between the texture feature values of the first pixel and its neighboring pixels in the first texture feature image, and calculate a second difference between the maximum texture feature value and the minimum texture feature value in the first texture feature image;
[0009] In the first pixel of the first texture feature image, obtain a first number of pixels whose first difference is greater than the second difference;
[0010] Compare the first number with a preset second number, and determine whether the lens for obtaining the first image is dirty according to the comparison result.
[0011] In some of the embodiments, obtaining and enhancing the region of interest in the first image according to the brightness feature of the first image includes:
[0012] Obtain the weight matrix of each pixel in the first image according to the brightness feature in the first image;
[0013] Map the pixel values of the first image according to the cumulative distribution function of the first image, and adjust the pixel values of the mapped first image according to the weight matrix.
[0014] In some embodiments, obtaining the weight matrix of each pixel in the first image according to the brightness feature in the first image includes:
[0015] Obtain the brightness weight matrix of the first image according to the maximum gray value of the pixels of the first image in each color channel;
[0016] Obtain the texture matrix of the first image;
[0017] Perform normalization processing on the brightness weight matrix and the texture matrix to obtain the weight matrix.
[0018] In some embodiments, calculating a second difference between the maximum texture feature value and the minimum texture feature value in the first texture feature image includes:
[0019] Obtain a first parameter according to the degree of dirt estimated by the lens;
[0020] Adjust the difference between the maximum texture feature value and the minimum texture feature value in the first texture feature image based on the first parameter to obtain the second difference.
[0021] In some embodiments, comparing the first number with a preset second number and determining whether the lens for obtaining the first image is dirty according to the comparison result includes:
[0022] Obtain a second parameter according to the preset lens detection accuracy, and adjust the preset second number based on the second parameter;
[0023] Compare the first number with the second number;
[0024] When the first number is less than or equal to the second number, determine that the lens for obtaining the first image is dirty;
[0025] When the first number is greater than the second number, determine that the lens for obtaining the first image is not dirty.
[0026] In some embodiments, before comparing the first number with a preset second number and determining whether the lens for obtaining the first image is dirty according to the comparison result, the method further includes:
[0027] Obtain a second image captured by a lens without dirt; wherein, the shooting positions of the first image and the second image are the same;
[0028] Obtain and enhance the region of interest in the second image according to the brightness feature of the second image;
[0029] Determine a second texture feature image based on the enhanced second image;
[0030] Calculate a third difference between the texture feature values of a second pixel in the second texture feature image and its neighboring pixels, and calculate a fourth difference between the maximum texture feature value and the minimum texture feature value in the second texture feature image;
[0031] Obtain the second number according to the number of pixels in the second pixel of the second texture feature image for which the third difference is greater than the fourth difference.
[0032] In some of the embodiments, the neighboring pixels of the first pixel include at least one of the following: the pixels in the row direction of the first pixel, the pixels in the column direction of the first pixel, the pixels in the row and column directions of the first pixel, and the pixels surrounding the first pixel within a specified range.
[0033] In a second aspect, a lens detection device is provided in this embodiment. The device includes:
[0034] A first processing module, configured to obtain and enhance the region of interest in the first image according to the brightness feature of the first image;
[0035] A second processing module, configured to determine a first texture feature image based on the enhanced first image;
[0036] A difference obtaining module, configured to calculate a first difference between the texture feature values of a first pixel in the first texture feature image and its neighboring pixels, and calculate a second difference between the maximum texture feature value and the minimum texture feature value in the first texture feature image;
[0037] A pixel obtaining module, configured to obtain a first number of pixels in the first pixel of the texture feature image for which the first difference is greater than the second difference;
[0038] A judgment module, configured to compare the first number with a preset second number, and judge whether the lens for obtaining the first image is dirty according to the comparison result.
[0039] In a third aspect, a computer device is provided in this embodiment, including a memory and a processor. The memory stores a computer program, and when the processor executes the computer program, the lens detection method described in the first aspect above is implemented.
[0040] Fourthly, in this embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the lens detection method described in the first aspect above is implemented.
[0041] In the above lens detection method, device, computer device and storage medium, by enhancing the region of interest of the first image through the brightness feature of the first image, the influence of the lens dirt region on the brightness and texture of the first image obtained by the lens can be highlighted, thereby improving the recognizability of the region corresponding to the lens dirt in the first image; the second difference is obtained according to the maximum texture feature value and the minimum texture feature value in the first texture feature image of the first image, so as to adaptively adjust the second difference according to the first image texture feature, improving the applicability of the lens detection method; the first number of pixels in the first texture feature image that may correspond to the lens dirt is captured through the first difference and the second difference, and based on the first number, it can be accurately recognized whether there is an impact on the image texture feature due to lens dirt when shooting the first image, ultimately improving the accuracy of lens dirt detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 It is an application environment diagram of the lens detection method in an embodiment of the present application;
[0043] Figure 2 It is a flowchart of the lens detection method in an embodiment of the present application;
[0044] Figure 3 It is a flowchart of the lens detection method in another embodiment of the present application;
[0045] Figure 4 It is a structural block diagram of the lens detection device in an embodiment of the present application;
[0046] Figure 5 It is an internal structure diagram of the computer device in an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0047] In order to make the objectives, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0048] The lens detection method provided by the embodiments of the present application can be applied as Figure 1In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or can be placed in the cloud or on other network servers. The first image captured by the lens is obtained through the terminal 102 or a system including the terminal and the server, and lens detection is implemented based on the first image. Among them, the terminal 102 can be, but is not limited to, various personal computers, laptops, smartphones, Internet of Things camera devices, etc. The server 104 can be implemented by an independent server or a server cluster composed of multiple servers.
[0049] In one embodiment, as Figure 2 shown, a lens detection method is provided. Taking the terminal in Figure 1 as an example, the method includes the following steps:
[0050] Step S202, obtain and enhance the region of interest in the first image according to the brightness feature of the first image.
[0051] Among them, the brightness feature includes, but is not limited to, one or more of the following features: the brightness distribution uniformity of the first image, brightness gradient, contrast, etc. Optionally, the brightness distribution in the first image can be determined according to the texture feature value of the pixels in the first image to obtain the brightness feature.
[0052] The region of interest in the first image includes the region where dirt may exist. Optionally, after obtaining the brightness feature of the first image, weights can be assigned to each pixel in the first image, and the region of interest in the first image can be determined based on the pixel weights. Or, edge detection can also be performed based on the brightness feature of the first image, and the region of interest can be determined based on the edge detection result. Or, threshold segmentation can also be performed based on the brightness feature of the first image, and the region in the first image where the texture feature value is greater than the specified threshold is determined as the region of interest. Among them, the enhancement of the region of interest can be achieved by increasing the contrast of the region of interest. The methods for increasing the contrast include, but are not limited to, linear mapping of the brightness value of the region of interest, filtering, histogram equalization, etc. Or, the enhancement of the region of interest can also be achieved by filtering, edge enhancement, etc. By enhancing the region of interest, the recognizability of the region corresponding to the lens dirt in the first image can be improved.
[0053] Step S204, determine the first texture feature image based on the enhanced first image.
[0054] Among them, the texture feature of the enhanced first image can be obtained through texture calculation methods such as filters and gray-level co-occurrence matrices to obtain the first texture feature image.
[0055] Step S206: Calculate the first difference between the texture feature values of the first pixel and its neighboring pixels in the first texture feature image, and calculate the second difference between the maximum texture feature value and the minimum texture feature value in the first texture feature image.
[0056] Herein, the first texture feature value and the second texture feature value are the pixel values of each pixel in the first texture feature image. Optionally, traverse the pixels of the first texture feature value, and use the currently traversed pixel as the first pixel. The neighboring pixels are the other pixels in the first texture feature image except the first pixel, and the neighboring pixels are around the first pixel.
[0057] Optionally, obtain the first texture feature value of the first pixel in the first texture feature image, and obtain the second texture feature values of the neighboring pixels of the first pixel. In the case of obtaining the second texture feature values of multiple neighboring pixels, the multiple second texture feature values can be integrated first, and then based on the integrated second texture feature value and the first texture feature value, the first difference is obtained. Herein, when calculating the first difference, the difference between the first texture feature value and the second texture feature value can be used as the first difference; alternatively, the first difference can be obtained by calculating methods such as the square difference or the normalized difference between the first texture feature value and the second texture feature value. Optionally, when the first texture feature image is a color image, the differences between the second texture feature value components of each color channel with respect to the first texture feature value components of the corresponding channels can be calculated respectively, and one or more color channel components can be selected for combination according to user requirements to obtain the first difference.
[0058] Optionally, obtain the texture feature values of all pixels in the first texture feature image, and obtain the maximum texture feature value and the minimum texture feature value therein. Based on the same calculation method of the first difference, the second difference is calculated.
[0059] Step S208: In the first pixel of the first texture feature image, obtain the first number of pixels for which the first difference is greater than the second difference.
[0060] Herein, the first difference being greater than the second difference indicates that the corresponding first pixel is located in a region with a relatively large texture change in the texture feature space of the first image, and the region with a relatively large texture change may be a lens dirty region, because lens dirt will cause the first difference of the first pixel to be greater than the second difference. Optionally, traverse the pixels in the first texture feature image, and in the case where it is determined that the first difference corresponding to the currently traversed pixel (the first pixel) is greater than the second difference, use the currently traversed pixel as the first pixel for which the first difference is greater than the second difference. After all pixels in the first texture feature image have been traversed, the first number is obtained.
[0061] Step S210: Compare the first number with a preset second number, and determine whether the lens for obtaining the first image is dirty according to the comparison result.
[0062] Among them, the larger the second number is, the looser the judgment criterion for whether the lens for shooting the first image is dirty; the smaller the second number is, the stricter the judgment criterion for whether the lens for shooting the first image is dirty. Optionally, a judgment criterion for whether the lens for obtaining the first image is dirty can be preset, and the second number can be set correspondingly according to the strictness of the judgment criterion. When the first number is greater than or equal to the second number, it is determined that the lens for obtaining the first image is dirty; when the first number is less than the second number, it is determined that the lens for obtaining the first image is not dirty.
[0063] In the above lens detection method, the first image is preprocessed according to the brightness feature of the image to enhance the region of interest in the first image, improving the recognizability when judging whether the lens for shooting the first image is dirty; according to the maximum texture feature value and the minimum texture feature value in the first texture feature image of the enhanced first image, the second difference used to judge whether a pixel corresponds to a dirty part of the lens is adaptively obtained. Capture the first number of pixels in the first image that may correspond to the dirty part of the lens according to the first difference and the second difference between the pixels in the first texture feature image, and determine whether the lens for shooting the first image is dirty by comparing the first number with the preset second number, realizing data quantization processing; ultimately improving the accuracy of lens dirt detection.
[0064] In one embodiment, obtaining and enhancing the region of interest in the first image according to the brightness feature of the first image includes: obtaining the weight matrix of each pixel in the first image according to the brightness feature in the first image; mapping the pixel values of the first image according to the cumulative distribution function of the first image, and adjusting the pixel values of the mapped first image according to the weight matrix.
[0065] Optionally, according to the brightness feature of the first image, higher weights are assigned to the pixels in the uneven brightness region of the first image, and smaller weights are assigned to the other pixels in the first image, obtaining the weight matrix corresponding to each pixel of the first image.
[0066] Among them, the cumulative distribution function is used to describe the possibility of the gray level corresponding to the gray value of each pixel in the first image being less than or equal to a specified gray level. Optionally, a specified gray level is predefined, and the probability that the pixel gray value of each pixel in the first image is less than or equal to the specified gray level is accumulated to obtain the cumulative distribution function. While mapping the pixel values in the original first image through the cumulative distribution function, the size of each pixel value is adjusted according to the weight matrix, and the preprocessed first image is obtained according to the adjusted pixels.
[0067] In this embodiment, by adjusting the pixel values through the cumulative distribution function and the weight matrix, the distribution of the pixel values in the first image can be improved, the regions with larger weights can be enhanced, the recognizable details in the first image can be increased, which helps to improve the accuracy of lens detection.
[0068] Further, in one embodiment, obtaining the weight matrix of each pixel in the first image according to the brightness feature in the first image includes: obtaining the brightness weight matrix of the first image according to the maximum gray value of the pixels in the first image in each color channel; obtaining the texture matrix of the first image; performing normalization processing on the brightness weight matrix and the texture matrix to obtain the weight matrix.
[0069] Among them, the texture matrix is used to describe the texture feature in the first image. The texture matrix of the first image can be the gray-level co-occurrence matrix of the image; or, after detecting the texture with specific frequencies and directions in the image through a filter, obtaining the texture matrix according to the filtering result; or, identifying the edges in the first image through the Canny operator and constructing the texture matrix according to the edge information.
[0070] The brightness weight matrix is used to describe the brightness information of each pixel in the first image. Optionally, the gray values of the pixel in multiple color channels can be obtained respectively, the magnitudes of the multiple gray values can be compared to obtain the maximum gray value of the pixel. Taking the maximum gray values of each pixel in multiple color channels as the gray values of each pixel in the first image, and constructing the brightness weight matrix according to the replaced pixel gray values and pixel positions. By obtaining the brightness weight matrix, the brightest region in the first image can be highlighted and the contrast of the first image can be enhanced.
[0071] Optionally, the normalization processing of the brightness weight matrix and the texture matrix can be realized by means such as min-max normalization, Z-score standardization, and maximum absolute value normalization.
[0072] In this embodiment, the brightness weight matrix is obtained through the maximum gray value of the pixel in each color channel, the brightest information in the first image is retained, and at the same time, the overall contrast of the image is enhanced. By normalizing and calculating the brightness weight matrix and the texture matrix, the regions with uneven brightness in the image texture can be highlighted through the brightness feature of the image, and the enhancement of the region of interest can be realized.
[0073] In one embodiment, calculating the second difference between the maximum texture feature value and the minimum texture feature value in the first texture feature image includes: obtaining the first parameter according to the estimated dirt degree of the lens; adjusting the difference between the maximum texture feature value and the minimum texture feature value in the first texture feature image based on the first parameter to obtain the second difference.
[0074] Among them, the degree of lens contamination can be estimated based on the environment where the lens is located, the installation position of the lens, and the installation duration. When the lens is installed in an area with a lot of dust and mud, it is estimated that the lens has a high degree of contamination; on the contrary, it is estimated that the lens has a relatively low degree of contamination. The first parameter can also be called a scale parameter, which is used to adjust the judgment scale of the first pixel: the longer the lens installation duration, the higher the estimated degree of lens contamination, and the first parameter is set to increase the second difference; the shorter the lens installation duration, the lower the estimated degree of lens contamination, and the first parameter is set to decrease the second difference. Specifically, when the first parameter is positively correlated with the second difference, the higher the estimated degree of lens contamination, the larger the corresponding first parameter; the lower the estimated degree of lens contamination, the smaller the corresponding first parameter. Similarly, in the case where the first parameter is negatively correlated with the second difference, it will not be elaborated. Optionally, the first parameter can be used as a scaling factor, and the first difference can be adjusted by linear scaling. The first parameter can also be used as a scaling factor in logarithmic scaling or exponential scaling to adjust the first difference to obtain the second parameter.
[0075] In this embodiment, by introducing the first parameter related to the estimated degree of lens contamination, adjusting the second difference, and changing the sensitivity when judging the first pixel whose first difference is greater than the second difference, the lens contamination detection requirements in different contamination states can be met.
[0076] In one embodiment, comparing the first number with a preset second number and judging whether the lens for obtaining the first image is contaminated according to the comparison result includes: obtaining a second parameter according to the preset lens detection accuracy and adjusting the preset second number based on the second parameter; comparing the first number and the second number; when the first number is less than or equal to the second number, judging that the lens for obtaining the first image is contaminated; when the first number is greater than the second number, judging that the lens for obtaining the first image is not contaminated.
[0077] Among them, when the preset lens detection accuracy is high, the second parameter needs to be set correspondingly so that the adjusted second number is small; when the preset lens detection accuracy is high, the second parameter needs to be set correspondingly so that the adjusted second number is large. Optionally, the second parameter can be set as a scaling factor based on methods such as linear scaling and logarithmic scaling to achieve the adjustment of the second number.
[0078] In this embodiment, by adjusting the second number with the second parameter, changing the judgment threshold when judging whether the lens is contaminated, to adapt to lens detection under various accuracy requirements, and improving the applicability of the lens detection method.
[0079] In one embodiment, before comparing the first number with a preset second number and determining whether the lens for obtaining the first image is dirty according to the comparison result, the method further includes: obtaining a second image captured by a lens without dirt; wherein, the shooting positions of the first image and the second image are the same; obtaining and enhancing the region of interest in the second image according to the brightness feature of the second image; determining a second texture feature image based on the enhanced second image; calculating a third difference between the texture feature values of the second pixels and their neighboring pixels in the second texture feature image, and calculating a fourth difference between the maximum texture feature value and the minimum texture feature value in the second texture feature image; obtaining the second number according to the number of pixels in the second pixels of the second texture feature image for which the third difference is greater than the fourth difference.
[0080] Wherein, the shooting positions of the first image and the second image are the same. Therefore, the corresponding shooting positions and shooting objects of the two are the same. The region of interest in the second image is the region with uneven brightness. The change in the brightness feature within the region of interest in the second image is caused jointly by the characteristics of the lens and the shooting position itself, rather than by lens dirt. Optionally, the brightness distribution in the second image can be determined according to the texture feature values of the pixels in the second image to obtain the brightness feature of the second image. The brightness feature of the second image includes, but is not limited to, one or more of the following features: the brightness distribution uniformity of the first image, brightness gradient, contrast, etc. After obtaining the brightness feature of the second image, weights can be assigned to each pixel in the second image, and the region of interest in the second image can be determined based on the pixel weights. Alternatively, based on the brightness feature of the second image, edge detection or threshold segmentation can be performed on the second image to further determine the region of interest in the second image. Optionally, the enhancement of the region of interest in the second image can be achieved by increasing the contrast, filtering, edge enhancement, etc. of the region of interest.
[0081] Wherein, the texture feature of the second image can be obtained by means of a filter, gray-level co-occurrence matrix, etc. to obtain the second texture feature image. Optionally, obtain the third texture feature value of the second pixel in the second texture feature image and the fourth texture feature value of the neighboring pixels of the second pixel. Wherein, the absolute difference, square difference, and normalized difference between the third texture feature value and the fourth texture feature value can be used as the third difference. Optionally, obtain the texture feature values of all pixels in the second texture feature image to obtain the maximum texture feature value and the minimum texture feature value therein. Based on the same calculation method as the third difference, calculate the fourth difference between the maximum texture feature value and the minimum texture feature value.
[0082] In this embodiment, obtaining the second number from the second image captured when the lens is clean can achieve the effect of adaptively adjusting the second number according to the characteristics of different lenses themselves to improve the robustness of lens detection.
[0083] In one embodiment, the neighboring pixels of the first pixel include at least one of the following: the pixels in the row direction of the first pixel, the pixels in the column direction of the first pixel, the pixels in the row and column directions of the first pixel, and the pixels surrounding the first pixel within a specified range. Among them, the neighboring pixels can be a set of one or more pixels. The specified range can be a regular area such as a square or a circle, or an irregular area. Optionally, the neighboring pixels can be the pixels within an n×n range centered on the first pixel, where n is a positive integer. It can be understood that the neighboring pixels of the first pixel can be selected according to requirements.
[0084] In one embodiment, the neighboring pixels of the second pixel can also include at least one of the following: the pixels in the row direction of the first pixel, the pixels in the column direction of the first pixel, the pixels in the row and column directions of the first pixel, and the pixels surrounding the first pixel within a specified range.
[0085] In this embodiment, by selecting different neighboring pixels, local pixel information of different scales can be captured according to requirements, the influence of noise on the texture feature values can be reduced, and the accuracy of the obtained texture feature values can be increased.
[0086] In one embodiment, considering that if there is dirt on the lens of a surveillance camera, the dirt often manifests as the loss of detailed texture and high-frequency information in the captured image. Figure 3 A flowchart of another lens detection method is given, as Figure 3 shown. By obtaining the clean background frame image registered when the camera is installed and the current frame image captured by the current lens, comparing the texture features between the current frame image and the background frame image, and capturing the differences in the texture features, it is determined whether there is dirt.
[0087] The current frame image is the first image in the above embodiment. To improve the accuracy of the texture features of the first image (current frame image), after obtaining the first image, image preprocessing can be performed on the first image, and the image preprocessing operations are as follows.
[0088] Calculate the luminance weight matrix W bright :
[0089]
[0090] where J represents the pixel value of the pixels in the first image, y represents the pixels obtained by traversing the entire image, and c is the channel traversed in the first image. For easy understanding, taking the first image as an RGB image as an example, for each pixel in the first image, the maximum value of the pixel in the RGB channels is selected, and a grayscale image corresponding to the first image is formed based on the selected maximum values; subsequently, a maximum filter is performed on the grayscale image of the first image to obtain the luminance weight matrix.
[0091] Perform Canny edge detection on the first image to obtain the texture features in the first image, and obtain the texture matrix of the first image based on the texture features in the first image. Perform normalization calculation according to the texture matrix and the brightness weight matrix to obtain matrix W:
[0092] T = W bright ×canny
[0093]
[0094] Perform weighted image histogram equalization based on matrix W, including: statistically calculating the grayscale histogram of the first image; calculating the cumulative distribution function (CDF) of the first image according to the grayscale histogram of the first image. Among them, the cumulative distribution function represents the sum of the number of pixels from grayscale level 0 to the current grayscale level of all pixels in the first image. Specifically, for each pixel with a grayscale level of i, the value of the CDF corresponding to this pixel is equal to the sum of the number of all pixels less than or equal to grayscale level i in the image.
[0095] Assume that the current pixel value is x. Based on the cumulative distribution function and matrix W, the new pixel value new_x of the current pixel x can be calculated, and the formula is as follows:
[0096] new_x = round(255 * CDF(x) * W(x))
[0097] Replace the original value x of all pixels in the first image with the new pixel value new_x to obtain the first image after weighted equalization.
[0098] Among them, the first image after weighted equalization is the first image after enhancing the region of interest based on the brightness feature. Since the presence of stains on the lens will directly cause local differences in the light entering the lens during imaging, therefore, by using pixel brightness as an auxiliary term to highlight the texture of the area where the stain is located on the lens, the features of the region with uneven brightness in the first image can be highlighted, improving the accuracy effect of lens detection.
[0099] On the basis of obtaining the preprocessed first image, calculate the Sobel texture to obtain the Sobel texture map, that is, the first texture feature image of the first image. After obtaining the Sobel texture map, traverse each pixel point and calculate the average difference between the first texture feature value of each pixel point (the first pixel) and the second texture feature values of the surrounding 5 * 5 neighborhood pixels, that is, the first difference. In order to evaluate whether the first pixel is a texture maximum point in the first texture feature image, obtain the second difference.
[0100] Optionally, denote the first difference as α, and the calculation formula of the second difference ε is as follows:
[0101] ε = β * (max(sobel) - min(sobel))
[0102] Among them, sobel is the first texture feature image, max(sobel) is the maximum texture feature value in the first texture feature image, and min(sobel) is the minimum texture feature value in the first texture feature image. β is the first parameter, and β can be set manually according to requirements. Optionally, β is set to 0.2 and can be adjusted according to specific usage scenarios.
[0103] Pixels with the first difference greater than or equal to the second difference are marked as maximum value points, and the first number of maximum value points in the first image is denoted as p cur . To determine whether there is lens dirt, compare the number p of maximum value points in the background frame image (the second image) background and the number p of maximum value points in the current frame image (the first image) cur , when p cur ≤ p background *γ, it indicates that there is a lens dirt phenomenon in the current frame image (the first image); when p cur > p background *γ, it indicates that there is a lens dirt phenomenon in the current frame image (the first image). Among them, γ is the second parameter. Optionally, β is set to 0.8 and can be adjusted according to specific usage scenarios.
[0104] In this embodiment, by combining the brightness feature and texture feature of the first image, equalization weighting processing is performed on the first image, highlighting the texture related to lens dirt in the first image; by obtaining the texture maximum value points for dirt judgment of the first image, the subtle images caused by dirt in the first image can be accurately captured, enhancing the robustness and accuracy of lens detection.
[0105] Based on the same inventive concept, an embodiment of the present application also provides a lens detection device for implementing the above-mentioned lens detection method. The implementation solution provided by this device to solve the problem is similar to the implementation solution described in the above method. Therefore, the specific limitations in one or more embodiments of the lens detection device provided below can refer to the limitations on the lens detection method in the above text and will not be elaborated here.
[0106] In one embodiment, as Figure 4 shown, a lens detection device is provided, including: a first processing module, a second processing module, a difference acquisition module, a pixel acquisition module, and a judgment module, where:
[0107] The first processing module is used to obtain and enhance the region of interest in the first image according to the brightness feature of the first image;
[0108] A second processing module, configured to determine a first texture feature image based on the enhanced first image;
[0109] A difference obtaining module, configured to calculate a first difference between the texture feature values of a first pixel and its neighboring pixels in the first texture feature image, and calculate a second difference between the maximum texture feature value and the minimum texture feature value in the first texture feature image;
[0110] A pixel obtaining module, configured to obtain a first number of pixels in the first pixel of the texture feature image, where the first difference of these pixels is greater than the second difference;
[0111] A judgment module, configured to compare the first number with a preset second number, and determine whether the lens for obtaining the first image is dirty according to the comparison result.
[0112] Optionally, the neighboring pixels of the first pixel include at least one of the following: pixels in the row direction of the first pixel, pixels in the column direction of the first pixel, pixels in the row and column directions of the first pixel, and pixels surrounding the first pixel within a specified range.
[0113] In one embodiment, the first processing module obtains and enhances the region of interest in the first image according to the brightness feature of the first image, including: obtaining a weight matrix of each pixel in the first image according to the brightness feature in the first image; mapping the pixel values of the first image according to the cumulative distribution function of the first image, and adjusting the pixel values of the mapped first image according to the weight matrix. Optionally, obtaining a weight matrix of each pixel in the first image according to the brightness feature in the first image includes: obtaining a brightness weight matrix of the first image according to the maximum gray value of the pixels in the first image in each color channel; obtaining the texture matrix of the first image; performing normalization processing on the brightness weight matrix and the texture matrix to obtain the weight matrix.
[0114] In one embodiment, the difference obtaining module calculates the second difference between the maximum texture feature value and the minimum texture feature value in the first texture feature image, including: obtaining a first parameter according to the estimated degree of dirt of the lens; adjusting the difference between the maximum texture feature value and the minimum texture feature value in the first texture feature image according to the first parameter to obtain the second difference.
[0115] In one embodiment, the judgment module compares the first number with a preset second number, and determines whether the lens for obtaining the first image is dirty according to the comparison result, including: obtaining a second parameter according to the preset lens detection accuracy, and adjusting the preset second number based on the second parameter; comparing the first number with the second number; in the case where the first number is less than or equal to the second number, determining that the lens for obtaining the first image is dirty; in the case where the first number is greater than the second number, determining that the lens for obtaining the first image is not dirty.
[0116] Optionally, before comparing the first number with a preset second number and determining whether the lens for obtaining the first image is dirty according to the comparison result, the method further includes: obtaining a second image captured by a lens without dirt; wherein, the shooting positions of the first image and the second image are the same; obtaining and enhancing the region of interest in the second image according to the brightness feature of the second image; determining a second texture feature image based on the enhanced second image; calculating a third difference between the texture feature values of the second pixel and its neighboring pixels in the second texture feature image, and calculating a fourth difference between the maximum texture feature value and the minimum texture feature value in the second texture feature image; obtaining the second number according to the number of pixels in the second pixel of the second texture feature image for which the third difference is greater than the fourth difference.
[0117] Optionally, the neighboring pixels of the second pixel include at least one of the following: pixels in the row direction of the first pixel, pixels in the column direction of the first pixel, pixels in the row and column directions of the first pixel, and pixels surrounding the first pixel within a specified range.
[0118] Each module in the above lens detection device can be implemented in whole or in part by software, hardware, and their combination. The above modules can be embedded in the processor of the computer device in hardware form or be independent of it, or can be stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to the above respective modules.
[0119] In one embodiment, a computer device is provided. The computer device can be a terminal, and its internal structure diagram can be as Figure 5 shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit, and an input device. Among them, the processor, the memory, and the input / output interface are connected through a system bus, and the communication interface and the display unit are connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used for the processor to exchange information with external devices. The communication interface of the computer device is used to communicate with external terminals in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (Near Field Communication), or other technologies. The computer program, when executed by the processor, implements a lens detection method. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device, etc.
[0120] Those skilled in the art can understand, Figure 5The structure shown is only a block diagram of some structures related to the solution of this application, and does not constitute a limitation on the computer device to which the solution of this application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.
[0121] In one embodiment, a computer device is further provided, including a memory and a processor. A computer program is stored in the memory, and when the processor executes the computer program, the steps in the above method embodiments are implemented.
[0122] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the steps in the above method embodiments are implemented.
[0123] In one embodiment, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in the above method embodiments are implemented.
[0124] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, database, or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memories. Non-volatile memories can include read-only memory (ROM), magnetic tapes, floppy disks, flash memories, optical memories, high-density embedded non-volatile memories, resistive random access memories (ReRAM), magnetoresistive random access memories (MRAM), ferroelectric random access memories (FRAM), phase change memories (PCM), graphene memories, etc. Volatile memories can include random access memory (RAM) or external cache memories, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The databases involved in the embodiments provided in the present application can include at least one of relational databases and non-relational databases. Non-relational databases can include distributed databases based on blockchain, etc., without limitation. The processors involved in the embodiments provided in the present application can be general-purpose processors, central processors, graphics processors, digital signal processors, programmable logic devices, data processing logics based on quantum computing, etc., without limitation.
[0125] The technical features of the above embodiments can be combined arbitrarily. For the sake of concise description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope described in this specification.
[0126] The above-described embodiments only represent several implementation manners of the present application. The description is relatively specific and detailed, but it should not be construed as a limitation on the patent scope of the present application. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.
Claims
1. A lens detection method, characterized in that: The method comprises: Acquire and enhance a region of interest in the first image according to a brightness feature of the first image; Determine a first texture feature image based on the enhanced first image; Calculating a first difference in texture feature values between a first pixel and its neighboring pixels in the first texture feature image, and calculating a second difference between a maximum texture feature value and a minimum texture feature value in the first texture feature image; In a first pixel of the first texture feature image, obtaining a first number of pixels where the first difference is greater than the second difference; The first number is compared with a preset second number, and it is determined whether a lens used to acquire the first image is dirty according to the comparison result.
2. The lens detection method according to claim 1, characterized in that: Acquiring and enhancing a region of interest in the first image according to a brightness feature of the first image includes: Obtaining a weight matrix for each pixel in the first image according to a brightness feature in the first image; The pixel values of the first image are mapped according to the cumulative distribution function of the first image, and the pixel values of the mapped first image are adjusted according to the weight matrix.
3. The lens detection method according to claim 2, characterized in that: The step of obtaining a weight matrix of each pixel in the first image according to the brightness feature in the first image includes: Obtaining a brightness weight matrix of the first image according to the maximum grayscale value of the pixels of the first image in each color channel; Obtaining a texture matrix of the first image; The brightness weight matrix and the texture matrix are normalized to obtain the weight matrix.
4. The lens detection method according to claim 1, characterized in that: Calculating a second difference between a maximum texture feature value and a minimum texture feature value in the first texture feature image comprises: Obtaining a first parameter according to the estimated degree of dirtiness of the lens; The difference between the maximum texture feature value and the minimum texture feature value in the first texture feature image is adjusted based on the first parameter to obtain the second difference.
5. The lens detection method according to claim 1, characterized in that: Comparing the first number with a preset second number, and judging whether a lens used to acquire the first image is dirty according to the comparison result, includes: Obtaining a second parameter according to a preset lens detection accuracy, and adjusting the preset second number based on the second parameter; comparing the first number and the second number; When the first number is less than or equal to the second number, it is determined that a lens for acquiring the first image is dirty; When the first number is greater than the second number, it is determined that a lens for acquiring the first image is not dirty.
6. The lens detection method according to claim 1 or 5, characterized in that: Before comparing the first number with a preset second number and determining whether a lens used to acquire the first image is dirty according to the comparison result, the method further includes: Acquire a second image captured by a lens without dirt; wherein the first image and the second image are captured at the same point; Acquire and enhance a region of interest in the second image according to a brightness feature of the second image; determining a second texture feature image based on the enhanced second image; Calculating a third difference in texture feature values between a second pixel and its neighboring pixels in the second texture feature image, and calculating a fourth difference between a maximum texture feature value and a minimum texture feature value in the second texture feature image; The second number is obtained according to the number of pixels in the second pixels of the second texture feature image whose third difference is greater than the fourth difference.
7. The lens detection method according to claim 1, characterized in that: The neighborhood pixels of the first pixel include at least one of the following: pixels in the row direction of the first pixel, pixels in the column direction of the first pixel, pixels in the row and column directions of the first pixel, and pixels surrounding the first pixel within a specified range.
8. A lens detection device, characterized in that: The device comprises: A first processing module, configured to acquire and enhance a region of interest in the first image according to a brightness feature of the first image; A second processing module, configured to determine a first texture feature image based on the enhanced first image; a difference acquisition module, used to calculate a first difference in texture feature values between a first pixel and its neighboring pixels in the first texture feature image, and to calculate a second difference between a maximum texture feature value and a minimum texture feature value in the first texture feature image; A pixel acquisition module, configured to acquire, in a first pixel of the texture feature image, a first number of pixels where the first difference is greater than the second difference; The judgment module is used to compare the first number with a preset second number, and judge whether the lens used to obtain the first image is dirty according to the comparison result.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.