A water level recognition method in complex scenes

Through the water level detection method based on machine learning and deep learning, combined with template matching and deep learning semantic segmentation technology, the problem of poor generalization ability of traditional water level detection in complex scenes has been solved, and high-precision and reliable water level monitoring has been achieved, adapting to Different environments and lighting conditions.

CN118379612BActive Publication Date: 2024-09-06WUHAN DASHUIYUN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410828244.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-25
Publication Date
2024-09-06
Estimated Expiration
2044-06-25

AI Technical Summary

Technical Problem

Traditional water level detection methods have poor generalization capabilities in complex scenarios and cannot adapt to different measurement points and environmental changes. In particular, it is difficult to install a water gauge under outdoor conditions and is greatly affected by factors such as light, storms, and rain, resulting in loss of accuracy.

Method used

Methods based on traditional machine learning and deep learning are used to calibrate and correct the water level detection image, select an appropriate water level calculation method, use the elevation fitting function to calculate the water surface elevation value, and combine template matching, target detection and deep learning semantic segmentation technology to adapt to different needs. lighting conditions and complex environments.

Benefits of technology

It improves the generalization ability and accuracy of water level detection, reduces the accuracy loss caused by external environmental factors, realizes high-precision and high-reliability water level identification and measurement, and adapts to complex scenes and changing conditions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118379612B
    Figure CN118379612B
Patent Text Reader

Abstract

The present invention provides a water level recognition method in a complex scene, which relates to the field of image recognition technology, and includes the following steps: S1: selecting a calibration image and collecting a test image at the same time; S2: preprocessing the test image, and using the calibration image to correct the preprocessed test image to obtain a registration image; S3: acquiring a water level scene, selecting a preset recognition method according to the water level scene, and using the preset recognition method to perform water level recognition on the registration image to obtain water level line position information; S4: inputting the water level line position information into an elevation fitting function, and calculating the water level information of the test image. The present invention can learn water area information under different lighting conditions, has better generalization ability, and can adapt to the detection needs of different measuring points.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image recognition, and in particular to a water level recognition method in complex scenes. Background Art

[0002] In the vast water conservancy industry, water level detection, as a common and very important demand, has become one of the key tasks in related fields. At present, water level detection mainly relies on a variety of different technical means for monitoring, including the use of float, pressure sensor, ultrasonic, radar and laser water level meters. In the context of the rapid development of science and technology today, with the continuous advancement of computer vision technology, water level recognition methods based on video and image processing have gradually begun to receive more widespread attention and application. However, traditional methods may require customized adjustments and parameter settings when dealing with different measuring points and environments, and do not have good generalization capabilities.

[0003] Patent document CN110443243A discloses a water level recognition method based on a water gauge. This method uses character information on the water gauge to determine the range of the water level, thereby performing rough positioning. Then, the water level line is accurately positioned using traditional methods. However, this method requires the installation of a water gauge, and does not take into account the possible obstruction of the water gauge or the inconvenience of installing the water gauge in complex outdoor scenes, and its generalization ability is poor. Summary of the invention

[0004] In view of this, the present invention provides a water level recognition method in complex scenes, which uses a method based on traditional machine learning and deep learning to calibrate and correct the water level detection image, and then selects a suitable water level calculation method according to the usage scenario to obtain the water level line information, and finally calculates the water surface elevation value in the collected image according to the elevation fitting function. It can learn the water area information under different lighting conditions, has better generalization ability, and can adapt to the detection needs of different measuring points.

[0005] The technical purpose of the present invention is achieved in this way:

[0006] The present invention provides a water level recognition method in a complex scene, comprising the following steps:

[0007] S1: Select the calibration image and collect the image to be tested at the same time;

[0008] S2: preprocessing the image to be tested, and using the calibration image to correct the preprocessed image to obtain a registered image;

[0009] S3: Acquire a water level scene, select a preset recognition method according to the water level scene, use the preset recognition method to perform water level recognition on the registration image, and obtain water level line position information;

[0010] S4: Input the water level line position information into the elevation fitting function to calculate the water level information of the image to be tested.

[0011] On the basis of the above technical solution, preferably, the water level scene is a scene with a physical water gauge or a scene without a physical water gauge.

[0012] On the basis of the above technical solution, preferably, when the water level scene is a scene with a physical water gauge, the preset recognition method includes a template matching method and a target detection method.

[0013] On the basis of the above technical solution, preferably, when the water level scene is a scene without a physical water gauge, the preset recognition method is a deep learning semantic segmentation method based on a virtual water gauge.

[0014] On the basis of the above technical solution, preferably, the template matching method is:

[0015] Select a picture containing a physical water ruler as a template image T;

[0016] Use the registered image as the search image S;

