A water level detection system and method based on image segmentation and object detection technologies
Through the combination of image segmentation and object detection technology, the problems of insufficient accuracy and poor anti-interference ability of intelligent devices in water level detection are solved, and accurate water level calculation is achieved when shading or stains are present, reducing labor costs and improving detection accuracy.
Patent Information
- Application Number
- CN202211477590.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-23
- Publication Date
- 2025-08-05
- Estimated Expiration
- 2042-11-23
AI Technical Summary
When detecting water level, existing smart devices have problems such as insufficient accuracy, poor anti-interference ability, and inability to obtain readings when blocked by the water level ruler.
The combination of image segmentation and object detection technology is used to obtain the water level ruler image through a fixed point camera, and the image segmentation and detection model are used for processing, including mask image generation, water level ruler coordinates and stain position recognition, combined with interleaving and ratio calculation and pixel height mapping, water level detection is achieved.
It improves the accuracy of water level detection, can accurately calculate the water level height when the water level ruler blocks or stains, reduces labor costs, has anti-interference capabilities, and supports remote program upgrades.
Smart Images

Figure CN115761468B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a water level detection system and method based on image segmentation and target detection technology, and belongs to the technical field of computer vision application. Background Art
[0002] With the development of artificial intelligence, the use of intelligent devices to replace human labor is becoming increasingly common in various fields. This paper focuses on the water conservancy industry. Due to the variability and uncertainty of river water levels, manual water level monitoring cannot ensure timeliness and effectiveness. In special circumstances, manual water level monitoring also poses certain safety risks.
[0003] Using smart products to monitor water levels can significantly reduce the labor costs and safety risks associated with manual inspections. However, while smart devices can address the challenges of manual inspections, they can also suffer from issues such as insufficient accuracy and poor anti-interference capabilities due to equipment and environmental factors. Furthermore, vision-based smart products cannot effectively read the current water level when the water gauge is obstructed.
[0004] To this end, the prior art discloses the following patent documents:
[0005] Chinese patent document CN112991342A discloses a water level line detection method based on a water level gauge image, and specifically discloses: step S1, obtaining a water level image corresponding to the water level gauge position collected in a water level detection scenario, and during initialization, using the first water level image I 0 as a reference to obtain the actual height y_t 0 of the water level line at the time of initialization; step S2, using a water level gauge detection model to detect the water level gauge position in the first water level image I 0, and cropping the corresponding water level gauge image J 0; step S3, using the water level line detection model to detect the relative coordinate y_p 0 of the water level line in the water level gauge image J 0; step S4, obtaining an initial value K of the conversion rate K p between the actual height of the water level line and the relative coordinate based on the water level gauge length M, the relative coordinate y_p 0 and the actual height y_t0 of the water level line at the time of initialization. 0; p represents the water level line detection sequence, and its value is a natural number greater than or equal to 0; when p is 0, it indicates the initialization of the detection sequence; step S5, in the subsequent detection process, the water level image is acquired according to the set period, and for the water level image I n of the current frame, the water level gauge detection model is used to perform water level gauge detection, and then the water level line detection model is used to detect and output the relative coordinates y_p n of the water level line, where n is a natural number greater than or equal to 1; step S6, based on the water level line relative coordinates y_p n and the conversion rate K n-1, the actual height y_t n of the water level line corresponding to the water level image I n of the current frame is calculated.
[0006] Chinese patent document CN113221898A discloses a method for automatic water level gauge reading, and specifically discloses: step S1, preprocessing a scale image to generate a binary image; wherein the scale is a water level gauge; step S2, detecting the inclination angle of the straight line at the edge of the scale in the binary image through Hough transform, and adjusting the image according to the straight line inclination angle; step S3, performing pixel-level calculation on the adjusted image to obtain a scale matrix; step S4, judging whether the scale matrix conforms to prior knowledge; if not, correcting the scale matrix; step S5, determining the scale reading based on the corrected scale data.
[0007] Chinese patent document CN109543596A discloses a water level monitoring method, and specifically discloses: step S1, inputting a first image containing a water level gauge into a pre-trained first convolutional neural network model to determine the first position information of a water level gauge prediction box in the first image; step S2, extracting a second image corresponding to the water level gauge from the first image based on the first position information, and inputting the second image into a pre-trained second convolutional neural network model to determine the second position information of a digital prediction box on the water level gauge in the second image, and identifying the numbers in each digital prediction box based on the second position information; step S3, determining the target number corresponding to the water surface based on the identified number, and determining the water level height based on the target number and the color of the target number.
[0008] In summary, current vision-based intelligent devices need to detect the water level scale corresponding to the current water surface when implementing water level detection. When the water level scale scale is blocked, water level detection cannot be effectively achieved. The method of relying on the difference between different images to achieve water level detection has poor anti-interference ability. For example, if the camera shakes or the angle changes slightly, there will be certain errors in the detection results. Summary of the Invention
[0009] In view of the deficiencies of the prior art, the present invention discloses a water level detection system based on image segmentation and target detection technology.
[0010] The invention also discloses a water level detection method based on image segmentation and target detection technology.
[0011] The present invention addresses the problems of insufficient accuracy, poor anti-interference ability and inability to obtain readings when the water level gauge is blocked in existing intelligent devices. It uses a combination of segmentation technology and target detection technology to detect the water level.
[0012] The detailed technical solutions of the present invention are as follows:
[0013] A water level detection system based on image segmentation and target detection technology is characterized by including a fixed-point camera, a water level gauge, and a platform deployed with a water level detection algorithm based on image segmentation and target detection technology; the fixed-point camera obtains an image of the water level gauge and transmits the image to the platform via a wireless network to ultimately obtain the water level height.
[0014] A water level detection method based on image segmentation and target detection technology, characterized by comprising:
[0015] Step S1, acquiring a visible light image of a target scene, wherein the target scene at least includes a river where a water level gauge is placed;
[0016] Step S2: Process the visible light image using an image segmentation and detection model:
[0017] A mask image is obtained by segmenting the image.
[0018] Obtaining detection results through the detection model, including the coordinates of the water level gauge, the position coordinates of the water level gauge scale, the position coordinates of the stain on the water level gauge, and the corresponding confidence levels;
[0019] The image segmentation and detection model uses an integrated neural network, and may also use independent image segmentation networks and target detection networks, wherein image segmentation is used to segment the image to be tested into corresponding mask images, and the detection model is used to identify the coordinates of the water level gauge, the position coordinates of the water level gauge scale, and the position coordinates of the stain on the water level gauge; the image segmentation and detection models are both conventional neural network models in the prior art, and as long as the output of the above-mentioned mask image and the output of the target coordinates are achieved, the technical features of the present invention are realized;
[0020] Step S3, determining the exact position of the water level gauge, includes two information processing paths:
[0021] The label information of the mask image is filtered, and the filtered mask image is binarized to obtain a binary mask image, and the position coordinate information of the water level scale corresponding to the binary mask image is obtained;
[0022] The other way is to obtain the water level gauge coordinate information in the detection result;
[0023] The position coordinates of the water level gauge along the route are calculated by intersection and union ratio with the position coordinates of the water level gauges whose confidence level in the detection results is greater than a preset confidence threshold, and the position coordinates of the water level gauge corresponding to the maximum intersection and union ratio are selected as the accurate position;
[0024] Step S4, determining whether there is stain on the water level gauge, includes two information processing paths:
[0025] The label information of the mask image is filtered, and the filtered mask image is binarized to obtain a binary mask image, and the position coordinate information of the stain corresponding to the binary mask image is obtained;
[0026] The other way is to obtain the stain coordinate information in the detection result;
[0027] By comparing the stains in the above two paths, it is determined whether there is stain on the water level gauge;
[0028] Calculate the pixel height of the water level gauge based on whether there is stain on it:
[0029] If there is a stain, the pixel height of the water level gauge is the sum of the pixel height of the water level gauge and the pixel height of the stain on the water level gauge;
[0030] If there is no stain, the pixel distance of the water gauge height is the pixel height of the water gauge;
[0031] Step S5, screening and calibrating the detection results of the position coordinates of the water level gauge scale, correcting the center coordinates of all the screened digital detection frames to the same straight line; calculating the pixel distances of the corrected adjacent digital numbers, removing outliers from the pixel distances of all adjacent digital numbers, and calculating the average value of the remaining pixel distances after screening out values with excessive distance deviations;
[0032] Step S6, based on the actual distance between the scale numbers of the water level gauge, calculate the mapping relationship from pixel distance to actual distance; map the pixel height of the water level gauge, map the pixel height of the water level gauge to the actual distance, and obtain the actual height of the water level gauge above the water surface.
[0033] Preferably, according to the present invention, in step S2, the image segmentation and detection model is a YoloV5 neural network model loaded with a segmentation head, so as to achieve simultaneous segmentation and detection;
[0034] The specific steps of step S2 include:
[0035] Training the image segmentation and detection model, recognizing the visible light image to be tested and outputting the result;
[0036] The training of the image segmentation and detection model includes steps S201 to S203:
[0037] Step S201: Collect water gauge images in different scenes, perform image segmentation annotation and target detection annotation using annotation tools, and generate annotation files of json type and xml type respectively;
[0038] Step S202: Process the image annotation files respectively, generate a mask image corresponding to the image for the json type annotation file, and generate a corresponding txt file for the xml type annotation file;
[0039] Step S203, using the water gauge images in different scenes and the corresponding processed annotation files to train the image segmentation and detection model;
[0040] Identify the visible light image to be tested and output the result:
[0041] Step S204 , using the trained image segmentation and detection model to identify the visible light image to be tested, and outputting the mask image, water level gauge coordinates, position coordinates of the water level gauge scale, and position coordinates of the stain on the water level gauge corresponding to the visible light image to be tested.
[0042] According to a preferred embodiment of the present invention, the step S3 specifically includes:
[0043] Step S301: The segmented mask image is filtered using the RGB channels and label information is added: the green part is the water level gauge, the blue part is the reflection of the water level gauge, the gray part is the stain between the water level gauge and the water level, and the red part is the obstruction between the water level gauge and the water level.
[0044] Step S302, performing binarization processing on the screened mask image to obtain a binarized mask image;
[0045] Step S303, performing contour search on the binarized mask image, preferably using a contour search function; preferably, the contour search function is the cv2.findCountours function in Opencv;
[0046] Step S304, finding the minimum circumscribed rectangle of the found contour;
[0047] Step S305: preset the noise point area threshold:
[0048] When the calculated area of the minimum circumscribed rectangle is less than or equal to the area threshold, it is determined to be a noise point and the contour found there is deleted;
[0049] Otherwise, save the position coordinates of the minimum bounding rectangle in the mask image;
[0050] Step S306, preset a water level gauge confidence threshold; perform intersection-and-union calculation on the position coordinates of the minimum circumscribed rectangle and the water level gauge position coordinates in the detection result whose confidence is greater than the preset water level gauge confidence threshold, and select the water level gauge position coordinates corresponding to the maximum intersection-and-union ratio as the accurate position.
[0051] According to a preferred embodiment of the present invention, in step S4, the specific method of comparing the stains in the two paths to determine whether there is stain on the water level gauge includes:
[0052] Step S401: Preset a stain confidence threshold; calculate the intersection and union ratio of the position coordinates of the minimum bounding rectangle and the position coordinates of stains in the detection results whose confidence is greater than the preset stain confidence threshold;
[0053] A first stain intersection-and-union ratio threshold is preset; when the intersection-and-union ratio is greater than the preset first stain intersection-and-union ratio threshold, it is determined that there is a stain at this position on the water level gauge.
[0054] According to a preferred embodiment of the present invention, in step S4, the specific method of comparing the stains in the two paths to determine whether there is stain on the water level gauge includes:
[0055] In step S402, if the result of one of the two paths shows that there is a stain on the water level gauge, the intersection-and-union ratio is calculated based on the coordinates of the stain position and the coordinates of the water level gauge position:
[0056] A second stain intersection-and-union ratio threshold is preset; when the intersection-and-union ratio is greater than the preset second stain intersection-and-union ratio threshold, it is determined that there is a stain at this position on the water level gauge.
[0057] According to the preferred embodiment of the present invention, in step S5, the specific steps of screening and calibrating the detection results of the position coordinates of the water level gauge scale include:
[0058] Step S501: preset a scale confidence threshold; filter the detection frames of all scale numbers on the water level gauge detected by the detection module: discard the detection frames with a value less than the scale confidence threshold, and discard the detection frames not on the water level gauge;
[0059] Step S502, performing linear fitting on the center coordinates of the filtered scale digital detection frame to form a fitting straight line;
[0060] Step S503, calculating the projection of the center coordinates of the scale digital detection frame onto the fitting line to correct the position of the scale digital detection frame;
[0061] Step S504, calculating the pixel distance between the center points of the correction scale digit detection frames to obtain the pixel distance between adjacent digits;
[0062] Step S505, calculating the mean of all pixel distances;
[0063] Step S506, calculating the standard deviation between all pixel distances and the mean;
[0064] Step S507: When the difference between a certain pixel distance and the mean is greater than three times the standard deviation σ, the pixel distance is an outlier. Outlier removal is a method. Here, an outlier refers to an abnormal value of the distance between adjacent point numbers.
[0065] Step S508, deleting all pixel distances determined to be outliers;
[0066] Step S509: taking the average value of all remaining adjacent digital pixel distances as the final pixel distance.
[0067] Preferably, according to the present invention, the specific steps in step S6 include:
[0068] Step S601, based on the actual distance between the water level gauge scale digits, calculate the mapping relationship f=l / c from pixel distance to actual distance, where c represents the pixel distance; l represents the actual distance between the water level gauge scale digits, and the pixel distance refers to the recalculated average value;
[0069] Step S602, mapping the pixel height of the water level gauge, mapping the pixel height of the water level gauge to the actual distance, and obtaining the actual height of the water level gauge on the water surface L = f*C, where f is the mapping relationship from pixel distance to actual distance; C represents the pixel distance of the water level gauge, wherein, if the actual length of the water level gauge is known, the actual length of the water level gauge and the actual height L of the water level gauge on the water surface can be subtracted to obtain the current water level height.
[0070] Compared with the prior art, the advantages and positive effects of the present invention are:
[0071] 1. Compare the segmentation algorithm and the detection algorithm to improve the accuracy of water level gauge detection.
[0072] 2. By mapping the pixel height of the water level gauge to the actual height, detection errors caused by inaccurate readings can be avoided.
[0073] 3. When there is an obstruction at the bottom of the water level gauge, although the water level gauge reading is invisible, its shape has a lowest point. Therefore, the method of the present invention can avoid the problem of being unable to read the water level gauge due to the existence of the obstruction to the greatest extent.
[0074] 4. When there are stains on the water level gauge, the stains completely block the reading of the water level gauge. The present invention solves the problem of inaccurate detection caused by invisible readings by detecting the stains on the water level gauge and calculating the pixel height.
[0075] 5. The present invention combines image segmentation and target detection technology to realize water level detection. By comparing the results of segmentation and detection with each other, the accuracy is improved, and the contour of the water level gauge is extracted using the segmentation method. Even if there is an obstruction that partially blocks the water level gauge, the lowest point of the water level gauge can be found. At the same time, by segmenting and detecting stains that completely block the water level gauge, the height of the part of the water level gauge blocked by the stain is effectively calculated, and then the complete height of the water level gauge is calculated. The present invention does not require personnel maintenance, facilitates remote program upgrades, reduces labor costs, has high detection accuracy, and strong anti-interference ability. BRIEF DESCRIPTION OF THE DRAWINGS
[0076] Figure 1 This is a flow chart of an embodiment of the mud water level detection method provided by the present invention;
[0077] Figure 2 This is a result diagram of target detection in the water level detection method provided by the present invention;
[0078] Figure 3 It is the mask image of the water level gauge that has been processed after image segmentation in the water level detection method provided by the present invention;
[0079] Figure 4 It is a mask image of the water level gauge reflection that has been processed after image segmentation in the water level detection method provided by the present invention;
[0080] Figure 5 It is a mask image of the stain that has been processed after image segmentation in the water level detection method provided by the present invention. Specific implementation methods
[0081] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention will be further described in detail below with reference to the accompanying drawings and examples.
[0082] It should be noted that in the description of the present invention, terms such as "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer" indicating directions or positional relationships are based on the directions or positional relationships shown in the accompanying drawings. These are merely for ease of description and do not indicate or imply that the device or component described must have a specific orientation, be constructed, or operate in a specific orientation. Therefore, they should not be construed as limitations on the present invention. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0083] Example 1
[0084] A water level detection system based on image segmentation and target detection technology includes a fixed-point camera, a water level gauge, and a platform deployed with a water level detection algorithm based on image segmentation and target detection technology; the fixed-point camera obtains an image of the water level gauge and transmits the image to the platform via a wireless network to ultimately obtain the water level height.
[0085] Example 2
[0086] like Figure 1 As shown, a water level detection method based on image segmentation and target detection technology includes:
[0087] Step S1, acquiring a visible light image of a target scene, wherein the target scene at least includes a river where a water level gauge is placed;
[0088] Step S2: Process the visible light image using an image segmentation and detection model:
[0089] A mask image is obtained by segmenting the image.
[0090] The detection results are obtained by the detection model, including the coordinates of the water level gauge, the position coordinates of the water level gauge scale, the position coordinates of the stain on the water level gauge and the corresponding confidence level; Figure 2 As shown, the contents displayed from top to bottom are explained as follows:
[0091] “ruler 0.79” means that the confidence level of the test result is 0.79;
[0092] "9 0.84" means that the confidence level of the test result of the water level gauge mark 9 is 0.84;
[0093] "8 0.83" means that the confidence level of the test result of the water level gauge mark 8 is 0.83;
[0094] "7 0.71" means that the confidence level of the test result of the water level gauge mark 7 is 0.71;
[0095] "-ruler 0.78" means that the confidence level in the detection result being the reflection of the water gauge is 0.78.
[0096] The image segmentation and detection model uses an integrated neural network, and may also use independent image segmentation networks and target detection networks, wherein image segmentation is used to segment the image to be tested into corresponding mask images, and the detection model is used to identify the coordinates of the water level gauge, the position coordinates of the water level gauge scale, and the position coordinates of the stain on the water level gauge; the image segmentation and detection models are both conventional neural network models in the prior art, and as long as the output of the above-mentioned mask image and the output of the target coordinates are achieved, the technical features of the present invention are realized;
[0097] Step S3, determining the exact position of the water level gauge, includes two information processing paths:
[0098] The label information of the mask image is filtered, and then the filtered mask image is binarized to obtain a binary mask image. The binary mask image of the water level gauge is shown in the attached figure. Figure 3 As shown in the attached figure, the binary mask image of the water level gauge reflection is shown in the attached figure. Figure 4 As shown, the position coordinate information of the water level gauge corresponding to the binary mask image is obtained;
[0099] The other way is to obtain the water level gauge coordinate information in the detection result;
[0100] The position coordinates of the water level gauge along the route are calculated by intersection and union ratio with the position coordinates of the water level gauges whose confidence level in the detection results is greater than a preset confidence threshold, and the position coordinates of the water level gauge corresponding to the maximum intersection and union ratio are selected as the accurate position;
[0101] Step S4, determining whether there is stain on the water level gauge, includes two information processing paths:
[0102] The label information of the mask image is filtered, and then the filtered mask image is binarized to obtain a binary mask image, as shown in the attached figure. Figure 5 As shown, the position coordinate information of the stain corresponding to the binary mask image is obtained;
[0103] The other way is to obtain the stain coordinate information in the detection result;
[0104] By comparing the stains in the above two paths, it is determined whether there is stain on the water level gauge;
[0105] Calculate the pixel height of the water level gauge based on whether there is stain on it:
[0106] If there is a stain, the pixel height of the water level gauge is the sum of the pixel height of the water level gauge and the pixel height of the stain on the water level gauge;
[0107] If there is no stain, the pixel distance of the water gauge height is the pixel height of the water gauge;
[0108] Step S5, screening and calibrating the detection results of the position coordinates of the water level gauge scale, correcting the center coordinates of all the screened digital detection frames to the same straight line; calculating the pixel distances of the corrected adjacent digital numbers, removing outliers from the pixel distances of all adjacent digital numbers, and calculating the average value of the remaining pixel distances after screening out values with excessive distance deviations;
[0109] Step S6, based on the actual distance between the scale numbers of the water level gauge, calculate the mapping relationship from pixel distance to actual distance; map the pixel height of the water level gauge, map the pixel height of the water level gauge to the actual distance, and obtain the actual height of the water level gauge above the water surface.
[0110] Example 3
[0111] As in the method described in Example 2, in step S2, the image segmentation and detection model is a YoloV5 neural network model loaded with a segmentation head, so as to achieve simultaneous segmentation and detection;
[0112] The specific steps of step S2 include:
[0113] Training the image segmentation and detection model, recognizing the visible light image to be tested and outputting the result;
[0114] The training of the image segmentation and detection model includes steps S201 to S203:
[0115] Step S201: Collect water gauge images in different scenes, perform image segmentation annotation and target detection annotation using annotation tools, and generate annotation files of json type and xml type respectively;
[0116] Step S202: Process the image annotation files respectively, generate a mask image corresponding to the image for the json type annotation file, and generate a corresponding txt file for the xml type annotation file;
[0117] Step S203, using the water gauge images in different scenes and the corresponding processed annotation files to train the image segmentation and detection model;
[0118] Identify the visible light image to be tested and output the result:
[0119] Step S204 , using the trained image segmentation and detection model to identify the visible light image to be tested, and outputting the mask image, water level gauge coordinates, position coordinates of the water level gauge scale, and position coordinates of the stain on the water level gauge corresponding to the visible light image to be tested.
[0120] Example 4
[0121] As in the method described in Example 2, step S3 specifically includes:
[0122] Step S301: The segmented mask image is filtered using the RGB channels and label information is added: the green part is the water level gauge, the blue part is the reflection of the water level gauge, the gray part is the stain between the water level gauge and the water level, and the red part is the obstruction between the water level gauge and the water level.
[0123] Step S302, performing binarization processing on the screened mask image to obtain a binarized mask image;
[0124] Step S303, performing contour search on the binarized mask image, preferably using a contour search function; preferably, the contour search function is the cv2.findCountours function in Opencv;
[0125] Step S304, finding the minimum circumscribed rectangle of the found contour;
[0126] Step S305: preset the noise point area threshold:
[0127] When the calculated area of the minimum circumscribed rectangle is less than or equal to the area threshold, it is determined to be a noise point and the contour found there is deleted;
[0128] Otherwise, save the position coordinates of the minimum bounding rectangle in the mask image;
[0129] Step S306, preset a water level gauge confidence threshold; perform intersection-and-union calculation on the position coordinates of the minimum circumscribed rectangle and the water level gauge position coordinates in the detection result whose confidence is greater than the preset water level gauge confidence threshold, and select the water level gauge position coordinates corresponding to the maximum intersection-and-union ratio as the accurate position.
[0130] Example 5
[0131] As in the method described in Example 2, in step S4, the specific method of comparing the stains in the two paths to determine whether there is a stain on the water level gauge includes:
[0132] Step S401: Preset a stain confidence threshold; calculate the intersection and union ratio of the position coordinates of the minimum bounding rectangle and the position coordinates of stains in the detection results whose confidence is greater than the preset stain confidence threshold;
[0133] A first stain intersection-and-union ratio threshold is preset; when the intersection-and-union ratio is greater than the preset first stain intersection-and-union ratio threshold, it is determined that there is a stain at this position on the water level gauge.
[0134] Example 6
[0135] As in the method described in Example 2, in step S4, the specific method of comparing the stains in the two paths to determine whether there is a stain on the water level gauge includes:
[0136] In step S402, if the result of one of the two paths shows that there is a stain on the water level gauge, the intersection-and-union ratio is calculated based on the coordinates of the stain position and the coordinates of the water level gauge position:
[0137] A second stain intersection-and-union ratio threshold is preset; when the intersection-and-union ratio is greater than the preset second stain intersection-and-union ratio threshold, it is determined that there is a stain at this position on the water level gauge.
[0138] Example 7
[0139] As in the method described in Example 2, in step S5, the specific steps of screening and calibrating the detection results of the position coordinates of the water level gauge scale include:
[0140] Step S501: preset a scale confidence threshold; filter the detection frames of all scale numbers on the water level gauge detected by the detection module: discard the detection frames with a value less than the scale confidence threshold, and discard the detection frames not on the water level gauge;
[0141] Step S502, performing linear fitting on the center coordinates of the filtered scale digital detection frame to form a fitting straight line;
[0142] Step S503, calculating the projection of the center coordinates of the scale digital detection frame onto the fitting line to correct the position of the scale digital detection frame;
[0143] Step S504, calculating the pixel distance between the center points of the correction scale digit detection frames to obtain the pixel distance between adjacent digits;
[0144] Step S505, calculating the mean of all pixel distances;
[0145] Step S506, calculating the standard deviation between all pixel distances and the mean;
[0146] Step S507: When the difference between a certain pixel distance and the mean is greater than three times the standard deviation σ, the pixel distance is an outlier. Outlier removal is a method. Here, an outlier refers to an abnormal value of the distance between adjacent point numbers.
[0147] Step S508, deleting all pixel distances determined to be outliers;
[0148] Step S509: taking the average value of all remaining adjacent digital pixel distances as the final pixel distance.
[0149] Example 8
[0150] As in the method described in Example 2, the specific steps in step S6 include:
[0151] Step S601, based on the actual distance between the water level gauge scale digits, calculate the mapping relationship f=l / c from pixel distance to actual distance, where c represents the pixel distance; l represents the actual distance between the water level gauge scale digits, and the pixel distance refers to the recalculated average value;
[0152] Step S602, mapping the pixel height of the water level gauge, mapping the pixel height of the water level gauge to the actual distance, and obtaining the actual height of the water level gauge on the water surface L = f*C, where f is the mapping relationship from pixel distance to actual distance; C represents the pixel distance of the water level gauge, wherein, if the actual length of the water level gauge is known, the actual length of the water level gauge and the actual height L of the water level gauge on the water surface can be subtracted to obtain the current water level height.
[0153] Through the above embodiment, the algorithm readings of the water level gauges numbered 1, 2, 3, and 4 are performed, and the absolute errors are obtained by comparing with the manual readings, see Table 1. It can be seen that the error between the detection method of the present invention and the manual readings is small, which meets the needs of actual scenarios.
[0154] Table 1 Water level gauge test results (reading refers to the height of the water level gauge above the water surface)
[0155] serial number 1 2 3 4 Manual reading / dm 41.90 15.60 18.10 11.50 Algorithm reading / dm 42.09 16.26 18.32 11.39 Absolute error / dm 0.19 0.46 0.22 0.11
Claims
1. A water level detection method based on image segmentation and target detection technology, characterized in that: include: Step S1, acquiring a visible light image of a target scene, wherein the target scene at least includes a river where a water level gauge is placed; Step S2: Process the visible light image using an image segmentation and detection model: A mask image is obtained by segmenting the image. Obtaining detection results through the detection model, including the coordinates of the water level gauge, the position coordinates of the water level gauge scale, the position coordinates of the stain on the water level gauge, and the corresponding confidence levels; Step S3, determining the exact position of the water level gauge, includes two information processing paths: The label information of the mask image is filtered, and the filtered mask image is binarized to obtain a binary mask image, and the position coordinate information of the water level scale corresponding to the binary mask image is obtained; The other way is to obtain the water level gauge coordinate information in the detection result; The position coordinates of the water level gauge along the route are calculated by intersection and union ratio with the position coordinates of the water level gauges whose confidence level in the detection results is greater than a preset confidence threshold, and the position coordinates of the water level gauge corresponding to the maximum intersection and union ratio are selected as the accurate position; Step S4, determining whether there is stain on the water level gauge, includes two information processing paths: The label information of the mask image is filtered, and the filtered mask image is binarized to obtain a binary mask image, and the position coordinate information of the stain corresponding to the binary mask image is obtained; The other way is to obtain the stain coordinate information in the detection result; By comparing the stains in the above two paths, it is determined whether there is stain on the water level gauge; Calculate the pixel height of the water level gauge based on whether there is stain on it: If there is a stain, the pixel height of the water level gauge is the sum of the pixel height of the water level gauge and the pixel height of the stain on the water level gauge; If there is no stain, the pixel distance of the water gauge height is the pixel height of the water gauge; Step S5, screening and calibrating the detection results of the position coordinates of the water level gauge scale, and correcting the center coordinates of all screened digital detection frames to the same straight line; Calculating the pixel distances of the corrected adjacent digits, removing outliers from the pixel distances of all adjacent digits, filtering out values with excessive distance deviations, and then calculating the average value of the remaining pixel distances; Step S6, based on the actual distance between the scale numbers of the water level gauge, calculate the mapping relationship from pixel distance to actual distance; map the pixel height of the water level gauge, map the pixel height of the water level gauge to the actual distance, and obtain the actual height of the water level gauge above the water surface.
2. The water level detection method based on image segmentation and target detection technology as claimed in claim 1, characterized in that: In step S2, the image segmentation and detection model is a YoloV5 neural network model loaded with a segmentation head to achieve simultaneous segmentation and detection; The specific steps of step S2 include: Training the image segmentation and detection model, recognizing the visible light image to be tested and outputting the result; The training of the image segmentation and detection model includes steps S201 to S203: Step S201: Collect water gauge images in different scenes, perform image segmentation annotation and target detection annotation using annotation tools, and generate annotation files of json type and xml type respectively; Step S202: Process the annotation files separately, generate a mask image corresponding to the image for the annotation file of the json type, and generate a corresponding txt file for the annotation file of the xml type; Step S203, using the water gauge images in different scenes and the corresponding processed annotation files to train the image segmentation and detection model; Identify the visible light image to be tested and output the result: Step S204 , using the trained image segmentation and detection model to identify the visible light image to be tested, and outputting the mask image, water level gauge coordinates, position coordinates of the water level gauge scale, and position coordinates of the stain on the water level gauge corresponding to the visible light image to be tested.
3. The water level detection method based on image segmentation and target detection technology as claimed in claim 1, characterized in that: The step S3 specifically includes: Step S301: The segmented mask image is filtered using the RGB channels and label information is added: the green part is the water level gauge, the blue part is the reflection of the water level gauge, the gray part is the stain between the water level gauge and the water level, and the red part is the obstruction between the water level gauge and the water level. Step S302, performing binarization processing on the screened mask image to obtain a binarized mask image; Step S303, performing contour search on the binarized mask image, wherein the function used for the contour search is the cv2.findCountours function in Opencv; Step S304, finding the minimum circumscribed rectangle of the found contour; Step S305: preset the noise point area threshold: When the calculated area of the minimum circumscribed rectangle is less than or equal to the area threshold, it is determined to be a noise point and the contour found there is deleted; Otherwise, save the position coordinates of the minimum bounding rectangle in the mask image; Step S306, preset a water level gauge confidence threshold; perform intersection-and-union calculation on the position coordinates of the minimum circumscribed rectangle and the water level gauge position coordinates in the detection result whose confidence is greater than the preset water level gauge confidence threshold, and select the water level gauge position coordinates corresponding to the maximum intersection-and-union ratio as the accurate position.
4. The water level detection method based on image segmentation and target detection technology as claimed in claim 3, characterized in that: In step S4, the specific method of comparing the stains in the two paths to determine whether there is stain on the water level gauge includes: Step S401: Preset a stain confidence threshold; calculate the intersection and union ratio of the position coordinates of the minimum bounding rectangle and the position coordinates of stains in the detection results whose confidence is greater than the preset stain confidence threshold; A first stain intersection-and-union ratio threshold is preset; when the intersection-and-union ratio is greater than the preset first stain intersection-and-union ratio threshold, it is determined that there is a stain at this position on the water level gauge.
5. The water level detection method based on image segmentation and target detection technology as claimed in claim 1, characterized in that: In step S4, the specific method of comparing the stains in the two paths to determine whether there is stain on the water level gauge includes: In step S402, if the result of one of the two paths shows that there is a stain on the water level gauge, the intersection-and-union ratio is calculated based on the coordinates of the stain position and the coordinates of the water level gauge position: A second stain intersection-and-union ratio threshold is preset; when the intersection-and-union ratio is greater than the preset second stain intersection-and-union ratio threshold, it is determined that there is a stain at this position on the water level gauge.
6. The water level detection method based on image segmentation and target detection technology as claimed in claim 1, characterized in that: In step S5, the specific steps of screening and calibrating the detection results of the position coordinates of the water level gauge scale include: Step S501: preset a scale confidence threshold; filter the detection frames of all scale numbers on the water level gauge detected by the detection module: discard the detection frames with a value less than the scale confidence threshold, and discard the detection frames not on the water level gauge; Step S502, performing linear fitting on the center coordinates of the filtered scale digital detection frame to form a fitting straight line; Step S503, calculating the projection of the center coordinates of the scale digital detection frame onto the fitting line to correct the position of the scale digital detection frame; Step S504, calculating the pixel distance between the center points of the correction scale digit detection frames to obtain the pixel distance between adjacent digits; Step S505, calculating the mean of all pixel distances; Step S506, calculating the standard deviation between all pixel distances and the mean; Step S507: when the difference between a certain pixel distance and the mean is greater than three times the standard deviation σ, the pixel distance is an outlier; Step S508, deleting all pixel distances determined to be outliers; Step S509: taking the average value of all remaining adjacent digital pixel distances as the final pixel distance.
7. The water level detection method based on image segmentation and target detection technology as claimed in claim 1, characterized in that: The specific steps in step S6 include: Step S601, based on the actual distance between the water level gauge scale digits, calculate the mapping relationship f = l / c from pixel distance to actual distance, where c represents the pixel distance; l represents the actual distance between the water level gauge scale digits; Step S602, mapping the pixel height of the water level gauge, mapping the pixel height of the water level gauge to the actual distance, and obtaining the actual height of the water level gauge on the water surface L=f*C, where f is the mapping relationship from pixel distance to actual distance; C represents the pixel distance of the water level gauge.
Citation Information
Patent Citations
Water level monitoring method and device, electronic device and storage medium
CN109543596A
Water level detection method, device and system based on water gauge image
CN112991342A
Automatic water gauge reading method
CN113221898A
Water gauge image water level automatic reading method and system based on Mask RCNN algorithm
CN112766274A