A method for detecting cracks in water pipelines
By using sliding window technology and gradient information entropy calculation, the threshold is dynamically adjusted, solving the problem of unsuitable threshold setting in water conservancy pipeline crack detection, and realizing high-precision crack identification and evaluation in complex environments.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- FOREVER COAST (BEIJING) TECHNOLOGY CO LTD
- Filing Date
- 2026-03-06
- Publication Date
- 2026-06-05
AI Technical Summary
Existing methods for detecting cracks in water conservancy pipelines are difficult to adaptively set detection thresholds under uneven lighting and noisy environments, resulting in unclear distinction between main cracks and secondary cracks. Furthermore, traditional algorithms are prone to missing small cracks or introducing false edge noise.
Using the sliding window technique, the confidence scores of primary and secondary cracks are calculated based on gradient magnitude and directional information entropy. The high and low thresholds are dynamically adjusted, and noise is eliminated by combining gradient direction consistency and gray-level similarity. The connection points of primary and secondary cracks are accurately located and edge detection is performed.
It automatically obtains the optimal edge detection threshold under different lighting and material conditions, accurately identifies small cracks, reduces false alarms, improves detection accuracy and signal-to-noise ratio, and reduces unnecessary maintenance costs.
Smart Images

Figure CN122156158A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and more specifically to a method for detecting cracks in water conservancy pipelines. Background Technology
[0002] Water conservancy pipelines, such as drainage pipes and canals, are subjected to various stresses over long periods, including internal pressure, external loads, corrosion, and temperature changes, making them prone to cracking. As a crucial component of urban infrastructure, the health of these pipelines directly impacts urban operational safety. Currently, crack detection in water conservancy pipelines primarily relies on CCTV (closed-circuit television) inspection robots combined with manual interpretation or automated algorithms. Regarding automated detection algorithms, existing technologies mainly fall into two categories: one is deep learning-based object detection algorithms (such as YOLO), which, while highly accurate, rely on massive amounts of labeled data for training and have extremely high computational resource requirements, making real-time deployment on embedded pipeline terminals with limited computing power; the other is edge detection algorithms based on traditional image processing (such as Canny and Sobel operators), which have lower computational complexity and stronger interpretability.
[0003] However, existing Canny edge detection algorithms heavily rely on globally fixed high and low thresholds. The internal environment of hydraulic pipelines is complex, with uneven lighting and noise from water stains and dirt. The gradient characteristics of primary cracks (wide cracks) and secondary cracks (fine, diverging cracks) differ significantly. Using a uniform, fixed threshold often has trade-offs: increasing the threshold to suppress noise may miss small secondary cracks; decreasing the threshold to preserve secondary cracks may introduce a large amount of false edge noise. Therefore, how to adaptively determine the detection threshold based on the local topology of the crack (such as the connection between primary and secondary cracks) is a pressing technical challenge that needs to be addressed. Summary of the Invention
[0004] This invention provides a crack detection method for water conservancy pipelines to solve the existing problem of unclear distinction between main cracks and secondary cracks in drainage pipelines using image perception.
[0005] The present invention provides a crack detection method for water conservancy pipelines, which adopts the following technical solution: One embodiment of the present invention provides a crack detection method for water conservancy pipelines, the method comprising the following steps: Images of the surface of the drainage pipe are acquired and converted to grayscale to obtain grayscale images of the inside of the drainage pipe. Edge detection is performed on the internal grayscale image to extract the main cracks in the internal grayscale image, and a sliding window is constructed with the pixels of the main cracks as the center. Based on the gradient magnitude and gradient direction information entropy of the pixels in the window, the confidence of the main and secondary cracks in each sliding window is calculated; the connecting pixels located at the junction of the main crack and the secondary crack are selected according to the confidence. Analyze the grayscale values and gradient features of pixels within the sliding window containing the connected pixels to calculate the probability of secondary crack pixels within the window; based on the probability, obtain the secondary crack pixels within the sliding window corresponding to the connected pixels. Based on the gradient magnitude distribution of all identified sub-crack pixels, calculate the high and low thresholds for edge detection. The internal grayscale image is re-evaluated using the high and low thresholds, the proportion of abnormal pixels is counted, and the anomaly detection is completed based on the comparison between the proportion and the preset threshold.
[0006] Furthermore, the specific steps for obtaining the main crack in the internal grayscale image are as follows: Canny edge detection is performed on the grayscale image inside the drainage pipe to obtain an edge detection image. The edge lines formed by all pixels in the edge detection image whose gradient magnitude is greater than the threshold A constitute the main crack in the grayscale image inside the drainage pipe.
[0007] Furthermore, the specific steps for obtaining the information entropy in the gradient direction are as follows: The formula for the information entropy in the gradient direction is: In the formula, This represents the ratio of the number of pixels within the w-th sliding window whose gradient direction is the i-th direction to the total number of pixels within the w-th sliding window. This represents the entropy value of the gradient direction of the pixel within the w-th sliding window, where 8 represents the eight directions of the gradient.
[0008] Furthermore, the specific steps for calculating the confidence scores of primary and secondary cracks for each sliding window are as follows: An exponential evaluation function based on gradient feature changes is constructed to calculate the confidence scores of the primary and secondary cracks; the evaluation function uses the natural constant as the base, and the exponential part is determined by the ratio of the information entropy in the gradient direction to the change in gradient magnitude; The confidence level of the primary and secondary cracks is negatively correlated with the information entropy of the gradient direction of the pixels within the sliding window, and positively correlated with the increment of the average gradient magnitude of the sliding window relative to the preceding window.
[0009] Furthermore, the specific steps for filtering the connecting pixel points located at the junction of the main crack and the secondary crack based on the confidence level are as follows: The center pixel of the sliding window when the confidence level of the primary and secondary cracks is greater than or equal to the preset threshold D is recorded as the connecting pixel.
[0010] Furthermore, the specific steps involved in analyzing the grayscale values and gradient features of pixels within the sliding window containing the connected pixels, and calculating the probability of secondary crack pixels within the window, are as follows: A local analysis window is constructed with the connecting pixels as the center. The target pixels within the window are traversed, and the number of pixels within the window whose gradient magnitude is less than that of the target pixel is counted and recorded as the gradient dominance number. The number of pixels within the window whose gradient direction is consistent with that of the target pixel is obtained and recorded as the direction consistency number. Based on the ratio of the sum of the gradient dominance number and the direction consistency number to the total number of pixels within the window, the weight coefficient of the target pixel is calculated. Pixels within the window whose grayscale difference from the target pixel is within a preset range are selected, their average gradient magnitude is calculated, and this average is added to the gradient magnitude of the target pixel itself to obtain the enhanced gradient magnitude; the weighting coefficient is multiplied by the enhanced gradient magnitude to obtain the probability that the target pixel is a secondary crack pixel.
[0011] Furthermore, the specific steps for obtaining the secondary crack pixels within the sliding window corresponding to the connected pixels are as follows: Sort the probability of all pixels in each sliding window being a secondary crack pixel from smallest to largest to obtain a sequence, denoted as E. Divide the sequence E into four equal parts, and select the pixel corresponding to the part with the largest average probability of being a secondary crack pixel, and denote it as the secondary crack pixel.
[0012] Furthermore, the specific steps for calculating the high and low thresholds for edge detection based on the gradient magnitude distribution of all identified sub-crack pixels are as follows: Get the number of all secondary crack pixels in the sliding window corresponding to each connected pixel, and record it as the first number; get the total number of all secondary crack pixels in the sliding window corresponding to all connected pixels, and record it as the second number; use the ratio between the first number and the second number as the weight of the sliding window corresponding to the connected pixel; The first product is the product of the maximum gradient magnitude of the secondary crack pixel within the sliding window corresponding to the connected pixel and the weight of the corresponding sliding window. This first product is accumulated across the sliding windows corresponding to the connected pixels to obtain the high threshold. The second product is the product of the minimum gradient magnitude of the secondary crack pixel within the sliding window corresponding to the connected pixel and the weight of the corresponding sliding window. This second product is accumulated across the sliding windows corresponding to the connected pixels to obtain the low threshold.
[0013] Furthermore, the specific steps involved in re-performing edge detection on the internal grayscale image using the high and low thresholds and calculating the proportion of abnormal pixels are as follows: Pixels with gradient magnitudes greater than or equal to the high threshold in the grayscale image inside the drainage pipe are classified as main cracks, while pixels with gradient magnitudes greater than or equal to the low threshold and less than the high threshold in the grayscale image inside the drainage pipe are classified as secondary cracks. Calculate the proportion of the number of main crack pixels in the grayscale image inside the drainage pipe to the total number of pixels in the grayscale image inside the drainage pipe, denoted as H1. Calculate the proportion of the number of secondary crack pixels in the grayscale image inside the drainage pipe to the total number of pixels in the grayscale image inside the drainage pipe, denoted as H2. Preset the first weight W1, and preset the second weight W2; Percentage of abnormal pixels in grayscale images of the inside of drainage pipes .
[0014] Furthermore, the anomaly detection based on the comparison result between this proportion and a preset threshold includes the following specific steps: When the percentage of abnormal pixels in the grayscale image inside the drainage pipe At this time, the grayscale image inside the drainage pipe shows a high degree of abnormality, requiring inspection; when the percentage of abnormal pixels in the grayscale image inside the drainage pipe is high... At that time, the anomaly level of the grayscale image inside the drainage pipe was small, and no maintenance was required. This is a preset threshold.
[0015] The beneficial effects of the technical solution of the present invention are: On the one hand, existing technologies typically use empirical values to set global high and low thresholds, which are difficult to consider under different lighting conditions and pipe material backgrounds. This invention innovatively proposes a threshold generation mechanism. Utilizing the topological connection relationship between the main crack and secondary cracks, a sliding window is used to extract the actual gradient features of the secondary cracks at the connection points, thereby calculating a dynamic high and low threshold adapted to the current image environment. This avoids the blindness of manual parameter tuning and ensures that the optimal edge detection threshold can be automatically obtained in pipes of different materials (such as concrete and PVC) and under different lighting conditions.
[0016] On the other hand, in the inspection of water conservancy pipeline projects, small branch cracks are often precursors to structural damage, but their gradient amplitude is close to background noise, making them easily filtered out by traditional algorithms. This invention utilizes a confidence evaluation model to pinpoint the connection points between primary and secondary cracks, and uses these as anchor points to perform targeted tracking and statistical analysis of weak edges. This not only preserves the integrity of secondary cracks and effectively repairs the "fracture" phenomenon at crack edges, but also more accurately assesses the damage level of the pipeline, preventing minor hidden dangers from being missed.
[0017] Furthermore, drainage pipes often contain high-frequency noise interference such as water stains, moss, and dirt. This invention introduces gradient direction consistency and gray-level similarity as constraints, effectively eliminating disordered background noise (such as water stain edges). In practical engineering applications, this mechanism significantly improves the signal-to-noise ratio of image processing and reduces unnecessary maintenance costs caused by false alarms. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 This is a flowchart illustrating the steps of a crack detection method for water conservancy pipelines according to the present invention. Detailed Implementation
[0020] To further illustrate the technical means and effects adopted by the present invention to achieve its intended purpose, the following, in conjunction with the accompanying drawings and preferred embodiments, details the specific implementation, structure, features, and effects of a crack detection method for water conservancy pipelines proposed according to the present invention. In the following description, different "one embodiment" or "another embodiment" do not necessarily refer to the same embodiment. Furthermore, specific features, structures, or characteristics in one or more embodiments can be combined in any suitable form.
[0021] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains.
[0022] The following description, in conjunction with the accompanying drawings, details a specific scheme for a crack detection method for water conservancy pipelines provided by the present invention.
[0023] Please see Figure 1 The diagram illustrates a flowchart of a crack detection method for water conservancy pipelines according to an embodiment of the present invention. The method includes the following steps: Step S101: Acquire images of the surface of the drainage pipe.
[0024] Considering the typically humid environment and poor lighting conditions inside water conservancy pipelines, simple image acquisition cannot meet the requirements for high-precision detection. This embodiment uses a CCTV crawling robot equipped with a high-definition industrial camera, with the camera resolution preferably selected as... Or even higher, to ensure that subtle subcrack features can be captured.
[0025] To eliminate the uneven light reflection caused by the cylindrical inner wall of the pipe (i.e., the spot effect of bright center and dark edge), the acquisition equipment is equipped with a ring-shaped shadowless LED supplementary light group with a color temperature controlled at 5500K-6000K (cool white light) to enhance the contrast between the crack and the background of the pipe wall.
[0026] Meanwhile, the crawling robot's speed is strictly controlled between 0.1 m / s and 0.3 m / s. Excessive speed will cause motion blur, severely affecting the accuracy of gradient magnitude calculation in subsequent step S002. The acquired raw RGB image is converted to grayscale using a weighted average method, as shown in the formula... This preserves the details of the green channel that are most sensitive to the human eye, resulting in high-quality grayscale images of the inside of the drainage pipes.
[0027] At this point, a grayscale image of the inside of the drainage pipe is obtained.
[0028] Step S102: Preset a sliding window, obtain connected pixels based on the gradient information of pixels in each window, perform pixel analysis in the sliding window area corresponding to the connected pixels to obtain secondary crack pixels, and obtain high threshold and low threshold based on all secondary crack pixels in the sliding window corresponding to the connected pixels.
[0029] (1) The grayscale images of the inside of the drainage pipe were processed to identify the main cracks.
[0030] Canny edge detection is performed on the grayscale image inside the drainage pipe to obtain an edge detection image. A preset gradient threshold A is used, where this embodiment uses A=150 as an example. This embodiment is not specifically limited, and A can be determined according to the specific implementation. The preset threshold A is used to obtain the main cracks in the grayscale image inside the drainage pipe. The edge lines formed by all pixels in the edge detection image whose pixel gradient magnitude is greater than the threshold A constitute the main cracks in the grayscale image inside the drainage pipe.
[0031] At this point, the main crack in the drainage pipe image is obtained.
[0032] (2) Set up a sliding window and slide it on the main crack to determine whether the sliding window has slid to the connection between the main crack and the secondary crack.
[0033] It should be noted that, since the gradient magnitudes of the main crack and the secondary crack are different in the edge detection image, the gradient magnitude of the main crack is larger and the gradient magnitude of the secondary crack is smaller. Therefore, if the features of the secondary crack appear at the pixel of the main crack, it can be determined that it is the connection between the main crack and the secondary crack. So, a sliding window is set here, and the sliding window is centered on each pixel of the main crack to analyze the gradient changes of the pixels within each sliding window.
[0034] Specifically, after detecting the main crack, any endpoint of the main crack is used as the starting pixel of the sliding window; the maximum length of the main crack is obtained, and half of the maximum length of the main crack is used as the width of the sliding window. The sliding window is moved along the edge line with a step size of one pixel to obtain the sliding window corresponding to each pixel on the edge line.
[0035] In another embodiment of the invention, the preset gradient threshold A and the sliding window size R can be adaptively adjusted for drainage pipes made of different materials (such as concrete pipes and PVC pipes). For example, for concrete pipes, due to their high surface roughness and high background noise, it is recommended to set the preset threshold A to 180-200 and the sliding window size R to [missing value]. To enhance noise reduction capabilities; for PVC pipes, which have a relatively smooth surface, it is recommended to set the preset threshold A to 120-150 and the sliding window size R to [missing value]. This is to improve sensitivity to fine scratch-like cracks.
[0036] It should be noted that when the pixel distribution inside the sliding window is such that the edge of the main crack does not contact the secondary crack, the pixel distribution inside the window usually exhibits a certain degree of uniformity. However, when the edge of the main crack inside the sliding window contacts the secondary crack, the presence of the secondary crack may introduce some irregularities and texture changes. In this case, the pixel distribution inside the sliding window may show obvious fluctuations in gradient amplitude, which represent the changes at the connection between the main crack and the secondary crack.
[0037] It should be further explained that when the sliding window comes into contact with the area containing the secondary crack, the secondary crack has edge pixels. Therefore, at this time, because the new edge pixels intrude into the sliding window area, the pixels inside the sliding window will undergo some changes, specifically: First, the gradient direction of the background pixels is disordered, and this is also true for the background pixels in the sliding window region. Therefore, when there are only some edge pixels and the rest are background pixels in the sliding window, if the sliding window is moved to a point where there are additional edge pixels, the entropy value of the gradient direction in the sliding window will usually decrease.
[0038] Secondly, when there are additional edge pixels within the sliding window, the average gradient magnitude of the entire sliding window usually increases. As mentioned earlier, secondary cracks have edges, but the gradient magnitude of the edges is smaller than that of the main crack edges. However, it is larger compared to the gradient magnitude of the background pixels. Therefore, when secondary crack pixels appear within the sliding window, the edge pixels of the secondary cracks replace some background pixels within the sliding window, causing the overall gradient magnitude to change, which tends to increase the average gradient magnitude within the sliding window.
[0039] Specifically, the gradient direction is divided into eight directions: 0°, 45°, 90°, 135°, 180°, 225°, 270°, and 315°. The confidence scores of the primary and secondary cracks for each sliding window are obtained based on the changes in the entropy of the gradient direction of the pixels within the sliding window, the changes in the average gradient magnitude of all pixels within the sliding window, and the length of the pixel chain within the sliding window. The specific formula is as follows: In the formula, This represents the entropy value of the gradient direction of a pixel within the w-th sliding window. This represents the average gradient magnitude of all pixels within the w-th sliding window. This represents the average gradient magnitude of all pixels within the (w-1)th sliding window. This represents an exponential function with the natural constant as its base. denoted as the confidence level of the primary and secondary cracks in the w-th sliding window, where the w-th window is a sliding window centered on the w-th pixel in the main crack, and the (w-1)-th sliding window is the previous sliding window obtained from the main crack.
[0040] When w is 1, due to the absence of the previous sliding window, the confidence levels of the primary and secondary cracks in the first sliding window cannot be calculated. Then directly order ,in, The confidence level of the primary and secondary cracks in the second sliding window.
[0041] In this embodiment, the gradient directions of pixels within the sliding window are specified to be only eight directions. By obtaining the gradient directions of all pixels within the w-th sliding window, the ratio of the number of pixels in each direction to the total number of pixels within the w-th sliding window is calculated and denoted as the gradient direction ratio. It means that, among them, This represents the ratio of the i-th gradient direction within the w-th sliding window. The information entropy of the gradient direction is calculated based on this ratio, and the specific formula is as follows: In the formula, This represents the ratio of the number of pixels within the w-th sliding window whose gradient direction is the i-th direction to the total number of pixels within the w-th sliding window. This represents the entropy value of the gradient direction of the pixel within the w-th sliding window, where 8 represents the eight directions of the gradient.
[0042] Specifically, the smaller the entropy value of the gradient direction of pixels within the sliding window, the greater the confidence in the existence of a connection between a primary crack and a secondary crack within the sliding window. The entropy value of the gradient direction of pixels within a region is usually obtained by counting the number of pixels in each direction and calculating their proportion. The greater the increase in the average gradient magnitude of pixels within the sliding window compared to the previous sliding window, the greater the confidence in the existence of a connection between a primary crack and a secondary crack within the sliding window.
[0043] A threshold D is preset, and this embodiment uses D=0.8 as an example. This embodiment does not impose a specific limitation, and D can be determined according to the specific implementation. When the confidence of the primary and secondary cracks in the sliding window centered at the w-th pixel in the main crack is greater than or equal to the preset threshold D, the w-th pixel is considered to be the connection point between the main crack and the secondary crack; otherwise, it is not considered to be the connection point between the main crack and the secondary crack. That is, all pixels that may be the connection points between the main crack and the secondary crack can be obtained and denoted as the connecting pixels.
[0044] At this point, all connected pixels have been obtained.
[0045] (3) Analyze the sliding window area corresponding to the connected pixel points to obtain the secondary crack pixel points.
[0046] It should be noted that when traversing the sliding window with each pixel in the main crack as the center pixel, only the connecting pixels are obtained, but the specific secondary crack pixels are unknown. Therefore, each pixel in the sliding window corresponding to the connecting pixel is analyzed. So here, after analyzing each pixel, we filter to obtain the secondary crack pixels in the sliding window corresponding to the connecting pixel.
[0047] It should be further noted that the gradient magnitude of pixels belonging to the edge of the secondary crack is related to the surrounding pixels. The number of pixels in the surrounding area should be relatively large. When comparing the gradient magnitude with that of neighboring pixels, the pixel The gradient magnitude of a pixel is relatively large compared to its surrounding neighborhood. Pixels on an edge typically have similar grayscale values. By analyzing the difference between the gradient magnitude of the central pixel and the average gradient magnitude of all pixels except the central pixel within a sliding window, a larger difference indicates a larger grayscale change, thus more likely corresponding to an edge location. If a pixel belongs to the edge of a secondary crack, then there must be neighboring pixels with a gradient direction consistent with that pixel.
[0048] Specifically, all connected pixels in the grayscale image inside the drainage pipe are obtained. The probability that each pixel within the sliding window corresponding to a connected pixel is a secondary crack pixel is determined based on the gradient magnitude of the pixels within that window. This is expressed by the formula: In the formula, the t-th pixel in the sliding window whose m-th connected pixel is the center pixel of the sliding window is denoted as the target pixel. This represents the gradient magnitude of the target pixel. Let represent the gradient magnitude of the j-th pixel within a window centered on the target pixel, and let T represent the number of pixels within the window centered on the target pixel. The preset grayscale threshold is 5. Within the window centered on the target pixel, the average gradient magnitude of all pixels whose absolute difference from the target pixel's grayscale value is less than the preset grayscale threshold is obtained. , This indicates the number of pixels within the window centered on the target pixel that share the same gradient direction as the target pixel. This indicates the probability that the target pixel is a secondary crack pixel. This represents the step function. The window size, centered on the target pixel, is preset to be... In this embodiment, R=3 is used as an example for description. This embodiment is not specifically limited, and R can be determined according to the specific implementation.
[0049] Among them, when The larger the partial result value, the corresponding The larger the value, the larger the result value of that part as a coefficient. Represents pixels The larger the gradient magnitude of the pixel itself, the larger the average gradient of the pixels similar to it, and the greater the probability that it is a pixel on the edge of the crack.
[0050] After obtaining the probability that each pixel in the sliding window corresponding to the connected pixel is a secondary crack pixel, sort all the pixels in each sliding window in ascending order of probability of being a secondary crack pixel to obtain a sequence, denoted as E. Divide the sequence E into four equal parts, and obtain the pixel corresponding to the part with the largest average probability of being a secondary crack pixel in the four parts, and denot it as the secondary crack pixel. Similarly, obtain all the secondary crack pixels in the sliding window corresponding to each connected pixel.
[0051] At this point, all secondary crack pixels within the sliding window corresponding to the connected pixels are obtained.
[0052] (4) Obtain the high threshold and low threshold based on all the secondary crack pixels in the sliding window corresponding to the connected pixel.
[0053] Specifically, the number of all secondary crack pixels within the sliding window corresponding to each connected pixel is counted, denoted as . The weight of the sliding window corresponding to each connected pixel is calculated based on G, and expressed by the formula: In the formula, This represents the number of all sub-crack pixels within the sliding window corresponding to the r-th connected pixel. This represents the number of all sub-crack pixels within the sliding window corresponding to the k-th connected pixel, where K represents the number of connected pixels. This represents the weight of the sliding window corresponding to the r-th connected pixel.
[0054] The maximum and minimum amplitude values of the secondary crack pixels within the sliding window corresponding to the connected pixels are obtained. Based on the maximum and minimum amplitude values of the secondary crack pixels within all sliding windows, the high and low threshold values for Canny edge detection of the grayscale image inside the drainage pipe are obtained. This is specifically expressed by the formula: In the formula, This represents the weight of the sliding window corresponding to the r-th connected pixel. This represents the maximum gradient magnitude of the sub-crack pixel within the sliding window corresponding to the r-th connected pixel. Let K represent the minimum gradient magnitude of the second crack pixel within the sliding window corresponding to the r-th connected pixel, where K represents the number of connected pixels. This represents the high threshold for Canny edge detection when performing grayscale images of the interior of drainage pipes. This represents the low threshold for Canny edge detection when performing grayscale image analysis on the interior of the drainage pipe.
[0055] Thus, the high and low thresholds in the grayscale image inside the drainage pipe are obtained.
[0056] Step S103: Perform edge detection again on the grayscale image inside the drainage pipe based on the high and low thresholds in the grayscale image inside the drainage pipe to obtain new edge detection results.
[0057] Canny edge detection is performed again on the grayscale image inside the drainage pipe. High and low thresholds are used to obtain the main cracks and secondary cracks in the grayscale image inside the drainage pipe. Pixels with gradient amplitude greater than or equal to the high threshold are classified as main cracks, and pixels with gradient amplitude greater than or equal to the low threshold and less than the high threshold are classified as secondary cracks. Thus, the main cracks and secondary cracks in the grayscale image inside the drainage pipe are obtained.
[0058] The number of pixels with main cracks and the number of pixels with secondary cracks in the grayscale image inside the drainage pipe are obtained and denoted as U1 and U2, respectively. The proportion of the number of pixels with main cracks in the grayscale image inside the drainage pipe is calculated and denoted as H1. The proportion of the number of pixels with secondary cracks in the grayscale image inside the drainage pipe is calculated and denoted as H2. The first weight W1 is preset to 0.7, and the second weight W2 is preset to 0.3. This is used as an example to ensure that the sum of W1 and W2 is 1. The proportion of abnormal pixels in the grayscale image inside the drainage pipe is obtained, expressed by the formula: In the formula, H1 represents the proportion of pixels with main cracks in the grayscale image inside the drainage pipe to the total number of pixels in the grayscale image inside the drainage pipe; H2 represents the proportion of pixels with secondary cracks in the grayscale image inside the drainage pipe to the total number of pixels in the grayscale image inside the drainage pipe; and GG represents the proportion of abnormal pixels in the grayscale image inside the drainage pipe. Since the sum of H1 and H2 represents the proportion of pixels with main cracks and secondary cracks in the grayscale image inside the drainage pipe, and main cracks are more severe than secondary cracks, W1 is used as the weight of H1, and W2 is used as the weight of H2, and thus a weighted sum is obtained to obtain the proportion of abnormal pixels in the grayscale image inside the drainage pipe.
[0059] A preset anomaly threshold Gg is set. This embodiment uses Gg=0.5% as an example, but this embodiment is not specifically limited; Gg can be determined according to the specific implementation. The percentage of abnormal pixels in the grayscale image inside the drainage pipe is considered. At that time, it was considered that the grayscale image inside the drainage pipe was highly abnormal and required inspection; when the percentage of abnormal pixels in the grayscale image inside the drainage pipe was... At that time, it was considered that the degree of abnormality in the grayscale image inside the drainage pipe was small and no maintenance was required.
[0060] This concludes the embodiment.
[0061] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for crack detection in water conservancy pipelines, characterized in that, The method includes the following steps: Images of the surface of the drainage pipe are acquired and converted to grayscale to obtain grayscale images of the inside of the drainage pipe. Edge detection is performed on the internal grayscale image to extract the main cracks in the internal grayscale image, and a sliding window is constructed with the pixels of the main cracks as the center. Based on the gradient magnitude and gradient direction information entropy of the pixels in the window, the confidence of the main and secondary cracks in each sliding window is calculated; the connecting pixels located at the junction of the main crack and the secondary crack are selected according to the confidence. Analyze the grayscale values and gradient features of pixels within the sliding window containing the connected pixels to calculate the probability of secondary crack pixels within the window; based on the probability, obtain the secondary crack pixels within the sliding window corresponding to the connected pixels. Based on the gradient magnitude distribution of all identified sub-crack pixels, calculate the high and low thresholds for edge detection. The internal grayscale image is re-evaluated using the high and low thresholds, the proportion of abnormal pixels is counted, and the anomaly detection is completed based on the comparison between the proportion and the preset threshold.
2. The crack detection method for water conservancy pipelines according to claim 1, characterized in that, The specific steps for obtaining the main crack in the internal grayscale image are as follows: Canny edge detection is performed on the grayscale image inside the drainage pipe to obtain an edge detection image. The edge lines formed by all pixels in the edge detection image whose gradient magnitude is greater than the threshold A constitute the main crack in the grayscale image inside the drainage pipe.
3. The crack detection method for water conservancy pipelines according to claim 1, characterized in that, The specific steps for obtaining the information entropy in the gradient direction are as follows: The formula for the information entropy in the gradient direction is: In the formula, This represents the ratio of the number of pixels within the w-th sliding window whose gradient direction is the i-th direction to the total number of pixels within the w-th sliding window. This represents the entropy value of the gradient direction of the pixel within the w-th sliding window, where 8 represents the eight directions of the gradient.
4. The crack detection method for water conservancy pipelines according to claim 1, characterized in that, The specific steps for calculating the confidence scores of primary and secondary cracks in each sliding window are as follows: An exponential evaluation function based on gradient feature changes is constructed to calculate the confidence scores of the primary and secondary cracks; the evaluation function uses the natural constant as the base, and the exponential part is determined by the ratio of the information entropy in the gradient direction to the change in gradient magnitude; The confidence level of the primary and secondary cracks is negatively correlated with the information entropy of the gradient direction of the pixels within the sliding window, and positively correlated with the increment of the average gradient magnitude of the sliding window relative to the preceding window.
5. The crack detection method for water conservancy pipelines according to claim 1, characterized in that, The specific steps for filtering the connecting pixel points located at the junction of the main crack and the secondary crack based on the confidence level are as follows: The center pixel of the sliding window when the confidence level of the primary and secondary cracks is greater than or equal to the preset threshold D is recorded as the connecting pixel.
6. The crack detection method for water conservancy pipelines according to claim 1, characterized in that, The specific steps involved in analyzing the grayscale values and gradient features of pixels within the sliding window containing the connected pixels, and calculating the probability of secondary crack pixels within the window, are as follows: A local analysis window is constructed with the connecting pixels as the center. The target pixels within the window are traversed, and the number of pixels within the window whose gradient magnitude is less than that of the target pixel is counted and recorded as the gradient dominance number. The number of pixels within the window whose gradient direction is consistent with that of the target pixel is obtained and recorded as the direction consistency number. Based on the sum of the gradient dominance number and the direction consistency number, and the ratio of the sum to the total number of pixels within the window, the weight coefficient of the target pixel is calculated. Pixels within the window whose grayscale difference from the target pixel is within a preset range are selected, their average gradient magnitude is calculated, and this average is added to the gradient magnitude of the target pixel itself to obtain the enhanced gradient magnitude; the weighting coefficient is multiplied by the enhanced gradient magnitude to obtain the probability that the target pixel is a secondary crack pixel.
7. The crack detection method for water conservancy pipelines according to claim 1, characterized in that, The specific steps for obtaining the secondary crack pixels within the sliding window corresponding to the connected pixels are as follows: Sort the probability of all pixels in each sliding window being a secondary crack pixel from smallest to largest to obtain a sequence, denoted as E. Divide the sequence E into four equal parts, and select the pixel corresponding to the part with the largest average probability of being a secondary crack pixel, and denote it as the secondary crack pixel.
8. The crack detection method for water conservancy pipelines according to claim 1, characterized in that, The specific steps for calculating the high and low thresholds for edge detection based on the gradient magnitude distribution of all identified sub-crack pixels are as follows: Get the number of all secondary crack pixels in the sliding window corresponding to each connected pixel, and record it as the first number; get the total number of all secondary crack pixels in the sliding window corresponding to all connected pixels, and record it as the second number; use the ratio between the first number and the second number as the weight of the sliding window corresponding to the connected pixel; The first product is the product of the maximum gradient magnitude of the secondary crack pixel within the sliding window corresponding to the connected pixel and the weight of the corresponding sliding window. This first product is accumulated across the sliding windows corresponding to the connected pixels to obtain the high threshold. The second product is the product of the minimum gradient magnitude of the secondary crack pixel within the sliding window corresponding to the connected pixel and the weight of the corresponding sliding window. This second product is accumulated across the sliding windows corresponding to the connected pixels to obtain the low threshold.
9. The crack detection method for water conservancy pipelines according to claim 1, characterized in that, The specific steps involved in re-performing edge detection on the internal grayscale image using the high and low thresholds and calculating the proportion of abnormal pixels are as follows: Pixels with gradient magnitudes greater than or equal to the high threshold in the grayscale image inside the drainage pipe are classified as main cracks, while pixels with gradient magnitudes greater than or equal to the low threshold and less than the high threshold in the grayscale image inside the drainage pipe are classified as secondary cracks. Calculate the proportion of the number of main crack pixels in the grayscale image inside the drainage pipe to the total number of pixels in the grayscale image inside the drainage pipe, denoted as H1. Calculate the proportion of the number of secondary crack pixels in the grayscale image inside the drainage pipe to the total number of pixels in the grayscale image inside the drainage pipe, denoted as H2. Preset the first weight W1, and preset the second weight W2; Percentage of abnormal pixels in grayscale images of the inside of drainage pipes .
10. The crack detection method for water conservancy pipelines according to claim 1, characterized in that, The anomaly detection based on the comparison result of this proportion and the preset threshold includes the following specific steps: When the percentage of abnormal pixels in the grayscale image inside the drainage pipe At this time, the grayscale image inside the drainage pipe shows a high degree of abnormality, requiring inspection; when the percentage of abnormal pixels in the grayscale image inside the drainage pipe is high... At that time, the anomaly level of the grayscale image inside the drainage pipe was small, and no maintenance was required. This is a preset threshold.