[0017] Starting from the upper left corner of the search image S, slide the template image T in the horizontal and vertical directions with a preset step size. For each position where the template image T slides, the sub-image of the search image S covered by it is recorded as I;

[0018] The normalized cross-correlation method is used to measure the similarity between I and T. The I with the greatest similarity to T is taken as the target area. According to the location information of the target area, the water level position information is obtained.

[0019] On the basis of the above technical solution, preferably, the target detection method is:

[0020] Collect pictures containing physical water gauges at multiple measuring points, annotate them to create a data set, and preprocess the data set;

[0021] Construct the Yolov5 network model and set initial anchor boxes of different scales and aspect ratios according to the target size distribution of the data set;

[0022] Use the data set to train the Yolov5 network model until the loss converges to obtain the trained Yolov5 network model;

[0023] Use the trained Yolov5 network model to detect the registered image, and take the one with the highest confidence as the detection result for each detected water gauge bounding box;

[0024] According to the position of the water gauge bounding box in the detection result, the water level line position information is obtained.

[0025] Based on the above technical solution, preferably, the training process of the Yolov5 network model is:

[0026] The Yolov5 network model is trained on the basis of the initial anchor box to obtain the predicted box, and the predicted box is matched with the real box:

[0027] For each true box, the predicted boxes in the grid where it is located and the adjacent grids are used as candidate predicted boxes. The true box and the candidate predicted boxes are matched according to the matching conditions. If they match, the candidate predicted box is used as a positive sample, and the position information of the candidate predicted box is calculated by the prediction box regression formula. If they do not match, the candidate predicted box is used as a negative sample.

[0028] Calculate the positioning loss, confidence loss and classification loss of the positive sample and the true box, where the confidence of the true box matched by the positive sample is the intersection and union ratio of the true box and the positive sample; calculate the confidence loss of the negative sample and the true box, and the confidence of the true box matched by the negative sample is 0;

[0029] The parameters of the Yolov5 network model are iteratively adjusted through back propagation until the loss converges, that is, the training is completed, and the trained Yolov5 network model is obtained.

[0030] On the basis of the above technical solution, preferably, the matching condition is that the ratio of the width of the real frame to the width of the candidate prediction frame and the ratio of the height of the real frame to the height of the candidate prediction frame are both greater than 1 / 4 and less than 4, that is, the following formulas are satisfied at the same time: ;

[0031] Where GT_W is the width of the real box, GT_H is the height of the real box, Anchor_W is the width of the candidate prediction box, and Anchor_H is the height of the candidate prediction box.

[0032] Based on the above technical solution, preferably, the prediction box regression formula is: ;

[0033] Where, t x ,t y is the center point coordinate offset of the prediction box, t w ,t h is the width and height offset of the prediction box, c x 、c y is the distance from the upper left corner of the grid, b x , b y are the center point coordinates of the prediction box, b w , b h are the width and height of the prediction box respectively, and σ is the sigmoid function.

[0034] On the basis of the above technical solution, preferably, the deep learning semantic segmentation method based on the virtual water level gauge is:

[0035] Collect sample images and perform data enhancement on the sample images to form a training sample set;

[0036] Build a Unet++ model, and use the training sample set to train the Unet++ model to obtain the trained Unet++ model;

[0037] The registered images are input into the trained Unet++ model to form a waterside boundary map;

[0038] Manually calibrate the registered images to obtain a virtual water ruler, and determine the search area of ​​the water level line based on the virtual water ruler;

[0039] In the search area of ​​the water level line, the water bank boundary map is traversed to search for the longest continuous horizontal line in the water bank boundary map, which is the water level line;

[0040] The water level line is matched with the virtual water gauge to obtain the water level line position information.

[0041] On the basis of the above technical solution, preferably, the elevation fitting function is: ;

[0042] In the formula, x w is the pixel value corresponding to the water level position information, h(x w ) is the water level; [θ0,θ1,θ2,...,θ n ] is the solution weight of the elevation fitting function, which is obtained by linear regression training based on the calibration image. The loss function of linear regression is: ;

[0043] in represents [θ0,θ1,θ2,...,θ n ], m is the number of calibrated heights, x i is the i-th pixel value of the calibration image, h(x i ) is the height fitting function for x i The predicted elevation, y i For x i The corresponding calibration elevation.

[0044] Based on the above technical solution, preferably, step S2 includes:

[0045] S21: Using the VGG network to extract features from the calibration image and the image to be tested, to obtain a calibration feature map and a feature map to be tested;

[0046] S22: using a deep nearest neighbor search algorithm to find the point on the feature map to be tested that best matches each feature point of the calibration feature map, to form the best matching point pair;

[0047] S23: Counting the average displacements of all the best matching point pairs in the horizontal and vertical directions to obtain the offset of the image to be tested relative to the calibration image, and performing affine transformation on the image to be tested according to the offset to obtain the registration image.

