Image processing method and system for power grid identification
Through YOLO object detection and multi-scale gradient calculation, combined with similarity calculation, the problem of low image recognition accuracy in power grids is solved, and efficient and accurate equipment recognition and defect detection are achieved in complex environments.
Patent Information
- Application Number
- CN202410580296.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-11
- Publication Date
- 2024-11-19
- Estimated Expiration
- 2044-05-11
AI Technical Summary
The existing power grid image recognition technology has low recognition accuracy under the influence of light, angle and occlusion, especially the NCC algorithm is sensitive to geometric transformation and lighting changes, resulting in a decrease in matching accuracy.
The YOLO object detection algorithm is used to combine multi-scale gradient calculation and weighted quantization to extract equipment features, and determine whether there are defects in the image through similarity calculation. The weighted average method is used to fuse local similarity to calculate the global similarity, which improves recognition accuracy and robustness.
It realizes rapid and accurate identification and defect detection of power grid equipment, improves identification efficiency and accuracy, enhances feature representation capabilities, and maintains high accuracy in complex environments.
Smart Images

Figure CN118506067B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of power grid technology, and in particular to an image processing method and system for power grid identification. Background Art
[0002] In recent years, with the rapid development of computer vision and artificial intelligence technology, the use of image processing and pattern recognition methods to achieve automatic inspection and status diagnosis of power grid equipment has attracted widespread attention. By collecting image data of power grid equipment and using image processing algorithms to analyze and identify it, it is possible to automatically detect equipment defects, evaluate equipment health status, and provide decision support for power grid operation and maintenance.
[0003] However, due to the complex and changeable power grid environment, the wide variety of equipment, and the uneven image quality, the existing power grid image recognition technology generally has the problem of low recognition accuracy. Traditional image recognition methods mainly use feature extraction and classifier design, which have high requirements on the quality of image data and the generalization ability of the algorithm. In practical applications, they are easily affected by factors such as lighting, angle, and occlusion, resulting in reduced recognition accuracy.
[0004] In the related art, for example, Chinese patent document CN114155189A provides a method for fast analysis of distribution network defect images based on NCC image matching algorithm, which relates to the field of distribution network technology. The method includes classifying standard distribution network images to construct a recognition database; using image recognition algorithm to identify the equipment to be analyzed in the real-time distribution network graphics and standardize them, and obtaining the corresponding standard distribution network image according to the identified equipment to be analyzed; using NCC image matching algorithm to match the marked real-time distribution network image with the corresponding standard distribution network image. When the output NCC image has a mark, the real-time distribution network image is a distribution network defect image, and the equipment to be analyzed in the real-time distribution network image is a defective equipment. Otherwise, the equipment in the real-time distribution network image is a normal equipment. However, in this scheme, the NCC algorithm is sensitive to geometric transformations (such as translation, rotation, scaling, etc.) and illumination changes of the image. When these changes exist between the real-time distribution network image and the standard image, the matching accuracy of the NCC algorithm will be significantly reduced. Summary of the invention
[0005] 1. Technical issues to be solved
[0006] In response to the problem of low power grid image recognition accuracy in the prior art, the present application provides an image processing method and system for power grid recognition, which improves the equipment recognition accuracy by calculating the similarity between the image to be detected and the standard image, judging whether the image to be detected has defects, etc.
[0007] 2. Technical solution
[0008] The purpose of this application is achieved through the following technical solutions.
[0009] One aspect of the present specification provides an image processing method for power grid identification. First, power grid image data is collected, and the collected image data is input into an image preprocessing module to preprocess the image data to obtain preprocessed image data. Then, the preprocessed image data is input into a feature extraction module, and the device features in the image data are extracted according to the preprocessed image data to obtain extracted device features. Next, the extracted device features are input into a target detection module, and the preprocessed image data is subjected to target detection using a YOLO target detection algorithm to obtain a target detection result, and the target detection result includes the detected device. Subsequently, the target detection result is input into a device marking module to mark the detected device to obtain a marked device. According to the marked device, a corresponding standard image is selected from a standard distribution network image database, and the preprocessed image data is used as an image to be detected. Next, the image to be detected and the selected standard image are input into a similarity calculation module, and the similarity between the image to be detected and the standard image is calculated to obtain a similarity calculation result. Then, the similarity calculation result is input into a defect judgment module, and according to the similarity calculation result, it is judged whether the image to be detected has defects to obtain a judgment result. If the judgment result is that the image to be detected has defects, the image to be detected is input into the defect area acquisition module to obtain the defect area. Finally, the acquired defect area and the collected power grid image data are input into the defect visualization module, the acquired defect area is marked on the collected power grid image data, and the defect visualization result is generated.
[0010] Furthermore, for extracting device features from image data based on preprocessed image data, first, the preprocessed image data is divided into multiple data blocks to obtain multiple data blocks. Then, multi-scale gradient calculation is performed on each data block, specifically including: for each data block, different scale parameters are selected, such as 1, 2, 4, etc., and the data block is downsampled to obtain data blocks at different scales; for each data block at each scale, the gradients in the horizontal and vertical directions are calculated respectively, and the gradient calculation can be performed using the Sobel operator, Prewitt operator or Scharr operator; according to the gradients in the horizontal and vertical directions, the gradient amplitude and gradient direction of each pixel are calculated, and the gradient amplitude can be calculated using the square root of the sum of the squares of the horizontal and vertical gradients, and the gradient direction can be calculated using the inverse tangent function; the gradient amplitude and gradient direction at each scale are used as the gradient features of the data block at that scale. Through multi-scale gradient calculation, the gradient direction and gradient amplitude of each data block at different scales are obtained. The gradient direction and gradient amplitude of each data block at different scales are processed: the gradient direction of each data block at different scales is weighted quantized, the angle range from 0 to 360 degrees is divided into multiple intervals, such as 8 intervals, each gradient direction is quantized, and it is classified into the nearest interval to obtain the quantized gradient direction; each quantized gradient direction is weighted according to its corresponding gradient amplitude, and the gradient amplitudes in the same interval are accumulated to obtain the weighted gradient amplitude of the interval; the weighted gradient amplitudes of different intervals are combined into a histogram as the weighted gradient direction histogram of the data block at this scale. Through weighted quantization, the weighted gradient direction histogram of each data block at different scales is obtained. Then, the weighted gradient direction histogram of each data block at different scales is connected in series to obtain the multi-scale direction histogram of each data block, that is, the histograms at different scales are connected end to end to form a long vector. Finally, the multi-scale direction histograms of all data blocks are combined into a feature vector as the device feature in the preprocessed image data. Specifically, the multi-scale directional histograms of all data blocks can be arranged in a certain order, such as from left to right and from top to bottom according to the position of the data blocks, to form a large feature vector. Multi-scale gradient calculation and weighted quantization can effectively capture the direction and amplitude information of the image at different scales, and improve the representation ability and robustness of the features. Combining the features of different data blocks into a feature vector can comprehensively describe the equipment features in the image data and provide rich feature information for subsequent target detection and defect judgment.
[0011] Furthermore, for weighted quantization of the gradient direction of each data block at different scales, first, the weight of the gradient direction of each data block at different scales is calculated, specifically including: for the gradient direction of the i-th data block at the j-th scale, the cosine value of the angle between it and the main direction is calculated cos(i, j), and the main direction can be a predefined direction, such as a horizontal direction or a vertical direction, or a main direction calculated according to the gradient direction distribution of the data block; according to the gradient amplitude M(i, j) and the cosine value of the angle cos(i, j), the weight value W(i, j) of the gradient direction is calculated, and the calculation formula used is: Among them, e is a natural constant. According to this formula, the larger the gradient amplitude and the closer the cosine value of the angle is to 1 (that is, the closer the gradient direction is to the main direction), the larger the weight value is, indicating that the gradient direction contributes more to the characteristics of the data block. Through weight calculation, the weight value of each gradient direction of each data block at different scales is obtained. Then, the gradient direction of each data block at different scales is weighted quantized according to the weight value, specifically including: for the gradient direction O(i,j) of the i-th data block at the j-th scale, quantize it to the corresponding bin of the histogram according to its value, and the quantization method can be uniform quantization or non-uniform quantization. Using uniform quantization, the 360-degree angle range is divided into K bins, and the interval of each bin is 360 / K degrees. Then the quantization value Q(O(i,j),k) of the gradient direction O(i,j) in the k-th bin is 1, and the quantization values in other bins are 0; according to the weight value W(i,j) and the quantization value Q(O(i,j),k) of the gradient direction, the weighted quantization value H(i,j,k) is calculated, and the calculation formula used is: H(i,j,k)=W(i,j)×Q(O(i,j),k), which represents the value of the k-th weighted gradient direction histogram bin of the i-th data block at the j-th scale, that is, the weight value of the gradient direction is added to the corresponding bin. Through weighted quantization, the weighted gradient direction histogram of each data block at different scales is obtained. Each bin of the histogram represents the accumulated value of the weighted gradient direction in the corresponding interval. Finally, the weighted gradient direction histogram of each data block at different scales is used as the feature description of the data block. The histograms at different scales can be connected in series into a long vector, or the histograms at different scales can be used as multiple parallel feature channels. The complete data processing flow for weighted quantization of the gradient direction of each data block at different scales. The calculation of the gradient direction weight takes into account the gradient amplitude and the angle between the direction and the main direction, which can reflect the importance of different gradient directions to the data block features. Weighted quantization accumulates the weight value of the gradient direction into the corresponding histogram bin. The obtained weighted gradient direction histogram can comprehensively describe the gradient direction distribution characteristics of the data block, enhancing the representation ability and robustness of the feature.
[0012] Furthermore, for calculating the similarity between the image to be detected and the standard image, first, the image to be detected and the standard image are divided into multiple sub-blocks, specifically including: according to a predefined sub-block size, such as 8x8 or 16x16, the image to be detected and the standard image are divided into multiple non-overlapping sub-blocks; weighted calculation is performed on each sub-block, and the weighting coefficient can be determined according to factors such as the position of the sub-block in the image and the visual significance of the sub-block. The selection of the weighting coefficient can be adjusted according to experience or experimental results. Through division and weighting, multiple weighted sub-blocks of the image to be detected and the standard image are obtained. Then, for each sub-block, the brightness similarity, contrast similarity and structural similarity between the weighted sub-block of the image to be detected and the corresponding weighted sub-block of the standard image are calculated, specifically including: for the i-th sub-block, the weighted sub-block of the image to be detected and the corresponding weighted sub-block of the standard image are extracted; the mean brightness of the two sub-blocks is calculated to obtain the brightness similarity, which can be represented by the absolute value of the difference between the mean brightness of the two sub-blocks, and the smaller the value, the more similar the brightness; the contrast of the two sub-blocks is calculated to obtain the contrast similarity, which can be represented by the ratio of the standard deviations of the two sub-blocks, and the closer the value is to 1, the more similar the contrast is; the structural similarity of the two sub-blocks is calculated to obtain the structural similarity, which can be represented by the normalized mutual correlation coefficient of the two sub-blocks, and the closer the value is to 1, the more similar the structure is. Through calculation, the brightness similarity, contrast similarity and structural similarity of each sub-block are obtained.
[0013] Next, the local similarity R(x i ,y i ), specifically including: for the i-th sub-block, according to its brightness similarity, contrast similarity and structural similarity, calculate the local similarity R(x i ,y i ), you can use:
[0014] R(x i ,y i )=λ×L(x,y) α +(1-λ)×{C(x,y) β ×S(x,y) γ}, where L(x,y) represents the brightness similarity between the weighted image sub-block to be detected and the weighted standard image sub-block, C(x,y) represents the contrast similarity between the weighted image sub-block to be detected and the weighted standard image sub-block, S(x,y) represents the structural similarity between the weighted image sub-block to be detected and the weighted standard image sub-block; α, β, γ represent the weight coefficients of brightness similarity, contrast similarity and structural similarity respectively; λ represents the coefficient.
[0015] Finally, the weighted average method is used to sum the local similarities R(x i ,y i ) to obtain the global similarity R(x,y) between the image to be detected and the standard image, which specifically includes: according to the weighting coefficient w of each sub-block i And the local similarity R(x i ,y i ), calculate the global similarity R(x,y), the calculation formula used is: Among them, ∏ represents the multiplication symbol, and the local similarity R(x i ,y i ) According to the weighting coefficient w i Perform a power operation, and then multiply the results of all sub-blocks to obtain the global similarity R(x,y). Through weighted averaging, the global similarity R(x,y) between the image to be detected and the standard image is obtained. The global similarity comprehensively considers the local similarities of all sub-blocks and can more comprehensively evaluate the similarity between the two images. Sub-block division and weighting can specifically evaluate the local features of the image. The calculation of brightness, contrast and structural similarity evaluates the similarity of sub-blocks from multiple angles. The weighted average fusion of local similarities obtains the global similarity, which can comprehensively consider the overall similarity of the image and improve the accuracy and robustness of the similarity calculation.
[0016] Furthermore, for the calculation of brightness similarity, first, for the weighted image sub-block to be detected and the weighted standard image sub-block, their weighted mean is calculated, specifically including: for the image sub-block to be detected, the pixel gray value x_i and the corresponding weighting coefficient w are extracted i , calculate the weighted mean μ x , the calculation formula used is: The gray value x of each pixel i Multiply it by its corresponding weighting coefficient w i , then sum all the products and divide by the sum of the weighting coefficients Σw i , and obtain the weighted mean μ x For the standard image sub-block, the pixel gray value y_i and the corresponding weighting coefficient w are also extracted. i , calculate the weighted mean μ y , the calculation formula used is: The calculation process is the same as the weighted mean calculation of the sub-block of the image to be detected. Through calculation, the weighted mean μ of the sub-block of the image to be detected is obtained. x and the weighted mean μ of the standard image sub-block y Then, calculate the constant C 1Specifically, it includes: determining the dynamic range L of the image according to the number of bits of the image. For grayscale images with different numbers of bits, the values of L are as follows: 8-bit grayscale image: L = 255, 10-bit grayscale image: L = 1023, 12-bit grayscale image: L = 4095, 16-bit grayscale image: L = 65535. Select a small constant K_1, the value range is 0.01 to 0.05, which can be adjusted according to actual needs.
[0017] According to the dynamic range L of the image and the small constant K 1 , calculate the constant C 1 , the calculation formula used is:
[0018] C 1 =(K 1 ×L) 2 , that is, the small constant K 1 Multiply by the dynamic range of the image, L, and then square it to get the constant C 1 By calculation, we get the constant C 1 Finally, according to the weighted mean μ x , μ y and the constant C 1 , calculate the brightness similarity L(x,y), the calculation formula used is: The weighted mean μ x and μ y Multiply the product by 2 and add the constant C 1 , as the numerator; square the weighted means μ_x and μ_y respectively, then add them together, and add the constant C 1 , as the denominator; finally, divide the numerator by the denominator to obtain the brightness similarity L(x,y). The calculation of the weighted mean takes into account the grayscale value of each pixel in the image sub-block and the corresponding weighting coefficient, which can more accurately represent the brightness information of the sub-block. Constant C 1 The introduction of can avoid the situation where the denominator is zero and improve the stability of the calculation. The calculation formula of brightness similarity comprehensively considers the weighted mean and the constant C 1 , which can effectively evaluate the brightness similarity between two sub-blocks. The closer the value is to 1, the more similar the brightness is.
[0019] Furthermore, for the calculation of contrast similarity, first, for the weighted image sub-block to be detected and the weighted standard image sub-block, their weighted standard deviation is calculated, specifically including: for the image sub-block to be detected, the pixel gray value x is extracted therein i , the corresponding weighting coefficient w i and the weighted mean μ x , calculate the weighted standard deviation σ x , the calculation formula used is: The gray value x of each pixeli Subtract the weighted mean μ x , then square it and multiply it by the corresponding weighting coefficient w i , sum all the products and divide by the sum of the weighting coefficients Σw i , and finally perform a square root operation on the result to obtain the weighted standard deviation σ x For the standard image sub-block, the pixel gray value y is also extracted i , the corresponding weighting coefficient w i and the weighted mean μ y , calculate the weighted standard deviation σ y , the calculation formula used is: The calculation process is the same as the weighted standard deviation calculation of the image sub-block to be detected. Through calculation, the weighted standard deviation σ_x of the image sub-block to be detected and the weighted standard deviation σ of the standard image sub-block are obtained. y .
[0020] Then, calculate the constant C 2 , whose value is similar to the constant C 1 Equal, that is: C 2 =C 1 =(K 1 ×L) 2 , where K 1 is a small constant, ranging from 0.01 to 0.05; L is the dynamic range of the image. For grayscale images with different bits, the values of L are as follows: 8-bit grayscale image: L = 255, 10-bit grayscale image: L = 1023, 12-bit grayscale image: L = 4095, 16-bit grayscale image: L = 65535. By calculation, we get the constant C 2 Finally, according to the weighted standard deviation σ x , σ y and the constant C 2 , calculate the contrast similarity C(x,y), the calculation formula used is:
[0021] The weighted standard deviation σ x and σ y Multiply the product by 2 and add the constant C 2 , as the numerator; the weighted standard deviation σ x and σ y Square them separately, add them together, and add the constant C 2 , as the denominator; finally, divide the numerator by the denominator to obtain the contrast similarity C(x,y). The calculation of the weighted standard deviation takes into account the difference between each pixel in the image sub-block and the weighted mean and the corresponding weighting coefficient, which can effectively represent the contrast information of the sub-block. Constant C 2The introduction of can avoid the situation where the denominator is zero and improve the stability of the calculation. The calculation formula of contrast similarity comprehensively considers the weighted standard deviation and the constant C 2 , which can effectively evaluate the contrast similarity between two sub-blocks. The closer the value is to 1, the more similar the contrast is.
[0022] Furthermore, for the calculation of structural similarity, first, for the weighted image sub-block to be detected and the weighted standard image sub-block, their weighted covariance is calculated, specifically including: for the image sub-block to be detected and the standard image sub-block, the pixel gray value x is extracted i and i , the corresponding weighting coefficient w i , and the weighted mean μ x and μ y , calculate the weighted covariance σ xy , the calculation formula used is: The gray value x of each pixel in the sub-block of the image to be detected i Subtract the weighted mean μ x , the gray value y of each pixel in the standard image sub-block i Subtract the weighted mean μ y , then multiply the two differences, multiply by the corresponding weighting coefficient w_i, sum all the products, and divide by the sum of the weighting coefficients Σw i , we get the weighted covariance σ xy By calculation, the weighted covariance σ between the image sub-block to be detected and the standard image sub-block is obtained. xy .
[0023] Then, for the weighted image sub-block to be detected and the weighted standard image sub-block, their weighted standard deviations σ_x and σ_y are calculated. The calculation process is the same as the weighted standard deviation calculation in contrast similarity, that is: By calculation, the weighted standard deviation σ of the image sub-block to be detected is obtained x and the weighted standard deviation σ of the standard image sub-block y Next, calculate the constant C 3 , the calculation formula is: C 3 =C 2 / 2, where C 2 is a constant in the calculation of contrast similarity, C 2 =C 1 =(K 1 ×L) 2 , K 1is a small constant, ranging from 0.01 to 0.05; L is the dynamic range of the image. For grayscale images with different bits, the values of L are as follows: 8-bit grayscale image: L = 255, 10-bit grayscale image: L = 1023, 12-bit grayscale image: L = 4095, 16-bit grayscale image: L = 65535. By calculation, we get the constant C 3 Finally, according to the weighted covariance σ xy , weighted standard deviation σ x and σ y and the constant C 3 , calculate the structural similarity S(x,y), the calculation formula used is: Among them, × represents the multiplication operation, that is, the weighted covariance σ xy Add the constant C 3 , as the numerator; the weighted standard deviation σ x and σ y Multiply and add the constant C 3 , as the denominator; finally, divide the numerator by the denominator to obtain the structural similarity S(x,y). The calculation of the weighted covariance takes into account the difference between each pixel in the sub-block to be detected and the standard image sub-block and their respective weighted means and the corresponding weighting coefficients, which can effectively represent the structural correlation between the two sub-blocks. The calculation of the weighted standard deviation represents the dispersion of the pixel values within the sub-block. The constant C 3 The introduction of can avoid the situation where the denominator is zero and improve the stability of the calculation. The calculation formula of structural similarity comprehensively considers the weighted covariance, weighted standard deviation and constant C 3 , which can effectively evaluate the structural similarity between two sub-blocks. The closer the value is to 1, the more similar the structures are.
[0024] Further, for the calculation of local similarity values, first, for each sub-block, the brightness similarity L(x,y), contrast similarity C(x,y) and structural similarity S(x,y) between the weighted sub-block of the image to be detected and the weighted sub-block of the standard image have been calculated. Then, the weight coefficients α, β, γ and coefficient λ of brightness similarity, contrast similarity and structural similarity are determined, specifically including: according to actual needs and experience, the weight coefficient α of brightness similarity, the weight coefficient β of contrast similarity and the weight coefficient γ of structural similarity are set, and these weight coefficients are used to adjust the importance of different similarity indicators when calculating local similarity values. The value range of the weight coefficient is usually between 0 and 1, and satisfies α+β+γ=1. Also according to actual needs and experience, the coefficient λ is set to balance the combination of brightness similarity and contrast similarity with structural similarity. The value range of λ is usually between 0 and 1. Through the setting, the values of weight coefficients α, β, γ and coefficient λ are determined.
[0025] Finally, the local similarity value R(x) of each sub-block is calculated based on the brightness similarity L(x,y), contrast similarity C(x,y), structural similarity S(x,y) and weight coefficients α, β, γ and λ. i ,y i ), the calculation formula used is: R(x i ,y i )=λ×L(x,y) α +(1-λ)×{C(x,y) β ×S(x,y) γ}, the calculation process is as follows: the brightness similarity L(x,y) is raised to the power of α to obtain L(x,y) α . Raise the contrast similarity C(x,y) to the power of β to get C(x,y) β . Raise the structural similarity S(x,y) to the power of γ to get S(x,y) γ The calculation of the local similarity value comprehensively considers the brightness similarity, contrast similarity and structural similarity. By setting the weight coefficient and coefficient, the importance and combination of different similarity indicators can be flexibly adjusted. The closer the local similarity value is to 1, the higher the local similarity between the sub-block of the image to be detected and the sub-block of the standard image. By calculating the local similarity value of each sub-block, the similarity between the image to be detected and the standard image in different local areas can be comprehensively evaluated, providing important local similarity information for the subsequent global similarity calculation.
[0026] Further, the defect area is obtained, and the image to be detected is converted into a binary image: threshold processing is performed on the image to be detected, and pixels with grayscale values greater than or equal to the threshold are set to 1 to represent the defect area; pixels with grayscale values less than the threshold are set to 0 to represent the non-defect area. A binary image is obtained, in which the pixel value of the defect area is 1 and the pixel value of other areas is 0. The binary image is segmented into a foreground area and a background area: an image segmentation algorithm, such as a region growing algorithm or a watershed algorithm, is used to segment the binary image into a foreground area and a background area. The foreground area corresponds to the defect area, and the pixel value is 1; the background area corresponds to the non-defect area, and the pixel value is 0. Connected domain analysis is performed on the segmented foreground area: a connected domain labeling algorithm, such as a four-connected or eight-connected algorithm, is used to label the foreground area. Connected foreground pixels are labeled as the same connected domain, and different connected domains use different label values. The initial defect area is obtained, and each connected domain represents an initial defect area. Morphological processing is performed on the initial defect area: an erosion operation is performed on the initial defect area, and the initial defect area is eroded using a predefined structural element to remove the noise area whose area is less than the threshold. Perform expansion operation on the defective area after corrosion, use the predefined structural element to expand the defective area, and fill the holes in the defective area. Obtain the defective area after morphological processing, remove the noise area, and fill the hole area. Perform contour extraction on the defective area after morphological processing: Use contour extraction algorithm, such as Canny edge detection algorithm or Sobel operator, to extract the contour of the defective area after morphological processing. Obtain the contour of the defective area, which is a closed curve composed of continuous edge pixels. Perform geometric feature calculation on the contour of the defective area: Calculate the convex hull area of the contour of the defective area, and use convex hull algorithm, such as Graham scanning algorithm or Jarvis stepping algorithm, to calculate the area of the minimum convex polygon of the contour. Calculate the center position of the contour of the defective area, use the geometric center calculation formula, calculate the average coordinate value of the pixels inside the contour, and obtain the coordinate position of the geometric center of the defective area in the image. Use the contour of the defective area as the final defective area: Use the obtained contour of the defective area as the final defective area for subsequent defect analysis and visualization.
[0027] Preferably, the initial defect is obtained, and before the connected domain analysis, the binary image is subjected to morphological processing, such as opening or closing operations, to remove small noise areas and fill small hole areas. A more advanced connected domain labeling algorithm, such as a connected domain labeling algorithm based on graph theory, is used to improve the accuracy and efficiency of connected domain labeling. Preferably, in addition to calculating the convex hull area and center position, other geometric features such as perimeter, area, aspect ratio, circularity, etc. can also be calculated for geometric feature calculation to enrich the feature description of the defective area. A more advanced geometric feature calculation algorithm, such as a geometric feature calculation algorithm based on moments, is used to improve the accuracy and robustness of geometric feature calculation.
[0028] Another aspect of the present specification also provides an image processing system for power grid identification, including: an image preprocessing module: an image quality assessment of an input power grid image is performed to determine whether the image meets the requirements of subsequent processing, such as resolution, contrast, noise, etc. Noise removal is performed on the image, and noise and interference in the image are removed using algorithms such as median filtering and Gaussian filtering. Enhancement processing is performed on the image, such as histogram equalization and contrast adjustment, to improve the visual quality of the image and the distinguishability of features. An image segmentation module: an edge detection algorithm, such as the Canny operator or the Sobel operator, is used to extract edge information in the image. Based on the edge information, a region growing algorithm or a watershed algorithm is used to segment the image into different regions, each corresponding to a power grid device or line segment. The segmentation results are post-processed, such as morphological operations, small region filtering, etc., to remove segmentation errors and noise areas. A feature extraction module: feature extraction is performed on the segmented region, and features such as color, texture, and shape are extracted. Color features: the color histogram and color moment of the region are extracted to describe the color distribution and statistical information of the region. Texture features: Extract the grayscale co-occurrence matrix and Gabor filter response of the region to describe the texture pattern and structural information of the region. Shape features: Extract the geometric features of the region, such as area, perimeter, aspect ratio, circularity, etc., to describe the shape characteristics of the region. Feature selection and dimension reduction module: Perform feature selection on the extracted features and select the feature subset that contributes more to the identification of power grid equipment and lines. Use feature selection algorithms such as the Relief algorithm and the information gain algorithm to evaluate the importance and distinguishing ability of the features. Perform dimension reduction on the selected features and use algorithms such as principal component analysis (PCA) or linear discriminant analysis (LDA) to reduce the dimension of the features and improve the efficiency of subsequent classification. Classifier training and recognition module: Use machine learning algorithms such as support vector machine (SVM), random forest, convolutional neural network (CNN), etc. to train the classifier of power grid equipment and lines. Take the feature vector after feature selection and dimension reduction as input, and the corresponding power grid equipment and line category as output to train the classifier model. For new input images, extract features and use the trained classifier for prediction to identify the power grid equipment and lines in the image. Post-processing and visualization module: Post-process the recognition results of the classifier, such as result filtering, spatial relationship analysis, etc., to improve the accuracy and consistency of recognition. Visualize the recognition results, mark the recognized power grid equipment and lines on the original image, and generate an intuitive recognition result map. Calculate the evaluation indicators of the recognition results, such as accuracy, recall rate, F1 score, etc., to evaluate the performance and reliability of the system. Data management and update module: Establish a power grid image database to store and manage power grid image data for training and testing. Regularly update and expand the database, add power grid images in different scenarios and under different conditions, and improve the generalization ability of the system.Iteratively optimize and update the system, continuously improve algorithms and models based on new data and feedback, and enhance recognition performance and robustness.
[0029] 3. Beneficial effects
[0030] Compared with the prior art, the advantages of this application are:
[0031] By preprocessing the collected power grid image data, extracting the equipment features in the image data, and using the YOLO target detection algorithm for target detection, the equipment in the power grid image can be identified quickly and accurately, thereby improving the efficiency and accuracy of power grid image recognition.
[0032] By dividing the preprocessed image data into multiple data blocks, performing multi-scale gradient calculation on each data block, and weighted quantizing the gradient direction, a multi-scale directional histogram is obtained as the device feature. This can effectively extract the device features in the image, enhance the feature representation capability, and improve the accuracy of device recognition.
[0033] By calculating the similarity between the image to be detected and the standard image, and judging whether the image to be detected has defects based on the similarity calculation result, equipment defects in power grid images can be detected automatically and intelligently.
[0034] By dividing the image to be inspected and the standard image into multiple sub-blocks, performing weighted calculation on each sub-block, calculating the brightness similarity, contrast similarity and structure similarity between sub-blocks, and using the weighted average method to fuse the local similarity to obtain the global similarity, the local and global features of the image can be comprehensively considered to improve the accuracy and reliability of defect detection.
[0035] By segmenting the binary image into foreground and background areas, performing connected domain analysis, morphological processing and contour extraction on the foreground area, and obtaining the geometric features of the defect area, the defect area can be accurately located and described, providing an important basis for subsequent defect analysis and repair.
[0036] By marking the final defect area on the collected power grid image data and generating defect visualization results, the defect area can be displayed intuitively and vividly, which is convenient for operation and maintenance personnel to quickly locate and deal with defects, thereby improving the efficiency and quality of power grid operation and maintenance. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 is an exemplary flow chart of an image processing method for power grid identification according to some embodiments of this specification;
[0038] Figure 2 is an exemplary flow chart of extracting device features according to some embodiments of this specification;
[0039] Figure 3 is an exemplary flow chart of calculating similarity according to some embodiments of this specification;
[0040] Figure 4 is an exemplary flow chart of obtaining a defect area according to some embodiments of the present specification. DETAILED DESCRIPTION
[0041] The method and system provided in the embodiments of this specification are described in detail below with reference to the accompanying drawings.
[0042] Figure 1The present invention is an exemplary flow chart of an image processing method for power grid identification according to some embodiments of the present specification, comprising: collecting power grid image data and preprocessing the collected image data; extracting device features in the image data according to the preprocessed image data; using the YOLO target detection algorithm to perform target detection on the preprocessed image data according to the extracted device features, and obtaining a target detection result, wherein the target detection result includes the detected device; marking the detected device according to the target detection result to obtain the marked device; selecting a corresponding standard image from a standard power distribution network image database according to the marked device; using the preprocessed image data as an image to be detected; calculating the similarity between the image to be detected and the standard image; judging whether the image to be detected has defects according to the similarity calculation result; if the judgment result is that the image to be detected has defects, obtaining a defective area, and the step of obtaining the defective area comprises: converting the image to be detected into a binary image, wherein the binary image has defects. The pixel value of the defect area is 1, and the pixel value of other areas is 0; the binary image is divided into a foreground area and a background area, wherein the foreground area corresponds to the defect area, and the background area corresponds to the non-defect area; the segmented foreground area is subjected to a connected domain analysis, the connected domain is marked, and the initial defect area is obtained; the initial defect area is subjected to morphological processing to obtain the defect area after morphological processing, and the morphological processing includes corrosion operation and expansion operation, the corrosion operation is used to remove the noise area whose area is less than the threshold in the initial defect area, and the expansion operation is used to fill the hole area in the initial defect area; the contour of the defect area after morphological processing is extracted to obtain the contour of the defect area; the geometric feature calculation of the contour of the defect area is performed to obtain the geometric feature of the defect area, and the geometric feature includes the convex hull area and the center position, the convex hull area represents the area of the minimum convex polygon of the defect area, and the center position represents the coordinate position of the geometric center of the defect area in the image; the contour of the defect area is used as the final defect area. The acquired defect area is marked on the collected power grid image data to generate a defect visualization result, and the step of marking the defect area includes: mapping the final defect area back to the original collected power grid image data; marking the defect area on the original power grid image to generate an intuitive defect visualization result image. Automatic identification of power grid equipment is achieved by collecting power grid image data and performing preprocessing, feature extraction and target detection on the image data. After the equipment is identified, it is determined whether the equipment has defects by comparing the similarity with the standard image. If there is a defect, the defect area is accurately obtained through image segmentation, morphological processing and contour extraction, and the defect area is marked on the original image to generate intuitive defect visualization results.
[0043] Collecting grid image data: deploy high-resolution digital cameras or dedicated power equipment image acquisition devices at the grid site to collect images of grid equipment in all directions and at multiple angles. The parameters of the digital camera are set as follows: resolution not less than 12 million pixels, aperture F / 2.8, shutter speed 1 / 250s, ISO sensitivity 200, and white balance is set to automatic mode. The parameters of the dedicated power equipment image acquisition device are set as follows: resolution not less than 20 million pixels, aperture F / 2.0, shutter speed 1 / 500s, ISO sensitivity 100, and white balance is set to daylight mode. When collecting images, ensure that the key parts of the grid equipment (such as insulators, conductors, poles, etc.) are clearly visible to avoid occlusion, overexposure or underexposure. The collected original grid images are saved in JPEG format, with a color space of sRGB and a compression quality of not less than 90%.
[0044] Preprocess the original power grid image: Image quality assessment: Evaluate the quality of the collected original power grid image and calculate the image clarity, contrast, brightness and other indicators. Clarity assessment: Use the Brenner gradient function to calculate the image clarity score. If the score is lower than the preset threshold (such as 0.6), the image is considered blurred and needs to be re-collected. Contrast assessment: Calculate the image contrast score. If the score is lower than the preset threshold (such as 30), the image contrast is considered low and contrast enhancement is required. Brightness assessment: Calculate the average brightness value of the image. If the brightness value exceeds the preset range (such as [50, 200]), the image is considered too bright or too dark and brightness adjustment is required.
[0045] Noise removal: Use the median filter algorithm to denoise the image, and set the filter window size to 5x5 to remove salt and pepper noise and Gaussian noise in the image. Use the wavelet transform algorithm to denoise the image, select the Daubechies wavelet basis function, the decomposition layer number is 3, and the threshold is set to 3 times the standard deviation to remove high-frequency noise in the image. Image enhancement: Use the histogram equalization algorithm to enhance the contrast of the image to improve the contrast and clarity of the image. Use the Retinex algorithm to adjust the brightness of the image, adaptively adjust the brightness distribution of the image, and make the image details clearer. Use the Gamma correction algorithm to color correct the image, and set the Gamma value to 2.2 to make the image color more vivid and realistic. Image size standardization: The preprocessed image is uniformly scaled to a fixed size, such as 800x600 pixels, for subsequent feature extraction and target detection processes. Use the bilinear interpolation algorithm to scale the image to retain the image details.
[0046] Preprocessed grid image data storage: The preprocessed grid image data is classified and stored according to date and device type for subsequent retrieval and analysis. The image data storage format is PNG or TIFF, the color space is sRGB, and the bit depth is not less than 8 bits / pixel. The image data is stored in a high-reliability network attached storage (NAS) device, and an image database index is established for fast retrieval. The preprocessed grid image data is divided into multiple data blocks: A sliding window is used to slide horizontally and vertically with a fixed step size (such as 16 pixels) to divide the preprocessed grid image data into multiple data blocks of equal size. The size of the data block is set to 64x64 pixels to ensure that each data block contains sufficient device feature information, while avoiding the reduction of feature extraction efficiency due to excessively large data blocks. For the edge area of the image, the data block is supplemented by zero padding to ensure that the size of each data block is consistent.
[0047] Figure 2 This is an exemplary flow chart of extracting device features according to some embodiments of this specification, and multi-scale gradient calculation is performed on each data block: 4 different scale factors are selected, such as 0.5, 1.0, 1.5 and 2.0, and multi-scale gradient calculation is performed on each data block. At each scale, the Sobel operator is used to calculate the gradient in the horizontal and vertical directions of the data block to obtain the gradient magnitude and gradient direction of each pixel. The calculation formula of the gradient magnitude is:
[0048] Among them G x (x,y) and G y (x, y) represents the horizontal and vertical gradient components at the pixel point (x, y). The calculation formula for the gradient direction is: Represents the angle between the gradient vector and the horizontal direction. The direction space is evenly divided into 8 direction intervals, each of which corresponds to an angle range of 45 degrees. For the gradient direction of each pixel point, it is quantized into the corresponding direction index (0-7) according to the direction interval to which it belongs. At each scale, the sum of the gradient amplitudes of the pixels in each direction interval is calculated to obtain the weighted gradient amplitudes of the 8 directions. The weighted gradient amplitudes of the 8 directions are normalized to obtain the weighted gradient direction histogram of each data block at the current scale. Each bin of the histogram represents the weighted gradient amplitude proportion of the corresponding direction interval. The weighted gradient direction histograms of each data block at different scales are concatenated: for each data block, its weighted gradient direction histograms at 4 scales are concatenated in sequence to obtain a 32-dimensional feature vector (4 scales x 8 directions). Each element in the feature vector represents the weighted gradient amplitude proportion of the data block at the corresponding scale and direction, reflecting the gradient distribution characteristics of the data block at different scales and directions. Combine the multi-scale directional histograms of all data blocks into a feature vector: The preprocessed power grid image data is divided into M data blocks, and each data block corresponds to a 32-dimensional feature vector. The feature vectors of the M data blocks are concatenated in order from left to right and from top to bottom to obtain a 32*M-dimensional feature vector. This feature vector represents the multi-scale gradient directional distribution characteristics of the equipment in the entire preprocessed power grid image data, which can be used as the input feature for subsequent target detection and defect recognition.
[0049] Input the extracted device features into the trained YOLO target detection model: Use a pre-trained YOLO target detection model, such as YOLOv5, which is pre-trained on the COCO dataset and can detect 80 common targets. Based on the pre-trained model, fine-tune the model using the power grid equipment image dataset to adapt it to the power grid equipment detection task. Reshape the extracted device feature vector to the input size required by the YOLO model, such as 640x640x3, where 3 represents the three RGB color channels. Input the device feature vector into the YOLO model, which extracts multi-scale feature maps through multiple convolution and pooling operations, and generates target detection results through the prediction head. Obtain the target detection result, which contains information such as the category, location, and confidence of the detected power grid equipment: The output of the YOLO model contains multiple bounding boxes, each of which corresponds to a detected target. Each prediction box contains 5 parameters: (x, y, w, h, confidence), where (x, y) represents the coordinates of the center point of the prediction box, (w, h) represents the width and height of the prediction box, and confidence represents the confidence that the prediction box contains the target. The coordinates and size of the prediction box are normalized values relative to the size of the input image. They need to be scaled and translated according to the size of the original image to obtain the actual position of the prediction box in the original image. Each prediction box also contains a category probability vector, which represents the category probability distribution of the target to which the prediction box belongs. The category with the highest probability is selected as the category label of the prediction box. According to the preset confidence threshold (such as 0.5), the prediction boxes with confidence lower than the threshold are filtered out to obtain the final target detection result.
[0050] According to the target detection results, the detected equipment is marked: each prediction box in the target detection results is traversed, and the detected equipment is marked on the original power grid image according to the category label and location information of the prediction box. The detected equipment is marked with a rectangle or polygon. The color of the marking is different according to the different equipment categories, such as transformers are marked in red, circuit breakers are marked in blue, etc. A text label is added near the marked box to display the category name and confidence of the equipment, such as "transformer: 0.85", indicating that the confidence of the transformer is detected is 0.85. For overlapping or adjacent equipment, different annotation styles or colors can be used to facilitate distinction and identification. Obtain the marked power grid equipment image data: Save the annotated power grid image as a new image file, such as JPG or PNG format, and use the original image file name plus the "_annotated" suffix when saving, such as "image001_annotated.jpg". The size and resolution of the annotated image are consistent with the original image for subsequent analysis and visualization. The annotated image is saved in the same folder as the original image for easy management and retrieval.
[0051] The preprocessed image data is used as the image to be detected: an image is randomly selected from the preprocessed power grid image data set as the image to be detected, denoted as I_test. The size of the image to be detected is MxN, where M represents the height of the image and N represents the width of the image. The pixel value range of the image to be detected is [0, 255], which represents a grayscale image or an RGB color image. Calculate the similarity between the image to be detected and the standard image: select an image of the same category as the image to be detected from the standard power grid image data set as the standard image, denoted as I_ref. The size of the standard image is the same as that of the image to be detected, also MxN. The standard image is an image of power grid equipment taken under normal working conditions, reflecting the standard appearance and structural characteristics of the equipment. Divide the image to be detected and the standard image into multiple sub-blocks, and perform weighted calculation on each sub-block: Divide the image to be detected I_test and the standard image I_ref into KxL sub-blocks of the same size, and the size of each sub-block is (M / K)x(N / L). For the (i, j)th sub-block of I_test, record it as I_test(i, j); for the (i, j)th sub-block of I_ref, record it as I_ref(i, j). Gaussian weighting is performed on each sub-block, that is, pixels at the center of the sub-block are given a higher weight, and pixels at the edge are given a lower weight. The purpose of Gaussian weighting is to highlight the importance of the central area of the sub-block and reduce the interference of the edge area. The weighted I _test (i,j) is denoted as I _test_w (i,j), weighted I _ref(i,j) is denoted as I _ref_w (i,j).
[0052] Figure 3 This is an exemplary flow chart for calculating similarity according to some embodiments of the present specification. For each sub-block, the brightness similarity, contrast similarity and structural similarity between the weighted sub-block of the image to be detected and the corresponding weighted sub-block of the standard image are calculated: Brightness similarity l(i,j): measures the brightness difference between the two sub-blocks, that is, the difference between the mean values of the pixel values of the two sub-blocks. Among them, μ test_w (i,j) and μ ref_w (i,j) represent I test_w (i,j) and I ref_w The pixel mean of (i,j); C 1 is a small constant used to avoid the denominator being zero. Contrast similarity C(i,j): measures the contrast difference between two sub-blocks, that is, the ratio of the standard deviations of the pixel values of the two sub-blocks. Among them, σ test_w (i,j) and σ ref_w (i,j) represent I test_w (i,j) and I ref_w The pixel standard deviation of (i, j); C 2 is a small constant used to avoid zero denominator.
[0053] Structural similarity S(i,j): measures the structural similarity of two sub-blocks, that is, the correlation coefficient of the pixel values of the two sub-blocks.
[0054] Among them, σ test_ref_w (i,j) means I test_w (i,j) and I ref_w The covariance of (i,j); C 3 is a small constant used to avoid the denominator being zero. According to the brightness similarity, contrast similarity and structural similarity of each sub-block, the local similarity R(x i ,y i ): local similarity R(x) i ,y i ) is the product of brightness similarity L(x,y), contrast similarity C(x,y) and structure similarity S(i,j).
[0055] R(x i ,y i )=λ×L(x,y) α +(1-λ)×{C(x,y) β ×S(x,y) γ}, where α, β,
[0056] γ is a parameter used to adjust the importance of brightness, contrast and structural similarity, and is usually set to 1. The weighted average method is used to calculate the local similarity R(x i ,y i ) to obtain the global similarity R between the image to be detected and the standard image: The global similarity R is the local similarity R(x i ,y i ) is the weighted average of . Among them, w ij is the weight of sub-block (i, j), usually taken as Indicates that all sub-blocks have the same weight. The value range of global similarity S is [0, 1]. The closer to 1, the more similar the image to be detected is to the standard image, and the closer to 0, the greater the difference between the two images. Set the similarity threshold: According to the characteristics of the power grid equipment image and the requirements of defect detection, set a similarity threshold T to determine whether there are defects in the image to be detected. The value range of threshold T is [0, 1]. Usually a higher value such as 0.8 or 0.9 is selected to ensure high reliability of defect detection. The selection of threshold T needs to balance the detection accuracy and false alarm rate. The optimal threshold can be determined by testing and evaluating a large amount of labeled data.
[0057] Figure 4 This is an exemplary flowchart for obtaining defective areas according to some embodiments of this specification, comparing global similarity and threshold: comparing the global similarity R(x,y) between the image to be detected and the standard image with the preset threshold T. If R(x,y)<T, it is judged that the image to be detected has defects; otherwise, it is judged that the image to be detected has no defects. The comparison operation can be implemented using a simple if-else statement, as shown below: ifR(x,y)<T: print("There are defects in the image to be detected"), else: print("There are no defects in the image to be detected"), visualization of defect judgment results: In order to intuitively display the results of defect detection, the defective area can be marked on the image to be detected, or a binary defect mask image can be generated. If there are defects in the image to be detected, the defective area is marked in red or other eye-catching colors, and the non-defective area remains in the original color. If there are no defects in the image to be detected, a green check mark or text annotation can be added to the image to indicate that the image has passed the defect detection. The marking of defect areas can be achieved using drawing functions in image processing libraries such as Open CV, such as cv2.rectangle(x) or cv2.put Text(x).
[0058] Output and storage of defect judgment results: Output the defect judgment results to the console or log file, including the file name of the image to be detected, the global similarity value and the defect judgment result. If the image to be detected has defects, save it to the specified defect image folder, and add a "_defect" suffix to the file name. If the image to be detected is defect-free, save it to the specified qualified image folder, and add a "_pass" suffix to the file name. The output and storage of defect judgment results can be implemented using Python's file reading and writing functions, such as open(x), write(x) and save(x). Batch processing of defect judgment: In practical applications, it is usually necessary to perform defect detection on a large number of power grid equipment images, and batch processing can be used to improve efficiency. Store all images to be detected in a specified folder, and then use Python's os module to traverse the folder, read each image in turn and perform defect judgment. You can use multi-threading or multi-processing to process multiple images in parallel to make full use of computing resources and speed up processing. The results of batch processing can be output to a summary log file, including the file names, similarity values and defect judgment results of all images.
[0059] Convert the image to be detected into a binary image: Use Open CV's cv2.threshold(x) function to binarize the image to be detected. Set a threshold T, set the pixel values greater than or equal to T to 255 (white), and set the pixel values less than T to 0 (black). The selection of threshold T can be determined based on the brightness distribution of the image and the characteristics of the defect. Usually, the Otsu algorithm can be used to automatically calculate the optimal threshold. In the binarized image, the pixel value of the defect area is 255, and the pixel value of other areas is 0. Segment the binary image into foreground and background areas: Use Open CV's cv2.findContours(x) function to extract the contours of the binary image and obtain the contours of all connected areas. According to the geometric features of the contours, such as area and perimeter, distinguish the foreground area (defect area) and the background area (non-defect area). Usually, the area and perimeter of the defect area are small, while the area and perimeter of the background area are large. You can set an area threshold and a perimeter threshold to distinguish them. Set the pixel value of the foreground area to 255 and the pixel value of the background area to 0 to obtain the segmented binary image.
[0060] Connected domain analysis is performed on the segmented foreground area: Use Open CV's cv2.connectedComponents(x) function to mark the connected domains of the segmented binary image. Connected domain analysis marks all connected foreground pixels in the image as the same region and assigns a unique label value. The label value increases from 1, and 0 represents the background area, and the label map of the initial defect area is obtained. Based on the label map, the number of pixels, center position and other information of each defect area can be counted.
[0061] Perform morphological processing on the initial defect area: Use Open CV's cv2.erode(x) and cv2.dilate(x) functions to erode and dilate the initial defect area. The erosion operation can remove noise and burrs at the edge of the defect area to make the defect area smaller; the dilation operation can fill the holes and fractures inside the defect area to make the defect area larger. The number of erosion and dilation and the kernel size can be set according to the characteristics of the defect area. Usually, a 3x3 or 5x5 rectangular kernel is selected. Dilate the eroded image and erode the dilated image to obtain the defect area after morphological processing. Perform contour extraction on the defect area after morphological processing: Use Open CV's cv2.findContours(x) function to extract the contour of the binary image after morphological processing. Contour extraction connects the boundary pixels of the defect area into a closed curve to obtain the contour of the defect area. The contour is a vector composed of a series of pixel coordinate points, which can be used for subsequent defect area analysis and visualization.
[0062] Calculate the geometric features of the defect area contour: Use Open CV's cv2.contour Area(x) function to calculate the area of the defect area contour. Use Open CV's cv2.convex Hull(x) function to calculate the convex hull of the defect area contour and calculate the area of the convex hull. Use Open CV's cv2.moments(x) function to calculate the moments of the defect area contour and calculate the center position of the contour based on the moments. Geometric features such as area, convex hull area, and center position can be used for quantitative analysis and comparison of defect areas. Use the defect area contour as the final defect area: Draw the bounding box or mask of the defect area on the original image to be detected based on the pixel coordinates of the defect area contour. You can use Open CV's cv2.drawContours(x) function to draw the defect area contour in different colors and thicknesses. You can also use the pixel coordinates to generate a binary mask image of the same size as the original image, setting the pixel values of the defect area to 255 and the pixel values of other areas to 0. The final defect area contour or mask image can be used for visualization and further analysis of the defect area.
[0063] Map the final defect area back to the original acquired power grid image data: In the previous step, we obtained the contour or mask map of the defect area in the image to be detected, but these defect areas are extracted on the preprocessed image, and the size and position may be different from the original acquired power grid image. In order to accurately mark the defect area on the original image, it is necessary to map the coordinates of the defect area back to the coordinate system of the original image. The mapping process needs to take into account the geometric transformations such as scale transformation, translation, and rotation during the image preprocessing process. You can use Open CV's cv2.warp Affine(x) or cv2.warp Perspective(x) function to achieve coordinate mapping. Including: recording the geometric transformation parameters during image preprocessing, such as scaling factor, translation vector, rotation angle, etc. Apply the opposite geometric transformation to the preprocessing process to the contour coordinates of the defect area and map it back to the coordinate system of the original image. If a mask image is used to represent the defect area, apply the same geometric transformation as the preprocessing process to the mask image and map it to the coordinate system of the original image. The coordinates of the mapped defect area or mask image completely correspond to the size and position of the original power grid image, and can be directly marked and visualized on the original image. Mark the defect area on the original power grid image to generate an intuitive defect visualization result image: Use Open CV's drawing function to mark the defect area on the original power grid image and generate a defect visualization result image. There are many ways to visualize, and you can choose the appropriate method according to your needs and application scenarios. The common ones are as follows: Bounding box marking: Use the cv2.rectangle(x) function to draw a bounding box on the circumscribed rectangle of the defect area. You can choose different colors and thicknesses to highlight the defect area. Contour marking: Use the cv2.draw Contours(x) function to draw lines or fill polygons on the contour of the defect area. You can choose different colors and transparency to distinguish different defect areas. Mask overlay: Use the cv2.add Weighted(x) function to weighted overlay the mask image of the defect area with the original image. You can choose different weights and color mapping tables to generate a semi-transparent defect area overlay effect. Text annotation: Use cv2.put Text(x) function to add text annotation near the defect area, such as defect type, area, location and other information. You can choose different fonts, sizes and colors to enhance readability.
Claims
1. An image processing method for power grid identification, include: Collecting power grid image data and preprocessing the collected image data; Extracting device features in the image data according to the preprocessed image data; According to the extracted device features, the YOLO target detection algorithm is used to perform target detection on the preprocessed image data to obtain a target detection result, which includes the detected device; According to the target detection result, the detected device is marked to obtain the marked device; According to the marked equipment, a corresponding standard image is selected from a standard distribution network image database; The preprocessed image data is used as the image to be detected; Calculate the similarity between the image to be detected and the standard image; According to the similarity calculation result, determine whether the image to be inspected has defects; If the judgment result is that the image to be detected has defects, the defect area is obtained; Mark the acquired defect area on the collected power grid image data to generate defect visualization results; According to the preprocessed image data, the device features in the image data are extracted, including: Dividing the preprocessed image data into a plurality of data blocks; Perform multi-scale gradient calculation on each data block to obtain the gradient direction and gradient amplitude of each data block at different scales; For the gradient direction and gradient amplitude of each data block at different scales, the gradient direction of each data block at different scales is weighted and quantized to obtain the weighted gradient direction histogram of each data block at different scales; The weighted gradient direction histograms of each data block at different scales are concatenated to obtain a multi-scale direction histogram of each data block; Combining the multi-scale directional histograms of all data blocks into a feature vector as the device feature in the preprocessed image data; The gradient direction of each data block at different scales is weighted and quantized, including: Calculate the weight of the gradient direction of each data block at different scales to obtain the weight value of each gradient direction. The calculation formula of the weight value is: Where W(i,j) represents the gradient direction weight value of the i-th data block at the j-th scale, M(i,j) represents the gradient amplitude of the i-th data block at the j-th scale, and S(i,j) represents the cosine value of the angle between the gradient direction of the i-th data block at the j-th scale and the main direction; The gradient direction of each data block at different scales is weighted and quantized according to the weight value to obtain the weighted gradient direction histogram of each data block at different scales. The calculation formula of weighted quantization is: H(i,j,k)=W(i,j)×Q(O(i,j),k) Among them, H(i,j,k) represents the value of the kth weighted gradient direction histogram bin of the i-th data block at the j-th scale, O(i,j) represents the gradient direction of the i-th data block at the j-th scale, Q(O(i,j),k) represents the quantized value of the gradient direction O(i,j) in the k-th bin; the histogram bin represents the accumulated value of the weighted gradient direction in the corresponding interval.
2. The image processing method for power grid identification according to claim 1, Features: Calculate the similarity between the image to be detected and the standard image, including: Divide the image to be detected and the standard image into multiple sub-blocks, and perform weighted calculation on each sub-block; For each sub-block, the brightness similarity, contrast similarity and structure similarity between the weighted sub-block of the image to be detected and the corresponding weighted sub-block of the standard image are calculated; According to the brightness similarity, contrast similarity and structure similarity of each sub-block, the local similarity R(x i ,y i ); The weighted average method is used to calculate the local similarity R(x i ,y i ) to obtain the global similarity R(x,y) between the image to be detected and the standard image; Among them, R(x,y) represents the global similarity between the image to be detected X and the standard image Y, R(x i ,y i ) represents the local similarity of the i-th sub-block, w i represents the weighting coefficient of the i-th sub-block.
3. The image processing method for power grid identification according to claim 2, Features: The calculation formula for brightness similarity is: Among them, μ x and μ y They represent the weighted mean of the weighted image sub-block to be detected and the weighted standard image sub-block respectively. The calculation formula of the weighted mean is: Among them, x i and i Represent the grayscale value of the i-th pixel in the image sub-block to be detected and the standard image sub-block, respectively, and w i represents the weighting coefficient of the i-th pixel; C 1 is a constant; C 1 The calculation formula is: C 1 =(K 1 ×L) 2 Among them, K 1 is a small constant with a value range of 0.01 to 0.05; L is the dynamic range of the image. For an 8-bit grayscale image, the value of L is 255; for a 10-bit grayscale image, the value of L is 1023; for a 12-bit grayscale image, the value of L is 4095; for a 16-bit grayscale image, the value of L is 65535.
4. The image processing method for power grid identification according to claim 3, Features: The calculation formula of contrast similarity is: Among them, σ x and σ y They represent the weighted standard deviation of the weighted image sub-block to be detected and the weighted standard image sub-block respectively. The calculation formula of the weighted standard deviation is: Among them, x i and i Respectively represent the gray value of the i-th pixel in the image sub-block to be detected and the standard image sub-block, μ x and μ y They represent the weighted mean of the weighted image sub-block to be detected and the weighted standard image sub-block, respectively. i represents the weighting coefficient of the i-th pixel; C 2 is a constant, C 2 The value of C 1 equal.
5. The image processing method for power grid identification according to claim 4, Features: The calculation formula for structural similarity is: Among them, σ xy represents the weighted covariance of the weighted image sub-block to be detected and the weighted standard image sub-block. The calculation formula of the weighted covariance is: Among them, x i and i Respectively represent the gray value of the i-th pixel in the image sub-block to be detected and the standard image sub-block, μ x and μ y They represent the weighted mean of the weighted image sub-block to be detected and the weighted standard image sub-block, respectively. i represents the weighting coefficient of the i-th pixel; σ x and σ y They represent the weighted standard deviation of the weighted image sub-block to be detected and the weighted standard image sub-block respectively; C 3 is a constant: C 3 =C 2 / 2。 6. The image processing method for power grid identification according to claim 5, Features: According to the brightness similarity, contrast similarity and structure similarity, the local similarity value of each sub-block is calculated, and the local R(x i ,y i ) value is calculated as: R(x i ,and i )=λ×L(x,y) α +(1-λ)×{C(x,y) β ×S(x,y) γ } Among them, L(x,y) represents the brightness similarity between the weighted image sub-block to be detected and the weighted standard image sub-block, C(x,y) represents the contrast similarity between the weighted image sub-block to be detected and the weighted standard image sub-block, S(x,y) represents the structural similarity between the weighted image sub-block to be detected and the weighted standard image sub-block; α, β, γ represent the weight coefficients of brightness similarity, contrast similarity and structural similarity respectively; λ represents the coefficient.
7. The image processing method for power grid identification according to claim 6, Features: If the judgment result is that the image to be detected has defects, the defect area is obtained, including: The image to be inspected is converted into a binary image, in which the pixel value of the defective area is 1 and the pixel value of other areas is 0; The binary image is divided into a foreground area and a background area, wherein the foreground area corresponds to the defect area and the background area corresponds to the non-defect area; Perform connected domain analysis on the segmented foreground area, mark the connected domain, and obtain the initial defect area; Performing morphological processing on the initial defect region to obtain a defect region after morphological processing, wherein the morphological processing includes an erosion operation and a dilation operation, wherein the erosion operation is used to remove a noise region whose area is smaller than a threshold in the initial defect region, and the dilation operation is used to fill a hole region in the initial defect region; The contour of the defect area after morphological processing is extracted to obtain the contour of the defect area; the geometric features of the contour of the defect area are calculated to obtain the geometric features of the defect area, and the geometric features include the convex hull area and the center position. The convex hull area represents the area of the minimum convex polygon of the defect area, and the center position represents the coordinate position of the geometric center of the defect area in the image; The outline of the defect area is taken as the final defect area.
