A water gauge water level line detection method and device
By optimizing the Bézier curve model and feature offset module, and combining the CIOU loss function and classification prior branch, the accuracy and speed problems of traditional water level detection methods in complex environments are solved, and efficient automatic water level identification is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA TELECOM DIGITAL INTELLIGENCE TECH CO LTD
- Filing Date
- 2022-09-05
- Publication Date
- 2026-06-05
AI Technical Summary
Existing water level detection methods struggle to accurately identify water level lines in complex environments such as uneven lighting and water surface reflections. Traditional image processing methods are not precise enough and are slow.
A water level detection model based on Bézier curves is adopted. The feature offset identification module optimizes the fitting deviation of control points and curve features. Multi-task learning is carried out by combining CIOU loss function and classification prior branch to improve the accuracy and speed of the model.
It enables high-precision and rapid automatic identification of water level lines in complex environments, improving the accuracy and efficiency of water level line detection.
Smart Images

Figure CN115482410B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of artificial intelligence technology, and in particular relates to a method and device for detecting water level lines. Background Technology
[0002] Water level information plays a vital role in water conservancy, water transport, flood control and drought relief, and other hydrological data forecasting. Manually reading water level gauges is the traditional method for obtaining water level information, but it suffers from inaccuracies and dangers associated with human visual identification, as well as the inability to observe water levels during severe weather. Visual algorithms can largely avoid these problems.
[0003] The visual algorithm for water level detection is a crucial step in calculating water level readings. Previous techniques relied on overly simplistic and inaccurate image grayscale value calculations or slow image segmentation models to segment multiple key points along the water level to determine its location. Both methods have inherent limitations. Furthermore, traditional methods struggle to accurately locate the correct water level in complex situations such as uneven lighting or water surface reflections. Summary of the Invention
[0004] The main objective of this invention is to overcome the shortcomings and deficiencies of the prior art and provide a method and device for detecting water level lines, which can automatically identify the position of the water level line with high accuracy.
[0005] According to one aspect of the present invention, a method for detecting water level lines is provided, the method comprising the following steps:
[0006] S1: Collect water level image data from the water gauge, process the image data, and obtain processed water level data from the water gauge.
[0007] S2: Based on the processed water level data, construct a water level detection model, train the water level detection model, and save the model parameters;
[0008] S3: Receive the input image of the water level line to be detected, calculate the position of the water level line according to the water level line detection model, and output the detection result.
[0009] Preferably, the process of processing the image data to obtain the processed water level data includes:
[0010] The image data is segmented into a matrix containing pixel blocks, the matrix is scanned and classified, and the row and column positions of the waterline pixels in the matrix are marked.
[0011] Preferably, the step of constructing a water level detection model based on the processed water gauge data includes:
[0012] Based on the processed water level data, a water level detection model based on Bézier curves is constructed. The water level detection model includes a feature offset identification module, which optimizes the fitting deviation of the control points and curve features of the Bézier curve.
[0013] Preferably, the model loss function of the water level detection model based on Bézier curves is:
[0014] L total =αL reg +βL CIOU +γL cls
[0015] in,
[0016]
[0017]
[0018]
[0019] Where α, β, and γ are the weight proportions of the loss function, with values ranging from [0,1], n is the number of samples, IOU represents the ratio of the area of the overlapping region of the two rectangles to the area of the union of the two rectangles, the two rectangles represent the minimum bounding rectangles of the curves established by the model output control points; b is the center point of the minimum bounding rectangle of the curves established by the model output control points, ρ(·) is the Euclidean distance, c is the distance between the diagonals of the minimum bounding rectangles of the two curves, w and h are the width and height of the two rectangles, respectively, P O P1, P2, and P3 are the control points of the curve, gt indicates that the data is labeled, and B(t) represents the Bézier curve model. P represents the output of the Bézier curve model; i and T i Let L be the classification result vectors of the model output and the ground truth labeled i-th column anchor, respectively; CE (P i ,T i ) represents the cross-entropy loss of the i-th classifier.
[0020] Preferably, calculating the position of the water level line based on the water gauge water level line detection model includes:
[0021] Based on the input water level image from the water gauge, the trained model is used to calculate the control points of the Bézier curve of the water level. The model curve function is determined based on the control points, and the position of the water level is calculated using the curve function and the water gauge detection results.
[0022] According to another aspect of the present invention, the present invention also provides a water level detection device, the device comprising:
[0023] The processing module is used to collect water level line image data, process the image data, and obtain processed water level line data.
[0024] The construction module is used to construct a water level detection model based on the processed water level data, train the water level detection model, and save the model parameters.
[0025] The detection module is used to receive the input image of the water level line to be detected by the water gauge, calculate the position of the water level line according to the water level line detection model, and output the detection result.
[0026] Preferably, the processing module processes the image data to obtain processed water level data, including:
[0027] The image data is segmented into a matrix containing pixel blocks, the matrix is scanned and classified, and the row and column positions of the waterline pixels in the matrix are marked.
[0028] Preferably, the construction module constructs a water level detection model based on the processed water level data, including:
[0029] Based on the processed water level data, a water level detection model based on Bézier curves is constructed. The water level detection model includes a feature offset identification module, which optimizes the fitting deviation of the control points and curve features of the Bézier curve.
[0030] Preferably, the model loss function of the water level detection model based on Bézier curves is:
[0031] L total =αL reg +βL CIOU +γL cls
[0032] in,
[0033]
[0034]
[0035]
[0036] Where α, β, and γ are the weight proportions of the loss function, with values ranging from [0,1], n is the number of samples, IOU represents the ratio of the area of the overlapping region of the two rectangles to the area of the union of the two rectangles, the two rectangles represent the minimum bounding rectangles of the curves established by the model output control points; b is the center point of the minimum bounding rectangle of the curves established by the model output control points, ρ(·) is the Euclidean distance, c is the distance between the diagonals of the minimum bounding rectangles of the two curves, w and h are the width and height of the two rectangles, respectively, P O P1, P2, and P3 are the control points of the curve, gt indicates that the data is labeled, and B(t) represents the Bézier curve model. P represents the output of the Bézier curve model; i and T i Let L be the classification result vectors of the model output and the ground truth labeled i-th column anchor, respectively; CE (P i ,T i ) represents the cross-entropy loss of the i-th classifier.
[0037] Preferably, the detection module calculates the position of the water level line based on the water gauge water level line detection model, including:
[0038] Based on the input water level image from the water gauge, the trained model is used to calculate the control points of the Bézier curve of the water level. The model curve function is determined based on the control points, and the position of the water level is calculated using the curve function and the water gauge detection results.
[0039] Beneficial Effects: This invention improves model convergence by replacing polynomial parameters with Bézier curve parameters. For Bézier curve parameter optimization, a feature offset identification module is designed to optimize control point identification and curve feature fitting bias. Regarding the loss function, sampling points are used instead of control points for loss calculation, and the CIOU loss based on the minimum bounding rectangle of the curve is added to further improve the accuracy of the loss function. This invention can automatically identify the position of the water level line with high accuracy. The classification prior branch of the column anchor is an important structure for improving model performance. During training, it replaces the segmentation network in conjunction with the Bézier curve branch for multi-task learning, providing prior knowledge and feature fusion for curve modeling and accelerating model convergence.
[0040] The features and advantages of the present invention will become clear from the following accompanying drawings and a detailed description of specific embodiments thereof. Attached Figure Description
[0041] Figure 1 This is a flowchart of the water level gauge detection method;
[0042] Figure 2 This is a schematic diagram of a Bézier curve;
[0043] Figure 3 This is a diagram illustrating rightward max pooling.
[0044] Figure 4 This is a schematic diagram of the feature offset identifiable module structure;
[0045] Figure 5 This is a schematic diagram of scanning the pixel matrix column by column (column anchoring);
[0046] Figure 6 This is a schematic diagram of the detection model structure based on Bézier curves;
[0047] Figure 7 This is a schematic diagram of the water level gauge detection device. Detailed Implementation
[0048] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0049] Example 1
[0050] Figure 1 This is a flowchart of the water level gauge detection method. (For example...) Figure 1 As shown, the present invention provides a method for detecting water level lines using a water gauge, the method comprising the following steps:
[0051] S1: Collect water level image data from the water gauge, process the image data, and obtain processed water level data from the water gauge.
[0052] Specifically, video data captured by a water level camera is collected, video frames are split, and a detection model is used to detect water level lines. Data sets are then created by collecting cropped images of the water level lines.
[0053] Preferably, the process of processing the image data to obtain the processed water level data includes:
[0054] The image data is segmented into a matrix containing pixel blocks, the matrix is scanned and classified, and the row and column positions of the waterline pixels in the matrix are marked.
[0055] Specifically, the image data is segmented into a matrix containing pixel blocks, and this matrix is labeled as a column anchor. The least squares method is used to fit the control points of a Bézier curve using curve keypoint information for data annotation. This annotates the row and column positions of the waterline pixels within the column anchors and the keypoint information of the waterline curve. For curve datasets, control points cannot be annotated, so the data here is manually annotated as keypoints on the curve (i.e., annotations for the segmentation method). Based on the above description of keypoint annotation (its purpose being that control points cannot be manually annotated), the model needs control points as output and for calculating loss. Therefore, the least squares method is used here to fit the Bézier curve control point equation using manually annotated keypoints (sampling points).
[0056] like Figure 5 As shown, the waterline image is segmented into w*h pixel blocks. A column anchor is used to scan each column, and the pixel blocks in each column are classified to determine whether they contain a waterline. The classification branch can effectively learn the actual image features of the waterline, reducing the optimization difficulty of the curve equation regression.
[0057] The classification branch itself outputs a w*(h+1) dimensional feature map, where each element represents the probability of the waterline's presence at a given location in a column anchor. An additional dimension is used to indicate the absence of a waterline in that column anchor. Furthermore, the waterline is segmented by multiple blocks, with the block containing more pixels determining the waterline's location. If a column anchor contains multiple waterline pixels, the waterline grid markers that can be connected to adjacent column anchors are selected to train the maximum probability output.
[0058] S2: Based on the processed water level data, construct a water level detection model, train the water level detection model, and save the model parameters.
[0059] Preferably, the step of constructing a water level detection model based on the processed water gauge data includes:
[0060] Based on the processed water level data, a water level detection model based on Bézier curves is constructed. The water level detection model includes a feature offset identification module, which optimizes the fitting deviation of the control points and curve features of the Bézier curve.
[0061] Specifically, such as Figure 2 As shown, this embodiment uses a third-order Bézier curve as the optimization objective, taking into account both the optimization difficulty and the achievable accuracy of the model representation. The curve equation is:
[0062] B(t)=P0(1-t) 3 +3P1t(1-t) 2 +3P2t 2 (1-t)+P3t 3 ,t∈[0,1]
[0063] Among them, PO, P1, P2, and P3 are curve control points.
[0064] For Bézier curve modeling, although the control points are located at the true coordinates on the image, the pixel features at those coordinates do not represent the curve itself. When the control point positions deviate significantly, the model struggles to learn the correct curve modeling. To address this, this embodiment designs a feature offset recognition module. First, deformable convolutions are used to flexibly expand the receptive field. By learning a two-dimensional offset, the convolution kernel can use feature values of arbitrary shapes as input, thus better capturing the curve's inherent features. Furthermore, a max-pooling layer with directional retrieval is used to obtain the activation values on the true curve. For example... Figure 3 As shown, taking rightward max pooling as an example, the pooling operation output is filled with the maximum value that can be retrieved by searching to the right from the current value. At this time, the activation value on the curve can be passed to the left.
[0065] The overall structure of the feature offset identification module is as follows: Figure 4 As shown, the feature map undergoes deformable convolution, followed by max pooling in four directions, and then feature concatenation for output, which is then used for the remaining convolution operations. Specifically, for special scenarios such as water levels, where the control points are located in a single orientation along the water level, the directions for max pooling can be reduced to decrease model parameters.
[0066] Preferably, the model loss function of the water level detection model based on Bézier curves is:
[0067] L total =αL reg +βL CIOU +γL cls
[0068] in,
[0069]
[0070]
[0071]
[0072] Where α, β, and γ are the weight proportions of the loss function, with values ranging from [0,1], n is the number of samples, IOU represents the ratio of the area of the overlapping region of the two rectangles to the area of the union of the two rectangles, the two rectangles represent the minimum bounding rectangles of the curves established by the model output control points; b is the center point of the minimum bounding rectangle of the curves established by the model output control points, ρ(·) is the Euclidean distance, c is the distance between the diagonals of the minimum bounding rectangles of the two curves, w and h are the width and height of the two rectangles, respectively, P O P1, P2, and P3 are the control points of the curve, gt indicates that the data is labeled, and B(t) represents the Bézier curve model. P represents the output of the Bézier curve model; i and T i Let L be the classification result vectors of the model output and the ground truth labeled i-th column anchor, respectively; CE (P i ,T i ) represents the cross-entropy loss of the i-th classifier. Where, L reg For the regression loss sampling of the control points of the curve, L CIOU L is the minimum bounding box loss of the curve. cls The column anchor is the classification prior branch for classification loss. This classification prior branch is a crucial structure for improving model performance. During training, it replaces the segmentation network in conjunction with the Bézier curve branch for multi-task learning, providing prior information and feature fusion for curve modeling, thus accelerating model convergence.
[0073] Specifically, in this embodiment, the regression branch loss is calculated using the L1 loss of the curve sampling points, which more closely approximates the true curve error:
[0074]
[0075] The number of samples is n = 20.
[0076] For curve recognition scenarios, t values are sampled uniformly between 0 and 1. Specifically for water level recognition scenarios, more sampling points are used at the bottom of the water level line to improve the accuracy of water level recognition.
[0077] Furthermore, considering the overall curve recognition bias and the convex hull property of the Bézier curve, the CIOU loss is calculated for the minimum bounding rectangle of the curve:
[0078]
[0079] Where IOU is the intersection-union ratio of the rectangle areas, b is the center point of the rectangle, ρ(·) is the Euclidean distance, c is the distance between the diagonals of the least circumscribed rectangles of the two rectangles, and w and h are the width and height of the rectangles, respectively.
[0080] The final classification prior branch loss is obtained by summing w cross-entropy losses:
[0081]
[0082] Where w is the number of column anchors, L CE (P i ,T i ) represents the cross-entropy loss of the i-th classifier.
[0083] like Figure 6 As shown, the model uses shallow features from ResNet as the backbone. In the Bézier curve parametric regression branch, the features are processed through convolutional layers to output a one-dimensional vector, yielding the final Bézier curve control point result. In the column anchor-based classification prior branch, the features are processed through convolution, fully connected layers, and reshaping to obtain the final n*n dimensional feature map for column anchor classification. The final model loss function is:
[0084] L total =αL reg +βL CIOU +γL cls
[0085] α, β, and γ are weighting coefficients. Preferably, α = 0.5, β = 0.25, and γ = 0.25.
[0086] Furthermore, unlike segmentation models, the classification branch does not perform multiple rounds of upsampling and pixel-level classification, which greatly improves inference speed. Therefore, while conducting multi-task joint learning, the image semantic features of the classification branch and the prior features of the curve classification box position can be fused into the Bézier curve parameter regression branch in the form of spatial attention, further improving model performance.
[0087] S3: Receive the input image of the water level line to be detected, calculate the position of the water level line according to the water level line detection model, and output the detection result.
[0088] Preferably, calculating the position of the water level line based on the water gauge water level line detection model includes:
[0089] Based on the input water level image from the water gauge, the trained model is used to calculate the control points of the Bezier curve of the water level. The model curve function is determined based on the control points, and the position of the water level is calculated using the curve function and the water gauge detection results.
[0090] Specifically, to further enhance the semantic information of the regression equation, the image is divided into an average of n*n blocks. A column anchor is used to classify each block, with the classification result indicating the presence or absence of waterline pixels. The classification results from the column anchor are then used in conjunction with curve regression for joint multi-task learning. Simultaneously, classification features are used as priors to fuse with curve branch features for computation.
[0091] This embodiment improves model convergence by using Bézier curve parameters instead of polynomial parameters. For Bézier curve parameter optimization, a feature offset identification module is designed to optimize control point identification and curve feature fitting deviation. Regarding the loss function, sampling points are used instead of control points for loss calculation, and the CIOU loss based on the minimum bounding rectangle of the curve is added to further improve the accuracy of the loss function. This invention can automatically identify the position of the water level line with high accuracy.
[0092] Example 2
[0093] Figure 7 This is a schematic diagram of the water level gauge detection device. Figure 7 As shown, the present invention also provides a water level detection device, the device comprising:
[0094] Processing module 701 is used to collect water level line image data, process the image data, and obtain processed water level line data.
[0095] The construction module 702 is used to construct a water level detection model based on the processed water level data, train the water level detection model, and save the model parameters.
[0096] The detection module 703 is used to receive the input image of the water level line to be detected, calculate the position of the water level line according to the water level line detection model, and output the detection result.
[0097] Preferably, the processing module 701 processes the image data to obtain processed water level data, including:
[0098] The image data is segmented into a matrix containing pixel blocks, the matrix is scanned and classified, and the row and column positions of the waterline pixels in the matrix are marked.
[0099] Preferably, the construction module 702 constructs a water level detection model based on the processed water gauge data, including:
[0100] Based on the processed water level data, a water level detection model based on Bézier curves is constructed. The water level detection model includes a feature offset identification module, which optimizes the fitting deviation of the control points and curve features of the Bézier curve.
[0101] Preferably, the model loss function of the water level detection model based on Bézier curves is:
[0102] L total =αL reg +βL CIOU +γL cls
[0103] in,
[0104]
[0105]
[0106]
[0107] Where α, β, and γ are the weight proportions of the loss function, with values ranging from [0,1], n is the number of samples, IOU represents the ratio of the area of the overlapping region of the two rectangles to the area of the union of the two rectangles, the two rectangles represent the minimum bounding rectangles of the curves established by the model output control points; b is the center point of the minimum bounding rectangle of the curves established by the model output control points, ρ(·) is the Euclidean distance, c is the distance between the diagonals of the minimum bounding rectangles of the two curves, w and h are the width and height of the two rectangles, respectively, P O P1, P2, and P3 are the control points of the curve, gt indicates that the data is labeled, and B(t) represents the Bézier curve model. P represents the output of the Bézier curve model; i and T i Let L be the classification result vectors of the model output and the ground truth labeled i-th column anchor, respectively; CE (P i ,T i ) represents the cross-entropy loss of the i-th classifier. Where, L reg For the regression loss sampling of the control points of the curve, L CIOU L is the minimum bounding box loss of the curve. cls The column anchor is the classification prior branch for classification loss. This classification prior branch is a crucial structure for improving model performance. During training, it replaces the segmentation network in conjunction with the Bézier curve branch for multi-task learning, providing prior information and feature fusion for curve modeling, thus accelerating model convergence.
[0108] Preferably, the detection module 703 calculates the position of the water level line based on the water gauge water level line detection model, including:
[0109] Based on the input water level image from the water gauge, the trained model is used to calculate the control points of the Bezier curve of the water level. The model curve function is determined based on the control points, and the position of the water level is calculated using the curve function and the water gauge detection results.
[0110] The specific implementation process of the functions implemented by each module in this embodiment 2 is the same as the implementation process of each step in embodiment 1, and will not be repeated here.
[0111] The above description is only a preferred embodiment of the present invention and does not limit the patent scope of the present invention. All equivalent structural transformations made under the concept of the present invention using the contents of the present invention specification and drawings, or direct / indirect applications in other related technical fields, are included within the patent protection scope of the present invention.
Claims
1. A method for detecting water level lines using a water gauge, characterized in that, The method includes the following steps: S1: Collect water level image data from the water gauge, process the image data, and obtain processed water level data from the water gauge. S2: Based on the processed water level data, construct a water level detection model, train the water level detection model, and save the model parameters; S3: Receive the input image of the water level line to be detected, calculate the position of the water level line according to the water level line detection model, and output the detection result; The process of processing the image data to obtain the processed water level data includes: The image data is segmented into a matrix containing pixel blocks, the matrix is scanned and classified, and the row and column positions of the waterline pixels in the matrix are marked. The step of constructing a water level detection model based on the processed water gauge data includes: Based on the processed water level data, a water level detection model based on Bézier curves is constructed. The water level detection model includes a feature offset identification module, which optimizes the fitting deviation of the control points and curve features of the Bézier curve.
2. The method according to claim 1, characterized in that, The model loss function of the water level detection model based on Bézier curves is: in, , , , in, is the weighting percentage of the loss function, with a value range of [0,1], n is the number of samples, IOU represents the ratio of the area of the overlapping region of the two rectangles to the area of the union of the two rectangles, where the two rectangles represent the minimum bounding rectangle of the curve established by the model output control points; b is the center point of the minimum bounding rectangle of the curve established by the model output control points. Let c be the Euclidean distance, where c is the distance between the diagonals of the least circumscribed rectangles of the two curves, w and h are the width and height of the two rectangles, respectively, and P is the distance between the diagonals of the rectangles. O P1, P2, and P3 are the control points of the curve, gt indicates that the data is labeled, and B(t) represents the Bézier curve model. P represents the output of the Bézier curve model; i and T i These are the classification result vectors for the i-th column anchor, which are respectively the model output and the ground truth annotations. Let be the cross-entropy loss of the i-th classifier.
3. The method according to claim 2, characterized in that, The step of calculating the position of the water level line based on the water level detection model includes: Based on the input water level image from the water gauge, the trained model is used to calculate the control points of the Bezier curve of the water level. The model curve function is determined based on the control points, and the position of the water level is calculated using the curve function and the water gauge detection results.
4. A water level detection device, characterized in that, The device includes: The processing module is used to collect water level line image data, process the image data, and obtain processed water level line data. The construction module is used to construct a water level detection model based on the processed water level data, train the water level detection model, and save the model parameters. The detection module is used to receive the input image of the water level line to be detected, calculate the position of the water level line according to the water level line detection model, and output the detection result. The processing module processes the image data to obtain processed water level data, including: The image data is segmented into a matrix containing pixel blocks, the matrix is scanned and classified, and the row and column positions of the waterline pixels in the matrix are marked. The construction module, based on the processed water level data, constructs a water level detection model, including: Based on the processed water level data, a water level detection model based on Bézier curves is constructed. The water level detection model includes a feature offset identification module, which optimizes the fitting deviation of the control points and curve features of the Bézier curve.
5. The apparatus according to claim 4, characterized in that, The model loss function of the water level detection model based on Bézier curves is: in, , , , in, is the weighting percentage of the loss function, with a value range of [0,1], n is the number of samples, IOU represents the ratio of the area of the overlapping region of the two rectangles to the area of the union of the two rectangles, where the two rectangles represent the minimum bounding rectangle of the curve established by the model output control points; b is the center point of the minimum bounding rectangle of the curve established by the model output control points. Let c be the Euclidean distance, where c is the distance between the diagonals of the least circumscribed rectangles of the two curves, w and h are the width and height of the two rectangles, respectively, and P is the distance between the diagonals of the rectangles. O P1, P2, and P3 are the control points of the curve, gt indicates that the data is labeled, and B(t) represents the Bézier curve model. P represents the output of the Bézier curve model; i and T i These are the classification result vectors for the i-th column anchor, which are respectively the model output and the ground truth annotations. Let be the cross-entropy loss of the i-th classifier.
6. The apparatus according to claim 5, characterized in that, The detection module calculates the position of the water level line based on the water gauge water level line detection model, including: Based on the input water level image from the water gauge, the trained model is used to calculate the control points of the Bezier curve of the water level. The model curve function is determined based on the control points, and the position of the water level is calculated using the curve function and the water gauge detection results.