[0048] Based on the above technical solution, preferably, step S22 includes:

[0049] S221: Select a feature point pA in the calibration feature map FA;

[0050] S222: Using a deep nearest neighbor search algorithm on the feature graph FB to be tested, find the feature point pB that is most similar to pA as the best matching point of pA, and at the same time, find the feature point that is second most similar to pA as the second best matching point pB' of pA;

[0051] S223: Calculate the Euclidean distance d1 between pA and its best matching point pB, and the Euclidean distance d2 between pA and its second best matching point pB';

[0052] S224: If d1 / d2 is less than a preset threshold, pA and pB are considered to match and are regarded as a best matching point pair;

[0053] S225: Repeat steps S221-S224 until all feature points in the calibration feature map FA are matched, and the final best matching point pair is obtained.

[0054] On the basis of the above technical solution, preferably, step S2 further includes hierarchical optimization matching, and the process is as follows:

[0055] Starting from the highest layer n of the VGG network, a deep nearest neighbor search algorithm is used to perform feature matching on the feature map output by the nth layer;

[0056] Using the feature matching results of the nth layer, the search range of the deep nearest neighbor search algorithm of the feature map output by the n-1th layer is narrowed down to obtain the feature matching results of the feature map output by the n-1th layer;

[0057] The above process is repeated, and the feature matching results of each time are used to guide the matching of the next layer until the bottom layer of the VGG network is reached.

[0058] The method of the present invention has the following beneficial effects compared with the prior art:

[0059] (1) The present invention uses a method based on traditional machine learning and deep learning to calibrate and correct the water level detection image, then selects a suitable water level calculation method according to the usage scenario to obtain the water level line information, and finally calculates the water surface elevation value in the collected image according to the elevation fitting function. It can learn the water area information under different lighting conditions, has better generalization ability, and can adapt to the detection needs of different measuring points;

[0060] (2) The present invention has made detailed considerations for outdoor water level detection scenarios and various complex and changeable weather environments, and has made corresponding optimizations and improvements to the jitter, offset and other phenomena that are prone to occur in image acquisition devices when encountering severe weather such as strong winds and rainstorms. By using feature matching methods, the collected images are accurately corrected and calibrated. This processing step not only provides solid support for subsequent water level elevation fitting, but also significantly reduces the accuracy loss that may be caused by external environmental factors, ensuring that the water level detection results are more accurate and reliable;

[0061] (3) The present invention can realize high-precision and high-reliability water level recognition and measurement in a variety of complex scenarios. The pixel position is converted into the actual water level height through the elevation fitting function, which ensures the effectiveness, real-time and accuracy of monitoring, adapts to different conditions such as changing environment, changing lighting, and complex background, and greatly improves the adaptability and scalability of the water level monitoring system. BRIEF DESCRIPTION OF THE DRAWINGS

[0062] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0063] Figure 1 is a flow chart of a method according to an embodiment of the present invention;

[0064] Figure 2 This is a technical implementation diagram of an embodiment of the present invention. DETAILED DESCRIPTION

[0065] The following will be combined with the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0066] like Figure 1As shown, the present invention provides a water level recognition method in a complex scene, comprising the following steps:

[0067] S1: Select the calibration image and collect the image to be tested at the same time;

[0068] S2: preprocessing the image to be tested, and using the calibration image to correct the preprocessed image to obtain a registered image;

[0069] S3: Acquire a water level scene, select a preset recognition method according to the water level scene, use the preset recognition method to perform water level recognition on the registration image, and obtain water level line position information;

[0070] S4: Input the water level line position information into the elevation fitting function to calculate the water level information of the image to be tested.

[0071] like Figure 2 As shown, the technical implementation process of the present invention is: 1) select a calibration image, collect the image to be tested, and use these two images as input images; 2) pre-process the input image, that is, correct the image to be tested according to the calibration image to form a registration image; 3) judge the water level scene of the current image to be tested, that is, whether there is a physical water gauge. The water level scene is divided into a scene with a physical water gauge or a scene without a physical water gauge according to whether there is a physical water gauge. When there is no physical water gauge, it is necessary to manually calibrate the virtual water gauge for subsequent water level recognition; 4) For scenes with a physical water gauge, the water gauge template matching method or the deep learning water gauge target detection method can be used to identify the water level line position information; 5) For scenes without a physical water gauge, first calibrate the virtual water gauge, perform shoreline segmentation according to the deep learning model, extract the water-shore boundary line, and obtain the water level line position information through the correspondence between the water-shore boundary line and the virtual water gauge; 6) According to the identified water level line position information, post-process it, that is, substitute it into the elevation fitting function, Fitting calculation is performed to obtain the water level elevation of the current image to be tested; 7) Output the calculated water level elevation.

