Sewage treatment plant water level safety detection method and system based on AI vision algorithm
By using multi-frame fusion and adaptive preprocessing with AI vision algorithms, combined with HSV color filtering and time dithering mechanism, the problems of identification accuracy and stability of water level monitoring in sewage treatment plants have been solved, reducing operation and maintenance costs and improving safety redundancy.
Patent Information
- Application Number
- CN202511140762.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-14
- Publication Date
- 2025-12-23
AI Technical Summary
Existing water level monitoring methods for wastewater treatment plants lack accuracy in complex environments, are prone to misjudgment, have unstable alarm mechanisms, high resource consumption, high operation and maintenance costs, and are difficult to adapt to scenes with blurry images and low light.
A water level safety detection method based on AI vision algorithms is adopted. Through multi-frame fusion and adaptive preprocessing, impurities and steam interference are suppressed, the monitoring area is defined, HSV color filtering is used to identify water body characteristics, and alarm is triggered by a combination of dual thresholds and time anti-shake mechanism to achieve multimodal alarm.
It improves the accuracy and stability of water level identification, reduces operation and maintenance costs, enhances safety redundancy, and ensures the continuous and stable operation of the sewage treatment process.
Smart Images

Figure CN121190789A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent detection technology for wastewater treatment, and in particular to a method and system for detecting the safety of water levels in wastewater treatment plants based on AI visual algorithms. Background Technology
[0002] In wastewater treatment plants, industrial wastewater treatment, and urban sewage pipe networks, wastewater tank level monitoring is a core component for ensuring stable treatment processes and preventing overflows or pump idling. Early wastewater treatment plant level monitoring relied heavily on manual inspections (such as daily checks of level gauges) or single-point sensors (such as ultrasonic level gauges), which had significant limitations: manual inspections were infrequent (usually every 2-4 hours), making it impossible to promptly detect sudden level anomalies (such as a sudden increase in influent flow); sensors were susceptible to the corrosiveness of wastewater (such as the presence of acids, alkalis, and suspended solids) and water vapor interference (such as steam above the tank), frequently resulting in measurement drift or malfunctions, requiring regular maintenance (at least monthly calibration), leading to high maintenance costs.
[0003] With the development of computer vision technology, image-based wastewater level monitoring methods are gradually being applied. These methods use cameras installed above wastewater tanks to capture images, combined with image processing techniques to identify water level lines, replacing traditional methods. However, existing methods still face challenges in wastewater treatment plant scenarios: the recognition logic is not optimized for the complex environment of wastewater tanks (such as floating impurities and scale adhering to the tank walls); the fixed frequency of image processing per frame leads to stuttering at high-resolution video; and the alarm mechanism is simple (e.g., alarming when a threshold is exceeded), failing to consider short-term fluctuations in wastewater level (such as inrush water), easily triggering alarms frequently and interfering with maintenance personnel. Specifically, these include:
[0004] (1) Wastewater level recognition technology: Existing vision-based wastewater level monitoring methods mostly extract water level lines through simple edge detection (such as the Canny operator) or grayscale thresholding, which rely on the "grayscale difference between the liquid surface and the pool wall". However, in the wastewater treatment plant scenario, sludge flocs and foam often float on the liquid surface, and dirt adheres to the pool wall, resulting in a blurred "liquid surface-pool wall" boundary; moreover, the interior of the pool is dimly lit (most wastewater pools are closed or semi-closed structures), resulting in low image contrast. Traditional algorithms are prone to misjudging "impurity edges" as water level lines, with recognition errors reaching 5-10cm, which cannot meet the ±2cm accuracy requirement of wastewater treatment plants.
[0005] (2) Status Judgment and Alarm Technology: Traditional sewage water level status judgment mostly adopts the "fixed threshold + single trigger" mechanism, that is, an alarm is triggered immediately when the water level exceeds the threshold. However, in the sewage treatment process, the water level often changes briefly near the threshold due to the periodic fluctuations of influent and effluent (such as water level fluctuations caused by the alternating operation of influent pumps). Traditional methods will misjudge such normal fluctuations as abnormalities and frequently trigger alarms. At the same time, the alarm prompts are mostly single sound and light signals (such as buzzers) without combining quantitative information on water level height (such as "the current water level is only 30cm away from overflow"), making it difficult for operation and maintenance personnel to judge the degree of urgency in a timely manner.
[0006] (3) Scene adaptation and performance optimization technology: Sewage treatment plant cameras often produce blurry images due to water vapor and dust. Existing methods do not optimize preprocessing logic for such low-quality images, resulting in poor recognition stability (90% accuracy in sunny weather, dropping below 60% in cloudy or dusty weather). To ensure real-time processing of each frame, high resource consumption (CPU utilization >70%) is achieved. However, industrial control hosts in sewage treatment plants typically have limited configurations and are prone to resource conflicts with other control programs. This leads to the following technical defects:
[0007] (1) Insufficient identification accuracy: The identification logic was not optimized for the characteristics of sewage treatment plants, such as "many impurities on the liquid surface and dirt on the pool wall". The ability to distinguish between "real water level line" and "impurity edge" is weak, and the misjudgment rate is high (>15%). Furthermore, the effective monitoring area of the sewage pool is not defined, and the external environment (such as pool side pipes and ladders) is easily misjudged as water level reference objects, resulting in a measurement deviation of more than 10cm, which affects the accuracy of pump start-stop control.
[0008] (2) Poor alarm and interaction experience: The lack of a water level fluctuation anti-shaking mechanism causes frequent alarms (up to dozens of times per day) for normal operating conditions such as "water level briefly exceeds the threshold and then quickly falls back", which causes maintenance personnel to "desensitize" the alarm signals; the voice prompts lack quantitative information and only indicate "abnormal water level", failing to convey key information such as "current water level height" and "difference from the danger threshold", thus prolonging the emergency response time.
[0009] (3) Insufficient scene adaptability and performance: The preprocessing (such as defogging and contrast enhancement) was not optimized for the "blurry image and dim lighting" scene of the sewage treatment plant. On rainy days or when the pool is covered by steam, the missed detection rate rises to more than 30%, requiring manual verification. The sampling frequency was reduced to adapt to the performance of the industrial host (such as once every 30 seconds), which could not capture the sudden rise in water level in a short period of time (such as the sudden increase in water intake caused by pipe rupture), increasing the risk of sewage overflow.
[0010] Therefore, there is an urgent need to provide a new method and system for detecting water level safety in wastewater treatment plants based on AI visual algorithms to solve the above problems. Summary of the Invention
[0011] The technical problem to be solved by the present invention is to provide a method and system for water level safety detection in sewage treatment plants based on AI vision algorithms, which can improve the accuracy of water level identification in complex sewage pool scenarios, enhance the stability of water level anomaly judgment, reduce operation and maintenance costs, and improve safety redundancy.
[0012] To address the aforementioned technical problems, one technical solution adopted by this invention is: providing a method for detecting the safety of water levels in wastewater treatment plants based on AI visual algorithms, comprising the following steps:
[0013] S1: Read video frames for single-frame water level identification, perform real-time data cleaning and optimization based on the single-frame water level identification results, and suppress liquid surface impurities and steam interference through multi-frame fusion and adaptive preprocessing, while optimizing data flow to balance performance and real-time performance.
[0014] S2: Use a mask to generate the location of the sewage tank area and extract the effective ROI within the tank;
[0015] S3: Use HSV color filtering to identify water features, segment the liquid surface, and calculate the water level height;
[0016] S4: Determine the relationship between the current water level and the warning threshold, as well as the relationship between the current time and the interval between the last alarm and the anti-shake interval. If the composite judgment logic is satisfied at the same time, proceed to step S5; otherwise, the image annotation is normal.
[0017] S5: Utilizes visual and voice broadcasts for multimodal alarms and controls the frequency of alerts through time-based anti-shake.
[0018] In a preferred embodiment of the present invention, in step S1, real-time data cleaning employs a multi-frame sliding window to weighted smooth the single-frame water level identification result, and uses adaptive filtering and defogging enhancement algorithms to suppress surface impurities and steam interference. By calculating the local grayscale variance of the image, the bilateral filter kernel parameter σ is dynamically adjusted, and simultaneously, a dark channel prior algorithm is combined to remove steam atomization. The formula is as follows:
[0019]
[0020] Where J(x) is the image after defogging, I(x) is the original fogged image, A is the atmospheric light value, reflecting the fog concentration, t(x) is the transmittance, used to estimate the fog concentration, and t0 = 0.1.
[0021] In a preferred embodiment of the present invention, in step S1, optimizing data flow includes controlling the actual analysis frequency through frame skipping calculation, and dynamically adjusting the analysis interval according to the water level fluctuation amplitude.
[0022] The formula for calculating the actual analysis frequency by using frame skipping is as follows:
[0023] in:
[0024] Where, N skip This indicates the number of frames to skip, controlling the actual analysis interval. f is the original video frame rate, and T is the base analysis interval, adapting to the characteristics of slow water level changes in different wastewater treatment plants. For floor operations, H smooth It is the smoothed water level height;
[0025] The method for dynamically adjusting the analysis interval based on the amplitude of water level fluctuations is as follows:
[0026] The fluctuation amplitude is calculated using three consecutive frames of water level data. If |h t -h t-3 If the water level fluctuation exceeds 2cm, the analysis interval will be automatically shortened to T' seconds; when the water level stabilizes, i.e., the fluctuation is ≤2cm, the T-second interval will be automatically restored.
[0027] In a preferred embodiment of the present invention, step S2 specifically includes the following steps:
[0028] S201: Preset the vertex coordinates of the polygonal region based on the actual outline of the sewage tank;
[0029] S202: Generate a binary mask based on the above coordinates, which is represented as:
[0030]
[0031] Where M(x,y) is a binary mask image, (x,y) is the pixel coordinate of the image, and P is a preset polygonal region of the sewage pool, that is, pixels inside the pool are marked as valid regions, while the background outside the pool is marked as invalid regions.
[0032] S203: Pass Extract the effective region of interest (ROI) within the pool, where I roi (x,y) represents the effective region image within the pool, and I(x,y) represents the original image.
[0033] In a preferred embodiment of the present invention, step S3 specifically includes:
[0034] S301: Utilizing the characteristics of wastewater in the HSV color space, a liquid surface mask is generated, represented as follows:
[0035]
[0036] Among them, M water(x,y) represents the binary mask of the liquid surface, 255 represents the liquid surface area, and H(x,y), S(x,y), and V(x,y) are the hue, saturation, and lightness of the pixel, respectively.
[0037] S302: Extract the set of all non-zero pixel coordinates C from the liquid surface mask. water ={(x,y)|M water (x,y)=255}, if C water If empty, predict the current value based on the three most recent valid water levels and mark it as "invalid data"; otherwise, calculate the minimum y-coordinate of the liquid surface area. min,pixel =min{y|(x,y)∈C water The water level height is calculated using the following formula:
[0038] H actual =(y base,pixel -y min,pixel )·k
[0039] Among them, H actual This is the actual water level height, in meters; y base,pixel The preset y-coordinate of the pool bottom is given by y. min,pixel It is the minimum y-coordinate of the liquid surface in the image, and k is the pixel-to-actual-size mapping coefficient.
[0040] In a preferred embodiment of the present invention, in step S4, if the current water level exceeds the warning threshold and the interval between the current time and the last alarm exceeds the anti-shake interval, it is determined that the sewage treatment is abnormal and enters the multi-modal alarm mode; otherwise, no alarm is triggered.
[0041] In a preferred embodiment of the present invention, in step S5, visually, Chinese annotations are overlaid on the monitoring screen in real time to distinguish between normal and abnormal states; audio-wise, an independent thread is used for broadcasting, and its triggering logic is as follows:
[0042]
[0043] Among them, T speak Voice trigger flag, 1 for trigger, 0 for no trigger, S last S is the previous state marker. abnormal The current state is marked, Δt is the interval between the current time and the last voice recording, τ is the anti-shake interval, which is fixed at several seconds, ≠ is the logical NOT operation, and ∨ is the logical OR operation; when the state changes from normal to abnormal (S abnormal ≠S last Or conversely, or if the same state continues for more than Δt seconds, a voice alarm will be triggered.
[0044] To address the aforementioned technical problems, another technical solution adopted by this invention is: providing a system for detecting the safety of water levels in wastewater treatment plants based on AI visual algorithms, comprising:
[0045] The data reading and preprocessing module is used to read video frames for single-frame water level identification, perform real-time data cleaning and optimization based on the single-frame water level identification results, and suppress liquid surface impurities and steam interference through multi-frame fusion and adaptive preprocessing, while optimizing data flow to balance performance and real-time performance.
[0046] The wastewater tank area positioning module is used to generate wastewater tank area positioning using a mask and extract the effective region of interest (ROI) within the tank.
[0047] The liquid level recognition module uses HSV color filtering to identify water features, segment the liquid level, and calculate the water level height.
[0048] The abnormal state judgment module is used to judge the relationship between the current water level and the warning threshold, as well as the relationship between the current time and the interval between the last alarm and the anti-shake interval. If the composite judgment logic is satisfied at the same time, it enters the multimodal alarm unit; otherwise, the image annotation is normal.
[0049] The multimodal alarm module is used to provide multimodal alarms using visual and voice broadcasts, and controls the frequency of alerts through time-shaking control.
[0050] In a preferred embodiment of the present invention, the liquid level recognition module includes a water area screening unit and a water level height calculation unit;
[0051] The water body region screening unit is used to segment wastewater bodies using the characteristics of the HSV color space, generating a liquid surface mask, which is represented as:
[0052]
[0053] Among them, M water (x,y) represents the binary mask of the liquid surface, 255 represents the liquid surface area, and H(x,y), S(x,y), and V(x,y) are the hue, saturation, and lightness of the pixel, respectively.
[0054] The water level calculation unit is used to extract the set of all non-zero pixel coordinates C from the liquid surface mask. water ={(x,y)|M water (x,y)=255}, if C water If empty, predict the current value based on the three most recent valid water levels and mark it as "invalid data"; otherwise, calculate the minimum y-coordinate of the liquid surface area. min,pixel =min{y|(x,y)∈C water The water level height is calculated using the following formula:
[0055] H actual =(y base,pixel -y min,pixel )·k
[0056] Among them, H actual This is the actual water level height, in meters; y base,pixel The preset y-coordinate of the pool bottom is given by y. min,pixel It is the minimum y-coordinate of the liquid surface in the image, and k is the pixel-to-actual-size mapping coefficient.
[0057] In a preferred embodiment of the present invention, the multimodal alarm module includes a visual alarm unit and a voice alarm unit;
[0058] The visual alarm unit overlays Chinese annotations on the monitoring screen in real time to distinguish between normal and abnormal states.
[0059] The voice alarm unit uses an independent thread for broadcasting, and its triggering logic is as follows:
[0060]
[0061] Among them, T speak Voice trigger flag, 1 for trigger, 0 for no trigger, S last S is the previous state marker. abnormal The current state is marked, Δt is the interval between the current time and the last voice recording, τ is the anti-shake interval, which is fixed at several seconds, ≠ is the logical NOT operation, and ∨ is the logical OR operation; when the state changes from normal to abnormal (S abnormal ≠S last Or conversely, or if the same state continues for more than Δt seconds, a voice alarm will be triggered.
[0062] The beneficial effects of this invention are:
[0063] (1) This invention solves the problem of accurate water level identification in complex scenarios of sewage tanks. By limiting the monitoring area and optimizing the feature extraction logic, it achieves accurate identification of the real water level line, eliminates interference factors such as impurities and dirt, ensures the authenticity and reliability of water level data, and provides an accurate basis for subsequent process control (such as pump start-up and shutdown, water intake adjustment).
[0064] (2) This invention improves the stability of water level anomaly judgment. By designing a dual judgment mechanism of "water level height + duration", it accurately distinguishes between "short-term fluctuations caused by water inflow impact" and "abnormal state of continuous exceeding threshold", avoiding false alarms due to short-term water level fluctuations, reducing the interference of invalid alarms on operation and maintenance personnel, and improving the stability of anomaly judgment.
[0065] (3) In view of the characteristics of sewage treatment plant images being easily affected by dust, steam and dim light, the present invention optimizes the image preprocessing process (such as defogging and contrast enhancement) and combines dynamic sampling strategy to adapt to the performance of industrial control host, so that the method of the present invention can still maintain stable recognition (accuracy ≥ 90%) in harsh environments, while avoiding resource conflicts with other process control programs.
[0066] (4) This invention reduces operation and maintenance costs and improves safety redundancy. Through precise monitoring and intelligent alarm, it can promptly warn of abnormal water levels (such as triggering an alarm when the water level is 30cm away from the overflow threshold) to avoid sewage overflow (the cost of treating a single overflow can reach tens of thousands of yuan). It also reduces the reliance on traditional sensors (the annual maintenance cost of sensors is reduced by more than 60%). At the same time, it shortens the emergency response time through quantitative voice prompts (such as "current water level is 2.1 meters, 0.5 meters away from the overflow threshold"), ensuring the continuous and stable operation of the sewage treatment process. Attached Figure Description
[0067] Figure 1 This is a flowchart illustrating a preferred embodiment of the method for detecting water level safety in wastewater treatment plants based on AI visual algorithms according to the present invention.
[0068] Figure 2 This is a schematic diagram of the water level calculation logic;
[0069] Figure 3 This is a structural block diagram of the system for detecting water level safety in a wastewater treatment plant based on AI vision algorithms. Detailed Implementation
[0070] The preferred embodiments of the present invention will now be described in detail with reference to the accompanying drawings, so that the advantages and features of the present invention can be more easily understood by those skilled in the art, thereby providing a clearer and more explicit definition of the scope of protection of the present invention.
[0071] Please see Figure 1 The embodiments of the present invention include:
[0072] A method for detecting water level safety in wastewater treatment plants based on AI visual algorithms includes the following steps:
[0073] S1: Read video frames for single-frame water level identification, perform real-time data cleaning and optimization based on the single-frame water level identification results, and suppress liquid surface impurities and steam interference through multi-frame fusion and adaptive preprocessing, while optimizing data flow to balance performance and real-time performance; specifically including:
[0074] During real-time data cleaning, a 10-frame sliding window is used to weight and smooth the water level identification results. For the water level coordinates identified in each frame, the average value is calculated according to the principle of "higher weight for recent frames and lower weight for older frames" (e.g., the weight of the most recent frame is 0.2, the weight of the 10th frame is 0.05, and the total weight is 1). This reduces the single-frame jitter caused by liquid surface fluctuations (such as water inflow impact and sludge floating). The formula is as follows:
[0075] Among them, H smooth This is the smoothed water level height (output result), h i The water level recognition height (input) of the i-th frame, w i It is the weight of the i-th frame. Actual measurements show that this method can reduce water level fluctuations by 70% and effectively filter out transient interference (such as ±5cm errors caused by 1-2 seconds of sludge obstruction).
[0076] To address steam atomization and pool wall fouling in wastewater treatment plants, an adaptive filtering and defogging enhancement algorithm is employed: By calculating the local grayscale variance of the image (a larger variance indicates more severe impurities or fogging), the bilateral filter kernel parameters (σ values varying between 0.3 and 0.8) are dynamically adjusted—high variance regions (such as areas with dense steam) are enhanced and smoothed with larger σ values, while low variance regions (such as clear liquid surfaces) are preserved by smaller σ values. Simultaneously, a dark channel prior algorithm is combined to remove steam atomization; the formula is as follows:
[0077]
[0078] Where J(x) is the dehazed image (output), I(x) is the original hazy image (input), A is the atmospheric light value (reflecting fog concentration), t(x) is the transmittance (used to estimate fog concentration), and t0 = 0.1 (to avoid over-dehazing). After processing, the grayscale contrast between the liquid surface and the pool wall increased from <20 to ≥40, and the edge sharpness was improved by 50%.
[0079] Data storage and frame rate control employ a "dynamic sampling + frame skipping calculation" strategy: water level fluctuations are judged based on multi-frame smoothing results, and the analysis interval and storage frequency are dynamically adjusted. The calculation formula is as follows:
[0080] in:
[0081] Where, N skip This represents the number of frames to skip (output), f is the original video frame rate (e.g., 30 FPS), and T is the basic analysis interval. For floor operations. When the water level is stable, 1 frame of data is stored every 10 seconds. When there are large fluctuations, it is automatically increased to 1 frame every 2 seconds. The data of the most recent hour is stored in the hot cache, and historical data is stored in the cold storage according to "sewage tank number-date". Compared with fixed frequency storage, the storage space usage is reduced by 40%, and the CPU utilization of the industrial host is reduced from 80% to below 30%.
[0082] S2: Based on an improved water level recognition algorithm, this system addresses recognition errors caused by "blurred liquid surface and impurity interference" in sewage tanks through region focusing and composite judgment mechanisms, while also enhancing the stability of abnormal state judgment. It utilizes a mask to generate sewage tank region localization and extracts the effective region of interest (ROI) within the tank; specifically:
[0083] Wastewater tanks are often surrounded by various equipment such as pipes, ladders, and valves. These background elements can interfere with liquid level recognition. Traditional full-image analysis often misjudges shadows around the tank or reflections from equipment as the liquid level, leading to errors in water level calculation. To solve this problem, the method of this invention uses a "polygon region limitation + mask extraction" approach to lock in the effective monitoring range. Specifically, the coordinates of polygon vertices are first preset based on the actual outline of the wastewater tank (such as the upper left corner, upper right corner, etc., determined through on-site calibration). Then, a binary mask is generated based on these coordinates. Its core logic can be expressed as follows:
[0084]
[0085] Where M(x,y) is the binarized mask image (output), (x,y) are the pixel coordinates of the image, and P is the preset polygonal region of the sewage pool - pixels inside the pool are marked as 255 (valid region), and the background outside the pool is marked as 0 (invalid region).
[0086] After that, through Extract the effective region of interest (ROI) within the pool, where I roi The output image represents the effective area within the pool, while I represents the original image (input). This method retains only the pixels corresponding to 255 in the mask, filtering out all background outside the pool. In practical applications at wastewater treatment plants, this method can eliminate over 60% of invalid background interference, improving the computational efficiency of subsequent liquid level recognition by 40%. It fundamentally avoids interference from background elements in water level analysis, laying the foundation for accurate identification.
[0087] S3: Use HSV color filtering to identify water features, segment the liquid surface, and calculate the water level height;
[0088] Wastewater tanks often have floating sludge flocs, foam, and other impurities on their surface, and the tank walls are prone to dirt accumulation, resulting in blurred surface outlines. Traditional edge detection methods easily misjudge impurities as part of the surface, causing inaccurate water level calculations. To address this issue, the method of this invention achieves precise surface positioning and water level calculation through "HSV color segmentation + core feature extraction".
[0089] First, the characteristics of the sewage (light grayish-blue) in the HSV color space are used to segment the water and generate a liquid surface mask. The logic is as follows:
[0090]
[0091] Among them, M water (x,y) represents the binarized mask (output) of the liquid surface, 255 represents the liquid surface area, H, S, and V are the HSV color (hue, saturation, brightness) components of the pixel, and [100,140] is selected as the hue threshold (to match the blue tone of the sewage). This threshold can filter more than 60% of the brown sludge and more than 80% of the gray-white foam.
[0092] Next, extract the set of all non-zero pixel coordinates C from the liquid surface mask. water ={(x,y)|M water (x,y)=255}, if C water If the value is empty (e.g., the liquid surface is completely covered by sludge), then the backup strategy is activated (based on the current value predicted from the three most recent valid water levels, and marked as "invalid data"); otherwise, the minimum y-coordinate of the liquid surface area is calculated (corresponding to the highest point of the liquid surface, which is least affected by floating sludge). min,pixel =min{y|(x,y)∈C water The actual water level is calculated by combining the reference coordinates of the pool bottom, using the following formula:
[0093] H actual =(y base,pixel -y min,pixel )·k;
[0094] Among them, H actual This is the actual water level height (output value, unit: meters), y base,pixel It is the y-coordinate of the reference pixel at the bottom of the pool (pre-calibrated), y min,pixel is the minimum y-coordinate (pixel coordinate) of the liquid surface in the image, and k is the pixel-to-actual-size mapping coefficient (pre-calibrated). This formula eliminates the influence of pool tilt, calculates only the vertical height, and controls the detection error within ±2 cm.
[0095] Combination Figure 2The algorithm takes a pre-processed image (filtered with a ROI mask to eliminate interference from outside the pool) and the reference coordinates of the pool bottom as input. First, it extracts the water surface coordinates (using color space segmentation and non-zero pixel filtering for initial positioning). Then, it filters impurities (preserving the main body of the water surface and removing sludge / foam, etc.). Next, it extracts the minimum y-value of the liquid surface (locking the highest point of the water surface to resist the influence of local impurities). The core calculation is completed by the water level formula (water level height = reference coordinates of the pool bottom - minimum y-value of the liquid surface). Afterward, it compares the thresholds and outputs the normal or abnormal status (associated with visual and voice prompts) and displays the results. The impurity filtering process effectively removes interference and ensures the accuracy of water level calculation and status judgment.
[0096] S4: Determine the relationship between the current water level and the warning threshold, as well as the relationship between the current time and the interval between the last alarm and the anti-shake interval. If the composite judgment logic is satisfied at the same time, proceed to step S5; otherwise, the image annotation is normal.
[0097] The abnormal state judgment adopts a composite judgment logic of "dual threshold + duration verification": a first-level warning threshold (water level within 10cm of the warning value) and a second-level alarm threshold (water level exceeding the warning value) are set, and a duration verification is added to the alarm threshold. The formula is as follows:
[0098] Among them, S abnormal It is an abnormal status marker (1 indicates abnormal, 0 indicates normal), H actual This is the current water level (real-time monitoring value), H th It is the warning threshold (pre-set based on a safety assessment), T duration It represents the duration exceeding the threshold (accumulated in real time via timestamps), and "∧" indicates an AND relationship. H actual >H th ∧T duration ≥30s means that the current water level exceeds the warning value and the duration of exceeding the threshold is ≥30 seconds. Only when both conditions are met is it determined to be an "abnormal state" (S). abnormal =1), if the threshold is exceeded only briefly (such as a 2-second exceedance caused by influent impact), no alarm will be triggered. In wastewater treatment plant applications, this logic reduces the false alarm rate from 20% of the traditional single threshold method to 3% (only 1-2 false alarms per month), ensuring that real anomalies can be detected in a timely manner while avoiding interference from instantaneous fluctuations to operation and maintenance.
[0099] S5: Utilizes visual and voice broadcasts for multimodal alarms and controls the frequency of alerts through time-based anti-shake.
[0100] The monitoring interface supports overlay display of the layout map of the wastewater tanks in the plant area, and real-time annotation of water level values, status (normal / warning / abnormal) and duration: when the water level is within 10cm of the warning value (warning status), a yellow prompt box is displayed; when it exceeds the warning value (abnormal status), a red flashing box is displayed, and a water level trend curve for the past 1 hour (based on fitting) is automatically drawn; clicking on a single tank allows you to view historical data (1 record every 10 seconds) and keyframe images (time of occurrence, duration, and mitigation of the abnormality), which assists in fault analysis.
[0101] The alarm method employs a dual anti-shake mechanism of "content + status": it records the content (e.g., "Pool A abnormality") and time of the last alarm, and the voice trigger logic is as follows:
[0102]
[0103] Among them, T speak It is a voice trigger flag (1 = triggered, 0 = not triggered), S last It is the previous state flag, S abnormal This is the current status marker, Δt is the interval between the current time and the last voice message (in seconds), and "∨" represents "logical OR," meaning the entire expression is true if at least one of the two conditions is true. If the alarm content is the same and the interval is <120 seconds, only the status is updated without triggering a voice message; a voice prompt is triggered only when the content changes (e.g., from warning to abnormal) or the interval is ≥120 seconds (Δt≥120) ("Warning! Water level abnormal" is broadcast when there is an abnormality, and "Water level normal" is broadcast when there is a normality), and the voice message includes quantitative information: "The current water level of sewage tank A is 2.7 meters, exceeding the warning value by 0.2 meters, and has been ongoing for 1 minute." Invalid voice prompts are reduced by 80% (avoiding repeated broadcasts of the same status), and at the same time, through visual + voice prompts, it is ensured that maintenance personnel can quickly locate abnormal tanks.
[0104] In addition, the voice system adopts a multi-threaded non-blocking approach (creating independent threads via threading.Thread), avoiding the screen lag caused by traditional single-threaded broadcasting and ensuring real-time monitoring. When an abnormal state persists for 30 seconds without relief, it automatically sends control signals (such as "reduce the influent pump frequency to 80%" or "open the emergency drain valve") to the wastewater treatment plant PLC program, linking the influent adjustment methods. At the same time, it triggers the plant's audible and visual alarms (synchronously activated in the warehouse area and the central control room, with the alarm light flashing frequency increasing with the duration), automatically records the abnormal handling log (including water level changes, control actions, and operators), and supports exporting operation and maintenance reports (statistically counting the number of abnormalities and processing time by day / week / month).
[0105] The method described in this invention brings the following beneficial effects:
[0106] (1) Improved accuracy of water level recognition: By using HSV color segmentation, extraction of core features of the liquid surface (minimum y-value locking), and morphological noise filtering, the accuracy of water level recognition in complex scenarios is significantly improved. For common scenarios in wastewater treatment plants such as floating sludge on the liquid surface, steam atomization in the pool, and fouling on the pool walls, the method controls the error of water level height recognition to ±2cm (pixel-level error ±3), which is more than 60% higher than the traditional edge detection method (error ±8cm); the accuracy of judging "normal / abnormal" status reaches 96%, effectively reducing false alarms (such as stable recognition when sludge covers 30% of the liquid surface) and missed alarms (such as slow rise not being detected in time) caused by impurities, providing a reliable basis for the safe monitoring of water levels in wastewater treatment plants.
[0107] (2) Real-time response and enhanced stability: By adopting dynamic frame rate adjustment (10 seconds / frame when stable, 2 seconds / frame when fluctuating) and a non-blocking voice broadcast mechanism, the system can capture water level changes and status switching in real time. When the water level rises suddenly due to water inrush (e.g., a rise of 10cm within 5 minutes) or when steam suddenly increases (fogging interference), the system can complete status updates and warning triggers within 2 seconds, avoiding regulatory lag caused by response delays. By filtering instantaneous fluctuations through time-based anti-jitter logic (5-second intervals), the stability of anomaly judgment is improved by 80%, ensuring that warnings are only for real risks (e.g., water levels continuously exceeding the warning level).
[0108] (3) Optimization of operation and maintenance costs and improvement of security redundancy: By using frame skipping processing (analyzing 1 frame every 10 seconds) and resource scheduling strategies, the method reduces hardware resource consumption by 70% (CPU utilization rate drops from 80% to below 30%) while ensuring monitoring effectiveness, adapting to the performance limitations of industrial hosts in sewage treatment plants; the voice anti-shake mechanism (only broadcasting once within 5 seconds in the same state) reduces invalid voice prompts by 80%, reducing auditory fatigue of monitoring personnel; at the same time, it supports automatic recording of abnormal states and historical backtracking, reducing the frequency of manual inspections (reducing on-site inspections by 2 times per week), and reducing the overall operation and maintenance cost by 50%.
[0109] See Figure 3 This invention also provides a system for water level safety detection in wastewater treatment plants based on AI vision algorithms, including a data reading and preprocessing module, a wastewater pool area positioning module, a liquid level recognition module, an abnormal state judgment module, and a multimodal alarm module.
[0110] The data reading and preprocessing module is used to read video frames for single-frame water level identification, perform real-time data cleaning and optimization based on the single-frame water level identification results, and suppress liquid surface impurities and steam interference through multi-frame fusion and adaptive preprocessing, while optimizing data flow to balance performance and real-time performance.
[0111] The sewage tank area positioning module is used to generate sewage tank area positioning using a mask and extract the effective region ROI within the tank.
[0112] The liquid level recognition module uses HSV color filtering to identify water features, segment the liquid level, and calculate the water level height.
[0113] The abnormal state judgment module is used to judge the relationship between the current water level and the warning threshold, as well as the relationship between the current time and the interval between the last alarm and the anti-shake interval. If the composite judgment logic is satisfied at the same time, it enters the multimodal alarm unit; otherwise, the image annotation is normal.
[0114] The multimodal alarm module is used to provide multimodal alarms using visual and voice broadcasts, and to control the frequency of alerts through time-based anti-jitter control.
[0115] The liquid level recognition module includes a water area screening unit and a water level height calculation unit.
[0116] The water body region screening unit is used to segment wastewater bodies using the characteristics of the HSV color space, generating a liquid surface mask, which is represented as:
[0117]
[0118] Among them, M water (x,y) represents the binary mask of the liquid surface, 255 represents the liquid surface area, and H(x,y), S(x,y), and V(x,y) are the hue, saturation, and lightness of the pixel, respectively.
[0119] The water level calculation unit is used to extract the set of all non-zero pixel coordinates C from the liquid surface mask. water ={(x,y)|M water (x,y)=255}, if C water If empty, predict the current value based on the three most recent valid water levels and mark it as "invalid data"; otherwise, calculate the minimum y-coordinate of the liquid surface area. min,pixel =min{y|(x,y)∈C water The water level height is calculated using the following formula:
[0120] H actual =(y base,pixel -y min,pixel )·k
[0121] Among them, H actual This is the actual water level height, in meters; y base,pixel The preset y-coordinate of the pool bottom is given by y. min,pixel It is the minimum y-coordinate of the liquid surface in the image, and k is the pixel-to-actual-size mapping coefficient.
[0122] Furthermore, the multimodal alarm module includes a visual alarm unit and a voice alarm unit;
[0123] The visual alarm unit overlays Chinese annotations on the monitoring screen in real time to distinguish between normal and abnormal states.
[0124] The voice alarm unit uses an independent thread for broadcasting, and its triggering logic is as follows:
[0125]
[0126] Among them, T speak Voice trigger flag, 1 for trigger, 0 for no trigger, S last S is the previous state marker. abnormal The current state is marked, Δt is the interval between the current time and the last voice recording, τ is the anti-shake interval, which is fixed at several seconds, ≠ is the logical NOT operation, and ∨ is the logical OR operation; when the state changes from normal to abnormal (S abnormal ≠S last Or conversely, or if the same state continues for more than Δt seconds, a voice alarm will be triggered.
[0127] The above description is merely an embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent structural or procedural transformations made based on the content of the present invention's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. A method for detecting water level safety in wastewater treatment plants based on AI visual algorithms, characterized in that, Includes the following steps: S1: Read video frames for single-frame water level identification, perform real-time data cleaning and optimization based on the single-frame water level identification results, and suppress liquid surface impurities and steam interference through multi-frame fusion and adaptive preprocessing, while optimizing data flow to balance performance and real-time performance. S2: Use a mask to generate the location of the sewage tank area and extract the effective ROI within the tank; S3: Use HSV color filtering to identify water features, segment the liquid surface, and calculate the water level height; S4: Determine the relationship between the current water level and the warning threshold, as well as the relationship between the current time and the interval between the last alarm and the anti-shake interval. If the composite judgment logic is satisfied at the same time, proceed to step S5; otherwise, the image annotation is normal. S5: Utilizes visual and voice broadcasts for multimodal alarms and controls the frequency of alerts through time-based anti-shake.
2. The method for detecting water level safety in wastewater treatment plants based on AI visual algorithms according to claim 1, characterized in that, In step S1, real-time data cleaning uses a multi-frame sliding window to weighted smooth the single-frame water level identification results. Adaptive filtering and defogging enhancement algorithms are employed to suppress surface impurities and steam interference. The bilateral filter kernel parameter σ is dynamically adjusted by calculating the local grayscale variance of the image, and a dark channel prior algorithm is combined to remove steam atomization. The formula is as follows: Where J(x) is the image after defogging, I(x) is the original fogged image, A is the atmospheric light value, reflecting the fog concentration, t(x) is the transmittance, used to estimate the fog concentration, and t0 = 0.
1.
3. The method for detecting water level safety in wastewater treatment plants based on AI visual algorithms according to claim 1, characterized in that, In step S1, optimizing data flow includes controlling the actual analysis frequency through frame skipping calculation, and dynamically adjusting the analysis interval according to the water level fluctuation amplitude. The formula for calculating the actual analysis frequency by using frame skipping is as follows: in: Where, N skip This indicates the number of frames to skip, controlling the actual analysis interval. f is the original video frame rate, and T is the base analysis interval, adapting to the characteristics of slow water level changes in different wastewater treatment plants. For floor operations, H smooth It is the smoothed water level height; The method for dynamically adjusting the analysis interval based on the amplitude of water level fluctuations is as follows: The fluctuation amplitude is calculated using three consecutive frames of water level data. If |h t -h t-3 If the water level fluctuation exceeds 2cm, the analysis interval will be automatically shortened to T' seconds; when the water level stabilizes, i.e., the fluctuation is ≤2cm, the T-second interval will be automatically restored.
4. The method for detecting water level safety in wastewater treatment plants based on AI visual algorithms according to claim 1, characterized in that, The specific steps of step S2 include: S201: Preset the vertex coordinates of the polygonal region based on the actual outline of the sewage tank; S202: Generate a binary mask based on the above coordinates, which is represented as: Where M(x,y) is a binary mask image, (x,y) is the pixel coordinate of the image, and P is a preset polygonal region of the sewage pool, that is, pixels inside the pool are marked as valid regions, while the background outside the pool is marked as invalid regions. S203: Pass Extract the effective region of interest (ROI) within the pool, where I roi (x, y) represents the effective region image within the pool, and I(x, y) represents the original image.
5. The method for detecting water level safety in wastewater treatment plants based on AI visual algorithms according to claim 1, characterized in that, The specific steps of step S3 include: S301: Utilizing the characteristics of wastewater in the HSV color space, a liquid surface mask is generated, represented as follows: Among them, M water (x, y) represents the liquid surface binarization mask, 255 represents the liquid surface area, and H(x, y), S(x, y), and V(x, y) are the hue, saturation, and lightness of the pixel, respectively. S302: Extract the set of all non-zero pixel coordinates C from the liquid surface mask. water ={(x, y)|M water (x, y) = 255}, if C water If empty, predict the current value based on the three most recent valid water levels and mark it as "invalid data"; otherwise, calculate the minimum y-coordinate of the liquid surface area. min,pixel =min{y|(x,y)∈C water The water level height is calculated using the following formula: H actual =(y base,pixel -y min,pixe1 )·k Among them, H actual This is the actual water level height, in meters; y base,pixel The preset y-coordinate of the pool bottom is given by y. min,pixel It is the minimum y-coordinate of the liquid surface in the image, and k is the pixel-to-actual-size mapping coefficient.
6. The method for detecting water level safety in wastewater treatment plants based on AI visual algorithms according to claim 1, characterized in that, In step S4, if the current water level exceeds the warning threshold and the interval between the current time and the last alarm exceeds the anti-shake interval, it is determined that the sewage treatment is abnormal and enters the multi-modal alarm mode; otherwise, no alarm is triggered.
7. The method for detecting water level safety in wastewater treatment plants based on AI visual algorithms according to claim 1, characterized in that, In step S5, visually, Chinese annotations are overlaid on the monitoring screen in real time to distinguish between normal and abnormal states; audio-wise, a separate thread is used for broadcasting, with the triggering logic being... Among them, T speak Voice trigger flag, 1 for trigger, 0 for no trigger, S last S is the previous state marker. abnormal The current state is marked, Δt is the interval between the current time and the last voice recording, τ is the anti-shake interval, which is fixed at several seconds, ≠ is the logical NOT operation, and ∨ is the logical OR operation; when the state changes from normal to abnormal (S abnormal ≠S last Or conversely, or if the same state continues for more than Δt seconds, a voice alarm will be triggered.
8. A system for detecting water level safety in a wastewater treatment plant based on AI visual algorithms, characterized in that, include: The data reading and preprocessing module is used to read video frames for single-frame water level identification, perform real-time data cleaning and optimization based on the single-frame water level identification results, and suppress liquid surface impurities and steam interference through multi-frame fusion and adaptive preprocessing, while optimizing data flow to balance performance and real-time performance. The wastewater tank area positioning module is used to generate wastewater tank area positioning using a mask and extract the effective region of interest (ROI) within the tank. The liquid level recognition module uses HSV color filtering to identify water features, segment the liquid level, and calculate the water level height. The abnormal state judgment module is used to judge the relationship between the current water level and the warning threshold, as well as the relationship between the current time and the interval between the last alarm and the anti-shake interval. If the composite judgment logic is satisfied at the same time, it enters the multimodal alarm unit; otherwise, the image annotation is normal. The multimodal alarm module is used to provide multimodal alarms using visual and voice broadcasts, and controls the frequency of alerts through time-shaking control.
9. The system for detecting water level safety in wastewater treatment plants based on AI vision algorithms according to claim 8, characterized in that, The liquid level recognition module includes a water area screening unit and a water level height calculation unit; The water body region screening unit is used to segment wastewater bodies using the characteristics of the HSV color space, generating a liquid surface mask, which is represented as: Among them, M water (x, y) represents the liquid surface binarization mask, 255 represents the liquid surface area, and H(x, y), S(x, y), and V(x, y) are the hue, saturation, and lightness of the pixel, respectively. The water level calculation unit is used to extract the set of all non-zero pixel coordinates C from the liquid surface mask. water ={(x, y)|M water (x, y) = 255}, if C water If empty, predict the current value based on the three most recent valid water levels and mark it as "invalid data"; otherwise, calculate the minimum y-coordinate of the liquid surface area. min,pixel =min{y|(x,y)∈C water The water level height is calculated using the following formula: H actual =(y base,pixel -y min,pixe1 )·k Among them, H actual This is the actual water level height, in meters; y base,pixel The preset y-coordinate of the pool bottom is given by y. min,pixel It is the minimum y-coordinate of the liquid surface in the image, and k is the pixel-to-actual-size mapping coefficient.
10. The system for detecting water level safety in wastewater treatment plants based on AI visual algorithms according to claim 8, characterized in that, The multimodal alarm module includes a visual alarm unit and a voice alarm unit; The visual alarm unit overlays Chinese annotations on the monitoring screen in real time to distinguish between normal and abnormal states. The voice alarm unit uses an independent thread for broadcasting, and its triggering logic is as follows: Among them, T speak Voice trigger flag, 1 for trigger, 0 for no trigger, S last S is the previous state marker. abnormal The current state is marked, Δt is the interval between the current time and the last voice recording, τ is the anti-shake interval, which is fixed at several seconds, ≠ is the logical NOT operation, and ∨ is the logical OR operation; when the state changes from normal to abnormal (S abnormal ≠S last Or conversely, or if the same state continues for more than Δt seconds, a voice alarm will be triggered.
Citation Information
Cited By
An AI vision-based water treatment equipment intelligent monitoring system and method
CN122457745A