A water level identification method, device, system and storage medium
By combining the OpenCV and YOLOv5 algorithms and using jump determination rules for water level identification, the problem of slow speed and high hardware cost of the deep learning model in water level identification is solved, and fast, low-power water level observation in the wild environment is achieved.
Patent Information
- Application Number
- CN202410350557.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2024-01-29
- Filing Date
- 2024-03-26
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2044-03-26
AI Technical Summary
The existing deep learning model has slow recognition speed and high hardware cost in water level recognition, which cannot meet the real-time needs of the hydrology industry, especially during the flood season. Moreover, due to insufficient data sets, the model is under-fitted and cannot be effective in low-power environments in the wild. application.
Combined with the OpenCV algorithm library and YOLOv5 target detection algorithm, the water level is obtained through angle correction, grayscale processing, filtering smoothing and feature calculation, and the preset jump determination rules are used for mutual verification, reducing hardware costs and power consumption, and improving recognition speed. .
It achieves rapid water level recognition using a small amount of training data, reduces hardware costs, meets water level observation requirements in low-power environments in the wild, and improves the accuracy and efficiency of recognition.
Smart Images

Figure CN118135470B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a water level identification method, device, system and storage medium, and belongs to the technical field of water level identification. Background Art
[0002] Image-based water level recognition technology uses the water ruler in the image as an anchor object and calculates the water level information by identifying the numbers and scales on the water ruler and the distance relationship between them and the water level line.
[0003] In recent years, water level recognition technology based on deep learning has been the most widely used. This technology uses the advantages of convolutional neural networks to extract the image feature distribution of the original data set for deep learning, and generates new images that conform to specific scenarios after image enhancement, thereby improving the accuracy of water level recognition. It also uses OpenCV, FFMPEG, libx264 and other algorithm libraries to process images and videos, and basically realizes water level recognition in complex scenarios.
[0004] Traditional image recognition methods require manual feature design, which makes it very difficult to estimate and judge features in complex scenes, which seriously affects the speed and accuracy of recognition. The use of deep learning methods can significantly improve the performance of detection and recognition, but there are the following defects:
[0005] On the one hand, although the existing deep learning models have solved the problem of recognition accuracy, the recognition speed is slow and cannot meet the requirements of water level observation in the hydrological industry, especially during the flood season.
[0006] On the other hand, the existing deep learning models require a large amount of training data, but there is less actual water gauge training data and no public water gauge data set. Insufficient data sets will cause the model to be underfitting. Therefore, the degree of dependence on the data set and the computing power requirements of the hardware platform are very high, resulting in increased hardware costs and increased system power consumption. The high hardware cost is not conducive to promotion and application, and the high system power consumption cannot meet the low power consumption requirements of the solar power supply system in actual field application environments. Summary of the invention
[0007] The purpose of the present invention is to provide a water level identification method, device, system and storage medium, which can reduce hardware costs, meet the requirements of low power operation in field environments, and meet the water level observation requirements in actual hydrological scenarios.
[0008] In order to achieve the above object, the present invention provides the following technical solutions:
[0009] In a first aspect, the present invention provides a water level identification method, comprising:
[0010] Use the pre-acquired OpenCV algorithm library to recognize the water gauge image to be measured and obtain the first water level line;
[0011] Use the trained YOLOv5 target detection algorithm to identify the water gauge image to be measured and obtain the second water level line;
[0012] The second water level line is compared with the first water level line, and a water level recognition result is obtained based on a preset jump determination rule.
[0013] In combination with the first aspect, further, using the pre-acquired OpenCV algorithm library to recognize the water gauge image to be measured, obtaining the first water level line includes:
[0014] Performing angle correction on the image in the water gauge area selected by the target detection frame in the water gauge image to be measured, and performing grayscale processing on the angle-corrected image to obtain a grayscale image;
[0015] Performing grayscale enhancement and contrast stretching on the grayscale image to obtain an enhanced image;
[0016] Performing filtering and smoothing processing on the enhanced image to obtain a filtered image;
[0017] Based on the OpenCV algorithm library, feature calculation is performed on the filtered image to obtain gray value change features;
[0018] Performing horizontal projection on the filtered image, and finding a grayscale change jump point based on the grayscale value change characteristics;
[0019] Based on the grayscale change jump point, a first water level line is obtained.
[0020] Combined with the first aspect, further training of the YOLOv5 target detection algorithm includes:
[0021] The YOLOv5 target detection algorithm is trained using the pre-acquired water gauge image training set, and the parameters of the YOLOv5 target detection algorithm are optimized using the gradient descent method or the stochastic gradient descent method;
[0022] The YOLOv5 target detection algorithm trained this time is tested using the pre-acquired water gauge image test set, and the accuracy, recall rate and F1 value of the YOLOv5 target detection algorithm trained this time are calculated;
[0023] Based on the accuracy, recall and F1 value, a performance evaluation is performed on the YOLOv5 target detection algorithm trained this time, and a performance evaluation result of the YOLOv5 target detection algorithm trained this time is obtained;
[0024] Based on the performance evaluation result, the YOLOv5 target detection algorithm trained this time is trained again until the performance evaluation result of the retrained YOLOv5 target detection algorithm reaches a preset performance target, thereby obtaining a trained YOLOv5 target detection algorithm.
[0025] In combination with the first aspect, further, using the pre-acquired water gauge image training set to train the YOLOv5 target detection algorithm includes:
[0026] Perform water level scale marking on the water gauge images in the pre-acquired water gauge image training set to obtain marked data;
[0027] Using the labeled data to train the YOLOv5 target detection algorithm;
[0028] The annotation data includes the coordinates and category of the bounding box of each water level scale.
[0029] In combination with the first aspect, further, the preset jump determination rule includes:
[0030] If the error between the second water level line and the first water level line is less than or equal to a preset error threshold, outputting the second water level line as a water level recognition result;
[0031] If the error between the second water level line and the first water level line is greater than a preset error threshold, a preset register is used to record the number of times the error between the second water level line and the first water level line is greater than the preset error threshold;
[0032] If the number of times that the error between the second water level line and the first water level line is greater than a preset error threshold is less than a preset error threshold, outputting the second water level line as a water level recognition result;
[0033] If the number of times the error between the second water level line and the first water level line is greater than the preset error threshold is greater than or equal to the preset error threshold, the first water level line and the second water level line are reacquired, the reacquired first water level line is compared with the second water level line, and the water level identification result is reacquired based on the preset jump judgment rule.
[0034] In a second aspect, the present invention provides a water level identification device, comprising:
[0035] The first recognition module is used to recognize the water gauge image to be measured by using the pre-acquired OpenCV algorithm library to obtain the first water level line;
[0036] The second recognition module is used to use the trained YOLOv5 target detection algorithm to recognize the water gauge image to be measured and obtain the second water level line;
[0037] Jump determination module: used to compare the second water level line with the first water level line, and obtain a water level recognition result based on a preset jump determination rule.
[0038] In a third aspect, the present invention provides a water level identification system, including a processor and a storage medium;
[0039] The storage medium is used to store instructions;
[0040] The processor is used to operate according to the instructions to execute the steps of the method according to any one of the first aspects.
[0041] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any one of the methods described in the first aspect.
[0042] Compared with the prior art, the present invention has the following beneficial effects:
[0043] The water level recognition method provided by the present invention utilizes the traditional image recognition method and the YOLOv5 target detection algorithm to simultaneously recognize the water gauge image to be measured, and mutually verify them through jump judgment rules. It can realize rapid recognition under the premise of using a small amount of training data, thereby reducing hardware costs, meeting the requirements of low-power operation in field environments, and meeting the water level observation requirements in actual hydrological scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 is a flow chart of a water level identification method provided by an embodiment of the present invention;
[0045] Figure 2 Schematic diagram of grayscale change jump points provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0046] The technical solution of the present application is further described in detail below in conjunction with specific implementation methods.
[0047] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements with the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and should not be construed as limitations on the present application. In the absence of conflict, the embodiments of the present application and the technical features in the embodiments may be combined with each other.
[0048] Embodiment 1:
[0049] Figure 1 This is a flow chart of a water level identification method provided in this embodiment. This flow chart only shows the logical sequence of the method in this embodiment. Different methods can be used without conflict. Figure 1 The steps shown or described are accomplished in the order shown.
[0050] The water level identification method provided in this embodiment can be applied to a terminal and can be executed by a water level identification device, which can be implemented by software and / or hardware, and can be integrated in a terminal, for example: any tablet computer or computer device with communication function.
[0051] See also Figure 1 The water level recognition method of this embodiment specifically includes the following steps:
[0052] Step 1: Use the pre-acquired OpenCV algorithm library to recognize the water gauge image to be measured and obtain the first water level line;
[0053] In this embodiment, the pre-acquired OpenCV algorithm library is used to recognize the water gauge image to be measured, and obtaining the first water level line specifically includes the following steps:
[0054] Step 1: Perform angle correction on the image in the water gauge area selected by the target detection frame in the water gauge image to be measured, and perform grayscale processing on the angle-corrected image to obtain a grayscale image;
[0055] Step 2: Perform grayscale enhancement and contrast stretching on the grayscale image to obtain an enhanced image;
[0056] Step 3: Perform filtering and smoothing processing on the enhanced image to obtain a filtered image;
[0057] Step 4: Based on the OpenCV algorithm library, perform feature calculation on the filtered image to obtain the gray value change characteristics;
[0058] Step 5: Project the filtered image horizontally and find the grayscale change jump point based on the grayscale value change characteristics;
[0059] In this embodiment, the schematic diagram of the grayscale change jump point is as follows: Figure 2 shown.
[0060] Step 6: Based on the grayscale change jump point, obtain the first water level line.
[0061] Step 2: Use the trained YOLOv5 target detection algorithm to identify the water gauge image to be measured and obtain the second water level line;
[0062] The YOLOv5 target detection algorithm transforms target detection from a classification problem to a regression problem. It uses the entire image as the input of the network. After only one neural network, it can obtain the predicted bounding box and predicted category information of the target, greatly improving the efficiency of detection.
[0063] In the YOLOv5 target detection algorithm, the input image is divided into S×S grids. When the center of the target falls in a certain grid, the grid is responsible for the prediction of the target. Each grid needs to predict B candidate bounding boxes, each of which contains five prediction values: the center coordinates x and y of the bounding box, the width w and height h of the bounding box, and the confidence. In addition, each grid needs to predict C category probabilities. Therefore, after the input image passes through a convolutional neural network, it will eventually output a tensor of S×S×(B*5+C).
[0064] In this embodiment, training the YOLOv5 target detection algorithm specifically includes the following steps:
[0065] Step ①: Use the pre-acquired water gauge image training set to train the YOLOv5 target detection algorithm, and use the gradient descent method or the stochastic gradient descent method to optimize the parameters of the YOLOv5 target detection algorithm;
[0066] In this embodiment, the training of the YOLOv5 target detection algorithm using the pre-acquired water gauge image training set specifically includes the following steps:
[0067] Step i: annotate the water level scale of the water gauge image in the pre-acquired water gauge image training set to obtain the annotated data;
[0068] In this embodiment, the annotation data specifically includes the coordinates and category of the bounding box of each water level scale.
[0069] Step ii: Use the labeled data to train the YOLOv5 object detection algorithm.
[0070] Step ②: Use the pre-acquired water gauge image test set to test the YOLOv5 target detection algorithm trained this time, and calculate the accuracy, recall rate and F1 value of the YOLOv5 target detection algorithm trained this time;
[0071] Step 3: Based on the accuracy, recall rate and F1 value, the performance of the YOLOv5 target detection algorithm trained this time is evaluated to obtain the performance evaluation results of the YOLOv5 target detection algorithm trained this time;
[0072] Step ④: Based on the performance evaluation results, the YOLOv5 target detection algorithm trained this time is trained again until the performance evaluation result of the retrained YOLOv5 target detection algorithm reaches the preset performance target, and the trained YOLOv5 target detection algorithm is obtained.
[0073] In this embodiment, the water gauge image to be measured is input into the trained YOLOv5 target detection algorithm for recognition to obtain the second water level line.
[0074] Step 3: Compare the second water level line with the first water level line, and obtain the water level recognition result based on the preset jump judgment rule.
[0075] In this embodiment, the preset transition determination rules specifically include:
[0076] R1: If the error between the second water level line and the first water level line is less than or equal to the preset error threshold, output the second water level line as the water level recognition result;
[0077] R2: If the error between the second water level line and the first water level line is greater than a preset error threshold, a preset register is used to record the number of times the error between the second water level line and the first water level line is greater than the preset error threshold;
[0078] R21: If the number of times that the error between the second water level line and the first water level line is greater than the preset error threshold is less than the preset error threshold, the second water level line is output as the water level recognition result;
[0079] R22: If the number of times that the error between the second water level line and the first water level line is greater than the preset error threshold is greater than or equal to the preset error threshold, the first water level line and the second water level line are reacquired, and the reacquired first water level line is compared with the second water level line again, and the water level identification result is reacquired based on the preset jump judgment rule.
[0080] The water level recognition method provided in this embodiment utilizes the traditional image recognition method and the YOLOv5 target detection algorithm to simultaneously identify the water gauge image to be measured, and verify each other through jump judgment rules. It can achieve rapid recognition under the premise of using a small amount of training data, thereby reducing hardware costs, meeting the requirements of low-power operation in field environments, and meeting the water level observation requirements in actual hydrological scenarios.
[0081] Embodiment 2:
[0082] This embodiment provides a water level identification device, including:
[0083] The first recognition module is used to recognize the water gauge image to be measured by using the pre-acquired OpenCV algorithm library to obtain the first water level line;
[0084] The second recognition module is used to use the trained YOLOv5 target detection algorithm to recognize the water gauge image to be measured and obtain the second water level line;
[0085] Jump determination module: used to compare the second water level line with the first water level line, and obtain the water level recognition result based on the preset jump determination rule.
[0086] The water level identification device provided in the embodiment of the present application can execute the water level identification method provided in Example 1 of the present application, and has the corresponding functional modules and beneficial effects of the execution method.
[0087] Embodiment 3:
[0088] This embodiment provides a water level identification system, including a processor and a storage medium;
[0089] The storage medium is used to store instructions;
[0090] The processor is used to operate according to the instructions to execute the steps of the method in Example 1.
[0091] Embodiment 4:
[0092] This embodiment provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the steps of the method in Embodiment 1 are implemented.
[0093] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0094] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0095] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0096] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0097] The above are only preferred implementations of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A water level identification method, characterized in that: include: Use the pre-acquired OpenCV algorithm library to recognize the water gauge image to be measured and obtain the first water level line; Use the trained YOLOv5 target detection algorithm to identify the water gauge image to be measured and obtain the second water level line; Compare the second water level line with the first water level line, and obtain a water level recognition result based on a preset jump determination rule; Using the pre-acquired OpenCV algorithm library to identify the water gauge image to be measured, obtaining the first water level line includes: Performing angle correction on the image in the water gauge area selected by the target detection frame in the water gauge image to be measured, and performing grayscale processing on the angle-corrected image to obtain a grayscale image; Performing grayscale enhancement and contrast stretching on the grayscale image to obtain an enhanced image; Performing filtering and smoothing processing on the enhanced image to obtain a filtered image; Based on the OpenCV algorithm library, feature calculation is performed on the filtered image to obtain gray value change features; Performing horizontal projection on the filtered image, and finding a grayscale change jump point based on the grayscale value change characteristics; Based on the grayscale change jump point, obtaining a first water level line; Training the YOLOv5 object detection algorithm includes: The YOLOv5 target detection algorithm is trained using the pre-acquired water gauge image training set, and the parameters of the YOLOv5 target detection algorithm are optimized using the gradient descent method or the stochastic gradient descent method; The YOLOv5 target detection algorithm trained this time is tested using the pre-acquired water gauge image test set, and the accuracy, recall rate and F1 value of the YOLOv5 target detection algorithm trained this time are calculated; Based on the accuracy, recall and F1 value, a performance evaluation is performed on the YOLOv5 target detection algorithm trained this time, and a performance evaluation result of the YOLOv5 target detection algorithm trained this time is obtained; Based on the performance evaluation result, the YOLOv5 target detection algorithm trained this time is trained again until the performance evaluation result of the retrained YOLOv5 target detection algorithm reaches a preset performance target, thereby obtaining a trained YOLOv5 target detection algorithm; The preset jump determination rules include: If the error between the second water level line and the first water level line is less than or equal to a preset error threshold, outputting the second water level line as a water level recognition result; If the error between the second water level line and the first water level line is greater than a preset error threshold, a preset register is used to record the number of times the error between the second water level line and the first water level line is greater than the preset error threshold; If the number of times that the error between the second water level line and the first water level line is greater than a preset error threshold is less than a preset error threshold, outputting the second water level line as a water level recognition result; If the number of times the error between the second water level line and the first water level line is greater than the preset error threshold is greater than or equal to the preset error threshold, the first water level line and the second water level line are reacquired, the reacquired first water level line is compared with the second water level line, and the water level identification result is reacquired based on the preset jump judgment rule.
2. The water level identification method according to claim 1, characterized in that: Training the YOLOv5 target detection algorithm using the pre-acquired water gauge image training set includes: Perform water level scale marking on the water gauge images in the pre-acquired water gauge image training set to obtain marked data; Using the labeled data to train the YOLOv5 target detection algorithm; The annotation data includes the coordinates and category of the bounding box of each water level scale.
3. A water level identification device, characterized in that: include: The first recognition module is used to recognize the water gauge image to be measured by using the pre-acquired OpenCV algorithm library to obtain the first water level line; The second recognition module is used to use the trained YOLOv5 target detection algorithm to recognize the water gauge image to be measured and obtain the second water level line; A jump determination module: used to compare the second water level line with the first water level line, and obtain a water level recognition result based on a preset jump determination rule; Using the pre-acquired OpenCV algorithm library to identify the water gauge image to be measured, obtaining the first water level line includes: Performing angle correction on the image in the water gauge area selected by the target detection frame in the water gauge image to be measured, and performing grayscale processing on the angle-corrected image to obtain a grayscale image; Performing grayscale enhancement and contrast stretching on the grayscale image to obtain an enhanced image; Performing filtering and smoothing processing on the enhanced image to obtain a filtered image; Based on the OpenCV algorithm library, feature calculation is performed on the filtered image to obtain gray value change features; Performing horizontal projection on the filtered image, and finding a grayscale change jump point based on the grayscale value change characteristics; Based on the grayscale change jump point, obtaining a first water level line; Training the YOLOv5 object detection algorithm includes: The YOLOv5 target detection algorithm is trained using the pre-acquired water gauge image training set, and the parameters of the YOLOv5 target detection algorithm are optimized using the gradient descent method or the stochastic gradient descent method; The YOLOv5 target detection algorithm trained this time is tested using the pre-acquired water gauge image test set, and the accuracy, recall rate and F1 value of the YOLOv5 target detection algorithm trained this time are calculated; Based on the accuracy, recall and F1 value, a performance evaluation is performed on the YOLOv5 target detection algorithm trained this time, and a performance evaluation result of the YOLOv5 target detection algorithm trained this time is obtained; Based on the performance evaluation result, the YOLOv5 target detection algorithm trained this time is trained again until the performance evaluation result of the retrained YOLOv5 target detection algorithm reaches a preset performance target, thereby obtaining a trained YOLOv5 target detection algorithm; The preset jump determination rules include: If the error between the second water level line and the first water level line is less than or equal to a preset error threshold, outputting the second water level line as a water level recognition result; If the error between the second water level line and the first water level line is greater than a preset error threshold, a preset register is used to record the number of times the error between the second water level line and the first water level line is greater than the preset error threshold; If the number of times that the error between the second water level line and the first water level line is greater than a preset error threshold is less than a preset error threshold, outputting the second water level line as a water level recognition result; If the number of times the error between the second water level line and the first water level line is greater than the preset error threshold is greater than or equal to the preset error threshold, the first water level line and the second water level line are reacquired, the reacquired first water level line is compared with the second water level line, and the water level identification result is reacquired based on the preset jump judgment rule.
4. A water level identification system, characterized in that: including processor and storage medium; The storage medium is used to store instructions; The processor is used to operate according to the instructions to execute the steps of the method according to any one of claims 1 to 2.
5. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the method described in any one of claims 1 to 2 are implemented.