[0072] According to the technical implementation process described above, the present invention sets the following series of embodiments to explain in detail the water level identification method provided by the present invention.

[0073] Example 1

[0074] In this embodiment, the water level scene is a scene with a physical water gauge, and the preset recognition method is a template matching method. The specific implementation process is as follows:

[0075] S1: Select the calibration image and collect the image to be tested at the same time.

[0076] First, select the calibration image imageA; and use the camera to collect data to obtain the image to be tested imageB; imageA is used as the subsequent reference image to solve the problem of error in water level calculation caused by camera shake. At the same time, the reference image is used to calibrate the water level information.

[0077] S2: Preprocess the image to be tested, and use the calibration image to correct the preprocessed image to obtain a registered image.

[0078] The captured image to be tested, imageB, is matched with the selected calibration image, imageA, and the deviation of imageB is calculated. Finally, through affine transformation, imageB can be geometrically aligned with imageA, thereby achieving image registration. This solves the problem of camera shake caused by environmental influences.

[0079] The specific process is:

[0080] S21: Use the VGG network to extract features from the calibration image and the image to be tested to obtain a calibration feature map and a feature map to be tested.

[0081] The VGG network is used to extract features from the calibration and camera-captured images to obtain feature maps FA and FB of imageA and imageB; subsequent feature point matching directly calculates feature maps FA and FB.

[0082] S22: Use a deep nearest neighbor search algorithm to find the point on the feature map to be tested that best matches each feature point of the calibration feature map to form the best matching point pair.

[0083] S221: Select a feature point pA in the calibration feature map FA;

[0084] S222: Using a deep nearest neighbor search algorithm on the feature graph FB to be tested, find the feature point pB that is most similar to pA as the best matching point of pA, and at the same time, find the feature point that is second most similar to pA as the second best matching point pB' of pA;

[0085] S223: Calculate the Euclidean distance d1 between pA and its best matching point pB, and the Euclidean distance d2 between pA and its second best matching point pB';

[0086] S224: If d1 / d2 is less than a preset threshold, pA and pB are considered to match and are regarded as a best matching point pair;

[0087] S225: Repeat steps S221-S224 until all feature points in the calibration feature map FA are matched, and the final best matching point pair is obtained.

[0088] Specifically, in this embodiment, the preset threshold is set to 0.9. When searching for matching points, the nearest neighbor is represented by l2 distance, which is the Euclidean distance.

[0089] S23: Counting the average displacements of all the best matching point pairs in the horizontal and vertical directions to obtain the offset of the image to be tested relative to the calibration image, and performing affine transformation on the image to be tested according to the offset to obtain the registration image.

[0090] According to the horizontal direction x and the vertical direction y, the difference between the x and y coordinates of pA and pB in the best matching point pair is calculated, and the average value is calculated according to the difference of all the best matching point pairs to obtain the overall offset of imageB relative to imageA.

[0091] After obtaining the overall offset of the image, we then use affine transformation to register imageB. Affine transformation is a linear transformation that includes operations such as scaling, rotation, translation, and shearing. Applying affine transformation to imageB yields a new registered image imageC: C=W·B, where W is the translation matrix. The specific calculation process involves applying the above translation matrix to the coordinates of each pixel point, thereby adjusting the position of the image to align it with imageA.

[0092] Specifically, in this way, imageB is translated to a position aligned with imageA, thereby obtaining the registered image imageC. This prepares for the subsequent determination and calculation of the water level and solves the problem of accuracy loss caused by camera shaking and offset in complex scenes.

[0093] S3: Use the template matching method to identify the water level of the registered image and obtain the water level line position information.

[0094] The template matching method is:

[0095] Select a picture containing a physical water ruler as a template image T;

[0096] Use the registered image as the search image S;

[0097] Starting from the upper left corner of the search image S, slide the template image T in the horizontal and vertical directions with a preset step size. For each position where the template image T slides, the sub-image of the search image S covered by it is recorded as I;

[0098] The normalized cross-correlation method is used to measure the similarity between I and T. The I with the greatest similarity to T is taken as the target area. According to the location information of the target area, the water level position information is obtained.

[0099] Specifically, for the physical water gauge, the template matching method is used to determine the position of the water level. First, select a water gauge image and save it as a template image. Then divide imageC along the x-axis and y-axis into multiple regions of the same size as the template image with a step of 1, and use the Normalized Cross-Correlation (NCC) method to measure the similarity. The calculation formula is as follows: ;

[0100] Among them, S is the search image of size, that is, imageC. T is the water ruler template image of size k1×k2, S i,j is the subgraph covered by the template, that is, I, i, j is the coordinate of the upper left vertex of the subgraph in S.

[0101] The similarity values ​​between all sub-images and the template image are recorded, and the sub-image I with the largest similarity value is selected as the target area.

[0102] The position of the water level line is determined according to the position of the target area. The position relationship of the water scale scale in the template image T should be converted to the registration image imageC to obtain the water level line position information.

[0103] S4: Input the water level line position information into the elevation fitting function to calculate the water level information of the image to be tested.

[0104] Specifically, the water level elevation fitting is performed by pre-calibrating the elevation of the calibration image, and the water level line position information output by S3 is input into the elevation fitting function to obtain the water level information of the current image to be measured.

[0105] The elevation fitting function is a polynomial regression function used to describe the water level pixel value x w The actual water level h(x w ). The function is in the following form: ;

[0106] In the formula, x w is the pixel value corresponding to the water level position information, h(x w ) is the water level; [θ0,θ1,θ2,...,θ n ] is the solution weight of the elevation fitting function, which is obtained by linear regression training based on the calibration image.

[0107] Training the elevation fitting function requires the known water levels and corresponding pixel values ​​in the calibration image. This includes the following steps:

[0108] 1. Collect the known water level elevation y from the calibration image i and the corresponding pixel value x i .

[0109] 2. Use linear regression to fit these data points so that the model can correctly predict the water level elevation. The loss function of the linear regression used is: ;

[0110] in represents [θ0,θ1,θ2,...,θ n ], m is the number of calibrated heights, x i is the i-th pixel value of the calibration image, h(x i ) is the height fitting function for x i The predicted elevation, y i For x i The corresponding calibration elevation.

[0111] 3. Use an optimization algorithm such as gradient descent or least squares to minimize the loss function and find the best parameters [θ0,θ1,θ2,...,θ n ].

[0112] After training, the optimal parameters [θ0,θ1,θ2,...,θ n ], the water level position information (i.e., pixel coordinates) obtained by S3 is input into the elevation fitting function. These pixel values ​​x w The water level position is identified from the registered image.

[0113] Use the trained elevation fitting function to transform the pixel value x w Converted to predicted water level h(x w ).

[0114] Example 2

[0115] In this embodiment, the water level scene is a scene with a physical water gauge, and the preset recognition method is a target detection method. The specific implementation process is as follows:

[0116] S1: Select the calibration image and collect the image to be tested at the same time;

[0117] S2: preprocessing the image to be tested, and using the calibration image to correct the preprocessed image to obtain a registered image;

[0118] S3: Use the target detection method to identify the water level of the registered image and obtain the water level position information;

[0119] S4: Input the water level line position information into the elevation fitting function to calculate the water level information of the image to be tested.

[0120] The difference between this embodiment and Embodiment 1 is that the preset recognition method is a target detection method.

[0121] In this embodiment, the implementation process of steps S1 and S2 is the same as that of embodiment 1, and will not be repeated here.

[0122] Specifically, the target detection method is:

[0123] Collect pictures containing physical water gauges at multiple measuring points, annotate them to create a data set, and preprocess the data set;

[0124] Construct the Yolov5 network model and set initial anchor boxes of different scales and aspect ratios according to the target size distribution of the data set;

[0125] Use the data set to train the Yolov5 network model until the loss converges to obtain the trained Yolov5 network model;

[0126] Use the trained Yolov5 network model to detect the registered image, and take the one with the highest confidence as the detection result for each detected water gauge bounding box;

[0127] According to the position of the water gauge bounding box in the detection result, the water level line position information is obtained.

[0128] Firstly, pictures containing physical water gauges are collected at multiple measuring points, and water gauges are annotated to create a data set. The data set is preprocessed and its size is set to 640×640×3.

[0129] Construct the Yolov5 network model. According to the size of the dataset, set the initial anchor boxes of the Yolov5 network model to: [116, 90, 156, 198, 373, 326], [30, 61, 62, 45, 59, 119], [10, 13, 16, 30, 33, 23].

[0130] Use the data set to train the Yolov5 network model:

[0131] The Yolov5 network model is trained on the basis of the initial anchor frame to obtain the predicted frame, and the predicted frame and the real frame are matched to obtain positive and negative samples, including:

[0132] For each true box, the predicted boxes in the grid where it is located and the adjacent grids are used as candidate predicted boxes. The true box and the candidate predicted boxes are matched according to the matching conditions. If they match, the candidate predicted box is used as a positive sample, and the position information of the candidate predicted box is calculated by the prediction box regression formula. If they do not match, the candidate prediction box is used as a negative sample.

[0133] Specifically, cross-grid matching is used, that is, the two grids closest to the center point of the true frame are found from the four grids above, below, left and right of the grid where the true frame is located, and then the three grids are matched together with the grid where the true frame is located. The aspect ratio of the true frame and all anchor frames of these three grids is calculated. When the ratio of the width of the true frame to the width of the anchor frame and the ratio of the height of the true frame to the height of the anchor frame are both greater than 1 / 4 and less than 4, it is considered a match, that is, the following formulas are satisfied at the same time: ;

[0134] Where GT_W is the width of the real box, GT_H is the height of the real box, Anchor_W is the width of the candidate prediction box, and Anchor_H is the height of the candidate prediction box.

[0135] If this formula is not satisfied, it is considered a mismatch.

[0136] When the candidate prediction box is considered to be matched, the position information of the matched prediction box is calculated according to the prediction box regression formula. The prediction box regression formula is as follows: ;

[0137] Where, t x ,t y is the center point coordinate offset of the prediction box, t w ,t h is the width and height offset of the prediction box, c x 、c y is the distance from the upper left corner of the grid, b x , b y are the center point coordinates of the prediction box, b w , b h are the width and height of the prediction box respectively, and σ is the sigmoid function.

[0138] The matched prediction boxes are taken as positive samples, and the unmatched prediction boxes are taken as negative samples.

[0139] Calculate the positioning loss, confidence loss and classification loss of the positive sample and the true box, where the confidence of the true box matched by the positive sample is the intersection and union ratio of the true box and the positive sample; calculate the confidence loss of the negative sample and the true box, and the confidence of the true box matched by the negative sample is 0;

[0140] The parameters of the Yolov5 network model are iteratively adjusted through back propagation until the loss converges, that is, the training is completed, and the trained Yolov5 network model is obtained.

[0141] The trained Yolov5 model is used to predict the water gauge detection frame of the registered image, and the detection frame with the highest confidence is taken to determine the location information of the target water gauge, thereby obtaining the water level line location information.

[0142] In this embodiment, YOLOv5 is used to densely sample anchor boxes at multiple scales and use a cross-grid matching strategy to improve adaptability to target scale changes.

[0143] In this embodiment, after the water level position information is obtained, step S4 in embodiment 1 is used to perform elevation fitting to obtain water level information, that is, the actual water level elevation.

[0144] Example 3

[0145] In this embodiment, the water level scene is a scene without a physical water gauge, and the preset recognition method is a deep learning semantic segmentation method based on a virtual water gauge. The specific implementation process is as follows:

[0146] S1: Select the calibration image and collect the image to be tested at the same time;

[0147] S2: preprocessing the image to be tested, and using the calibration image to correct the preprocessed image to obtain a registered image;

[0148] S3: Use the deep learning semantic segmentation method based on the virtual water gauge to identify the water level of the registered image and obtain the water level position information;

[0149] S4: Input the water level line position information into the elevation fitting function to calculate the water level information of the image to be tested.

[0150] The difference between this embodiment and Embodiment 1 is that the water level scene is a scene without a physical water gauge, and the preset recognition method is a deep learning semantic segmentation method based on a virtual water gauge.

[0151] In this embodiment, the implementation process of steps S1 and S2 is the same as that of embodiment 1, and will not be repeated here.

[0152] Specifically, the deep learning semantic segmentation method based on the virtual water ruler is:

[0153] Collect sample images and perform data enhancement on the sample images to form a training sample set;

[0154] Build a Unet++ model, and use the training sample set to train the Unet++ model to obtain the trained Unet++ model;

[0155] The registered images are input into the trained Unet++ model to extract the waterfront boundary line and form a waterfront boundary map;

[0156] Manually calibrate the registered images to obtain a virtual water ruler, and determine the search area of ​​the water level line based on the virtual water ruler;

[0157] In the search area of ​​the water level line, the water bank boundary map is traversed to search for the longest continuous horizontal line in the water bank boundary map, which is the water level line;

[0158] The water level line is matched with the virtual water gauge to obtain the water level line position information.

[0159] Specifically, this embodiment uses a deep learning semantic segmentation algorithm to segment the water surface area, thereby determining the water level position. Semantic segmentation is a pixel-level classification task that aims to assign each pixel in an image to a predefined category (such as water surface, shore, etc.).

[0160] First, collect water level image samples, paying attention to covering different water levels, lighting, weather and other scenes. Label the collected images and mark each pixel with its category (such as water surface, shore). Use data enhancement techniques (such as rotation, scaling, flipping, etc.) to expand the data set and improve the generalization ability of the model.

[0161] Construct the Unet++ model, which is a fully convolutional network (FCN) based on the encoder-decoder structure. The Unet++ model introduces dense skip connections to enhance feature reuse and transfer. In the Unet++ model, the encoder part: consists of multiple downsampling modules, which are used to extract multi-scale features of the image; the decoder part: consists of multiple upsampling modules, which are used to restore the spatial resolution of the feature map; the skip connection: passes the shallow features of the encoder to the corresponding layer of the decoder to achieve feature fusion and detail retention.

[0162] In this embodiment, the working mechanism of the jump path of the Unet++ model can be expressed by the following formula: Let x i,j Represents node x i,j The output of x is, i refers to the down-sampling module along the encoding direction, and j refers to the up-sampling module along the skip path direction. The feature map is composed of x i,j It is calculated as follows: ;

[0163] Function H(·) represents a downsampling operation. U(·) represents an upsampling operation, and [ ] represents a connection layer. In this mechanism, nodes at level j=0 receive only one input from the previous layer of the encoder; nodes at level j=1 receive two inputs from two consecutive layers of the encoding subnetwork; for nodes at level j>1, they receive j+1 inputs, where input j is the output from the previous node j in the same skip path, and the last input is the upsampled output from the lower-level skip path. All previous feature maps are accumulated in this way and reach the correct node along the upsampling module on each skip path.

[0164] Specifically, this embodiment uses the Unet++ model to simultaneously extract high-level semantic features and low-level detail features, and utilizes dense skip connections to enhance feature reuse and transfer to capture the fine structure of the water surface boundary.

[0165] The Unet++ model is trained using the training sample set. The loss function can be the sum of the cross entropy loss and the Dice loss. The Adam optimizer is used to optimize the model parameters in iterations until the model converges, thus obtaining the trained Unet++ model.

[0166] The registered image is then input into the trained Unet++ model to perform shoreline segmentation on the registered image. The output is a segmentation map of the same size as the input image. Each pixel value in the segmentation map represents the category to which the position belongs. The segmentation map is used as the shore boundary map.

[0167] By calibrating the ruler or known scale object in the image, a benchmark is provided to determine the actual height of the water level. The position and scale of the virtual water ruler are manually marked on the registration image.

[0168] Based on the virtual water gauge, a horizontal search area that may contain the water level line is determined on the water bank boundary map. This area can be defined by an upper and lower limit range using the artificially calibrated water gauge scale.

[0169] In the determined horizontal search area, the water bank boundary map is searched row by row and pixel by pixel.

[0170] Traverse the horizontal pixel lines in the area, determine all continuous water surface pixel segments, and find the longest one. This longest continuous horizontal line is regarded as the water level line.

[0171] Pair the longest horizontal line found with the virtual water gauge. Get the water level position information through the calibration data of the virtual water gauge, that is, the pixel position of the water level in the image.

[0172] In this embodiment, after the water level position information is obtained, step S4 in embodiment 1 is used to perform elevation fitting to obtain water level information, that is, the actual water level elevation.

[0173] 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 in the protection scope of the present invention.

Claims

1. A water level recognition method in a complex scene, characterized in that: The steps include: S1: Select the calibration image and collect the image to be tested at the same time; S2: preprocessing the image to be tested, and using the calibration image to correct the preprocessed image to obtain a registered image; Step S2 includes: S21: Using the VGG network to extract features from the calibration image and the image to be tested, to obtain a calibration feature map and a feature map to be tested; S22: using a deep nearest neighbor search algorithm to find the point on the feature map to be tested that best matches each feature point of the calibration feature map, to form the best matching point pair; S23: Counting the average displacements of all the best matching point pairs in the horizontal and vertical directions to obtain the offset of the image to be tested relative to the calibration image, and performing affine transformation on the image to be tested according to the offset to obtain the registration image; Step S22 includes: S221: Select a feature point pA in the calibration feature map FA; S222: Using a deep nearest neighbor search algorithm on the feature graph FB to be tested, find the feature point pB that is most similar to pA as the best matching point of pA, and at the same time, find the feature point that is second most similar to pA as the second best matching point pB' of pA; S223: Calculate the Euclidean distance d1 between pA and its best matching point pB, and the Euclidean distance d2 between pA and its second best matching point pB'; S224: If d1 / d2 is less than a preset threshold, pA and pB are considered to match and are regarded as a best matching point pair; S225: repeating steps S221-S224 until all feature points in the calibration feature map FA are matched, and the final best matching point pair is obtained; S3: Acquire a water level scene, select a preset recognition method according to the water level scene, use the preset recognition method to perform water level recognition on the registration image, and obtain water level line position information; S4: Input the water level line position information into the elevation fitting function to calculate the water level information of the image to be tested.

2. The water level recognition method in a complex scene as claimed in claim 1, characterized in that: The water level scene is a scene with a physical water gauge or a scene without a physical water gauge.

3. The water level recognition method in a complex scene as claimed in claim 2, characterized in that: When the water level scene is a scene with a physical water gauge, the preset recognition methods include a template matching method and a target detection method.

4. The water level recognition method in a complex scene as claimed in claim 2, characterized in that: When the water level scene is a scene without a physical water gauge, the preset recognition method is a deep learning semantic segmentation method based on a virtual water gauge.

5. The water level recognition method in a complex scene as claimed in claim 3, characterized in that: The template matching method is: Select a picture containing a physical water ruler as a template image T; Use the registered image as the search image S; Starting from the upper left corner of the search image S, slide the template image T in the horizontal and vertical directions with a preset step size. For each position where the template image T slides, the sub-image of the search image S covered by it is recorded as I; The normalized cross-correlation method is used to measure the similarity between I and T. The I with the greatest similarity to T is taken as the target area. According to the location information of the target area, the water level position information is obtained.

6. The water level recognition method in a complex scene as claimed in claim 3, characterized in that: The target detection method is: Collect pictures containing physical water gauges at multiple measuring points, annotate them to create a data set, and preprocess the data set; Construct the Yolov5 network model and set initial anchor boxes of different scales and aspect ratios according to the target size distribution of the data set; Use the data set to train the Yolov5 network model until the loss converges to obtain the trained Yolov5 network model; Use the trained Yolov5 network model to detect the registered image, and take the one with the highest confidence as the detection result for each detected water gauge bounding box; According to the position of the water gauge bounding box in the detection result, the water level line position information is obtained.

7. The water level recognition method in a complex scene as claimed in claim 6, characterized in that: The training process of the Yolov5 network model is: The Yolov5 network model is trained on the basis of the initial anchor box to obtain the predicted box, and the predicted box is matched with the real box: For each true box, the predicted boxes in the grid where it is located and the adjacent grids are used as candidate predicted boxes. The true box and the candidate predicted boxes are matched according to the matching conditions. If they match, the candidate predicted box is used as a positive sample, and the position information of the candidate predicted box is calculated by the prediction box regression formula. If they do not match, the candidate predicted box is used as a negative sample. Calculate the positioning loss, confidence loss and classification loss of the positive sample and the true box, where the confidence of the true box matched by the positive sample is the intersection and union ratio of the true box and the positive sample; calculate the confidence loss of the negative sample and the true box, and the confidence of the true box matched by the negative sample is 0; The parameters of the Yolov5 network model are iteratively adjusted through back propagation until the loss converges, that is, the training is completed, and the trained Yolov5 network model is obtained.

8. The water level recognition method in a complex scene as claimed in claim 7, characterized in that: The matching condition is that the ratio of the width of the real box to the width of the candidate prediction box, and the ratio of the height of the real box to the height of the candidate prediction box are both greater than 1 / 4 and less than 4, that is, they satisfy the following formulas at the same time: ; Where GT_W is the width of the real box, GT_H is the height of the real box, Anchor_W is the width of the candidate prediction box, and Anchor_H is the height of the candidate prediction box.

9. The water level recognition method in a complex scene as claimed in claim 4, characterized in that: The deep learning semantic segmentation method based on virtual water ruler is: Collect sample images and perform data enhancement on the sample images to form a training sample set; Build a Unet++ model, and use the training sample set to train the Unet++ model to obtain the trained Unet++ model; The registered images are input into the trained Unet++ model to form a waterside boundary map; Manually calibrate the registered images to obtain a virtual water ruler, and determine the search area of ​​the water level line based on the virtual water ruler; In the search area of ​​the water level line, the water bank boundary map is traversed to search for the longest continuous horizontal line in the water bank boundary map, which is the water level line; The water level line is matched with the virtual water gauge to obtain the water level line position information.

10. The water level recognition method in a complex scene according to claim 1, characterized in that: The elevation fitting function is: ; In the formula, x w is the pixel value corresponding to the water level position information, h(x w ) is the water level; [θ0,θ1,θ2,...,θ n ] is the solution weight of the elevation fitting function, which is obtained by linear regression training based on the calibration image. The loss function of linear regression is: ; in [θ0,θ1,θ2,...,θ n ], m is the number of calibrated heights, x i is the i-th pixel value of the calibration image, h(x i ) is the height fitting function for x i The predicted elevation, y i For x i The corresponding calibration elevation.

11. The water level recognition method in a complex scene according to claim 1, characterized in that: Step S2 also includes hierarchical optimization matching, the process of which is as follows: Starting from the highest layer n of the VGG network, a deep nearest neighbor search algorithm is used to perform feature matching on the feature map output by the nth layer; Using the feature matching results of the nth layer, the search range of the deep nearest neighbor search algorithm of the feature map output by the n-1th layer is narrowed down to obtain the feature matching results of the feature map output by the n-1th layer; The above process is repeated, and the feature matching results of each time are used to guide the matching of the next layer until the bottom layer of the VGG network is reached.