Liquid level detection method and system based on image processing

Through the liquid level detection method based on image processing, red channel extraction and multi-scale morphological processing are used to solve the accuracy and adaptability problems of liquid level detection in complex industrial environments, and high-precision liquid level monitoring is achieved.

CN120673391APending Publication Date: 2025-09-19HUAIYIN INSTITUTE OF TECHNOLOGY
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510777520.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-11
Publication Date
2025-09-19

AI Technical Summary

Technical Problem

Existing liquid level detection technology has problems such as reduced measurement accuracy, high signal attenuation rate, and poor adaptability in complex industrial environments. It is particularly difficult to achieve high-precision detection under strong light and multi-angle lighting conditions.

Method used

A liquid level detection method based on image processing is adopted. By acquiring the original liquid level image data, red channel extraction, double threshold segmentation and multi-scale morphological processing are performed. The OTSU method and morphological operations are combined to improve the detection robustness.

Benefits of technology

The robustness and accuracy of detection are improved under complex lighting conditions, accurate monitoring of liquid level height is achieved, and stable operation is adapted to various environments and conditions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120673391A_ABST
    Figure CN120673391A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of liquid level detection, and discloses a liquid level detection method and system based on image processing, and the method comprises the steps: obtaining to-be-processed original liquid level image data; preprocessing the data of the original liquid level image, wherein the preprocessing comprises the steps of extracting a red channel from the original liquid level image, carrying out binarization processing on the image based on double thresholds, carrying out expansion on a binary image by using a square structure element, carrying out opening operation and closing operation on the expanded image, carrying out corrosion operation on the image subjected to the closing operation, and carrying out iteration for three times; and carrying out feature extraction on the preprocessed image, calculating a minimum bounding rectangular frame, drawing a rectangular frame in the original liquid level image, and judging the liquid level height according to the height of the rectangular frame. Compared with the prior art, dual threshold segmentation and multi-scale morphological processing are innovatively combined, and the detection robustness under the complex illumination condition is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of liquid level detection, and in particular to a liquid level detection method and system based on image processing. Background Art

[0002] Liquid level measurement is a key component of modern industrial automation control. Its accuracy has a significant impact on the stability of the production process and is directly related to several key areas such as product quality control, energy consumption optimization, and industrial safety protection. Currently, there are three main detection solutions commonly used in industrial sites: mechanical measuring devices, electrical characteristic sensors, and acoustic ranging equipment. Although traditional detection methods (such as mechanical, capacitive, and ultrasonic technologies) have a high degree of technical maturity, they still have significant limitations in complex industrial environments: mechanical devices are susceptible to medium corrosion, resulting in reduced measurement accuracy; capacitive sensors are sensitive to fluctuations in dielectric constant and require frequent calibration; and ultrasonic detection can have a signal attenuation rate of up to 30-40dB / m under steam or foamy liquid conditions, seriously affecting measurement reliability.

[0003] In recent years, with breakthroughs in computer vision algorithms and image processing hardware, non-contact visual liquid level detection technology has become an increasing research focus. This technology uses industrial-grade CCD cameras or CMOS image sensors to capture images of liquid tanks in real time and utilizes advanced digital image processing algorithms to accurately identify liquid level interfaces. Compared with traditional detection methods, visual inspection systems offer three major advantages: First, the completely non-contact measurement method completely avoids sensor contamination and wear. Second, high-frame-rate video and multi-frame fusion technology enable real-time tracking of dynamic liquid levels. Third, the system can be seamlessly integrated into existing Industrial Internet of Things platforms, enabling remote monitoring and data analysis.

[0004] Digital image processing, as the fundamental part of the image processing liquid level detection system, mainly includes processes such as image preprocessing, feature extraction, and image analysis. The use of preprocessing techniques such as histogram equalization and median filtering can effectively improve image contrast, suppress noise interference, and achieve effective information extraction and decision support in complex backgrounds. The application of machine vision technology in liquid level detection mainly manifests itself in image acquisition, image processing, and liquid level recognition. As a core branch in the field of artificial intelligence, deep learning has demonstrated excellent performance in image recognition and feature extraction tasks. It achieves end-to-end high-precision feature learning through architectures such as convolutional neural networks. However, it conventionally relies on expert-labeled infrared image data, and the training data set lacks typical interference factors, which may affect the model's generalization ability.

[0005] Existing technologies can still rely on model structure optimization and data for liquid level detection. However, their adaptability to complex conditions such as strong reflections and multi-angle lighting remains to be verified. For example, in strong light, the liquid level edge of a transparent bottle may be blurred due to specular reflection, affecting the model's detection accuracy. Future research should focus on developing adaptive algorithms and heterogeneous hardware platforms to meet the requirements of robust detection in multiple scenarios, improve detection speed and accuracy, explore more effective data fusion strategies, and develop universal solutions applicable to a wider range of application scenarios. Summary of the Invention

[0006] Purpose of the invention: To address the problems existing in the prior art, the present invention provides a liquid level detection method and system based on image processing, which analyzes the optical characteristics of transparent container liquid level imaging, performs edge enhancement based on the red channel, and innovatively combines dual threshold segmentation and multi-scale morphological processing to improve the detection robustness under complex lighting conditions.

[0007] Technical solution: The present invention provides a liquid level detection method based on image processing, comprising the following steps:

[0008] Step 1: Obtain the original liquid level image data to be processed;

[0009] Step 2: Preprocessing the original liquid level image data in step 1, the preprocessing comprising: extracting the red channel from the original liquid level image, binarizing the image based on a double threshold, dilating the binary image using a square structure element, performing opening and closing operations on the dilated image, and performing an erosion operation on the closed image and iterating three times;

[0010] Step 3: Extract features from the preprocessed image, calculate the minimum bounding rectangle, draw a rectangle in the original liquid level image, and determine the liquid level height based on the height of the rectangle.

[0011] Furthermore, in step 1, when acquiring the original liquid level image, a high-definition camera is connected via a USB 3.0 interface, and the hardware driver is loaded according to MATLAB's Image Acquisition Toolbox. The device is first detected through imaqhwinfo, and then the acquisition parameters are set using videoinput.

[0012] Furthermore, the image is binarized using a double threshold in step 2 as follows:

[0013] The red channel is binarized using pixel values, and then the threshold is calculated using the OTSU method to further binarize the image.

[0014] ① Primary background screening: Based on grayscale histogram statistical analysis, sample size N ≥ 1000, set the global threshold Tg =100, when the pixel intensity satisfies I(x,y)>T g When , the pixel is classified as the background area and grayscale value remapping is performed. Under standard lighting conditions, the 100-120 grayscale range effectively separates more than 90% of the background interference area;

[0015] ② Liquid area identification: For pixels that are not marked as background, that is, I(x, y) < 100 and I(x, y) ≠ 1, an asymmetric double threshold strategy is often used to process them. The marked background (gray value = 1) is excluded through mask operation, and then the intensity threshold is determined for the remaining pixels. The intensity threshold T is set. l =80, will satisfy I(x,y) <T l The pixel is set to 255, which is pure white;

[0016] ③Add morphological closing operation to eliminate the pores caused by thresholding. Its mathematical expression is:

[0017]

[0018] Furthermore, the OTSU method is used to calculate the threshold as follows:

[0019] Assume that the image gray level is L, L = 256, and rely on the inter-class variance Reach the maximum value to determine the optimal threshold t * :

[0020]

[0021] The formula for calculating the between-class variance is:

[0022]

[0023] Among them, the proportion of foreground pixels is represented by ω0(t), the proportion of background pixels is ω1(t), and the average grayscale of the two categories are μ0(t) and μ1(t) respectively;

[0024] In converting the grayscale image to a binary image, an optimized recursive algorithm is used. The specific steps are as follows:

[0025] 1) Calculate the normalized histogram

[0026] 2) Initialize the cumulative probability ω(0) and the cumulative mean μ(0);

[0027] 3) In the process of traversing the gray level, the update method of ω(k+1) is: ω(k+1)=ω(k)+p(k+1), and μ(k+1) uses To update;

[0028] 4) Recording The maximum k value.

[0029] Furthermore, in step 2, the binary image is expanded using a 9×9 square structure element, specifically:

[0030] For a binary image I and a structuring element B, the dilation operation is defined as:

[0031]

[0032] Where E represents two-dimensional Euclidean space, B^ is the reflection of the structural element B, and (B^) is the set formed after B^ is translated by z;

[0033] The image is expanded using a fast algorithm:

[0034] 1) Structural element decomposition: The 9×9 square is decomposed into a sequence of structural elements consisting of 3×3 horizontal line segments and 3×3 vertical line segments;

[0035] 2) Separate convolution: perform dilation operations in the row and column directions in sequence;

[0036] 3) Result merging: combine intermediate results through logical OR operation.

[0037] Furthermore, in step 2, the expanded image is opened and closed, specifically:

[0038] The opening operation eliminates isolated noise points or foreground protrusions smaller than the structure element B by first corroding and then dilating, while keeping the topological structure of the target body unchanged;

[0039] The closing operation fills the internal pores of the target with a diameter less than ||B|| / 2 by first dilating and then corroding, and bridges the adjacent areas with a spacing <||B||, while retaining the groove features with a depth ≥||B||;

[0040] A cascade strategy of opening and closing operations is adopted to achieve dual optimization through 5×5 circular structural elements: the opening operation eliminates isolated noise points with a size of ≤3px, and the closing operation bridges the edge breaks of the liquid surface. At the same time, the Hausdorff distance change rate of the main structure of the bottle is controlled within 0.5%.

[0041] Furthermore, in step 2, the image after the closing operation is eroded and iterated three times, specifically:

[0042]

[0043] In the iterative strategy design of morphological erosion, a 9×9 square structure element is used to perform three iterative erosions. The mechanism is to eliminate single-pixel edges and isolated noise points in each iteration.

[0044] Furthermore, the feature extraction in step 3 is specifically as follows:

[0045] The Canny method is used to detect the edges of the preprocessed image, and the minimum circumscribed rectangular frame is calculated based on the edge points. On this basis, a rectangular frame is drawn in the original liquid level image, and the liquid level is determined according to the height of the rectangular frame.

[0046] Furthermore, the liquid level is determined according to the height of the rectangular frame as follows:

[0047] Through experimental calibration, an accurate height-volume correspondence table is constructed, and the final liquid level height is determined according to the correspondence table;

[0048] Alternatively, a discretization classification strategy can be used to divide the continuous height value into several intervals. Each interval corresponds to a specific liquid level state. The liquid level height is determined by finding the minimum circumscribed rectangle of the edge points. The liquid level percentage calculation formula is:

[0049]

[0050] The present invention also discloses a liquid level detection system based on image processing, comprising:

[0051] An image acquisition module is used to obtain the original liquid level image data to be processed;

[0052] An image preprocessing module is used to preprocess the original liquid level image data. The preprocessing includes: extracting the red channel from the original liquid level image, binarizing the image based on a double threshold, dilating the binary image using a square structure element, opening and closing the dilated image, and eroding the closed image and iterating three times.

[0053] The feature extraction module is used to extract features from the preprocessed image, calculate the minimum circumscribed rectangular frame, and draw a rectangular frame in the original liquid level image;

[0054] The liquid level height calculation module is used to calculate the liquid level height based on the height of the rectangular frame.

[0055] Beneficial effects:

[0056] This paper analyzes the optical properties of transparent container liquid level imaging. Addressing the lack of contrast in traditional methods, an adaptive background removal algorithm is designed based on the red channel and innovatively combines dual threshold segmentation with multi-scale morphological processing. This improves detection robustness under complex lighting conditions. This preprocessing step provides a more accurate and reliable image information foundation for subsequent liquid level feature extraction. The system can more precisely analyze liquid level height and any potential changing trends, enabling real-time and efficient monitoring of liquid levels. This ensures stable operation of the liquid level detection system in a variety of environments and conditions, while also outputting highly accurate liquid level data. BRIEF DESCRIPTION OF THE DRAWINGS

[0057] Figure 1 It is the overall flow chart of the present invention;

[0058] Figure 2 This is a flow chart of the image acquisition module of the present invention;

[0059] Figure 3 This is a flow chart of the image preprocessing module of the present invention;

[0060] Figure 4 This is a flow chart of the feature extraction module of the present invention;

[0061] Figure 5 This is the test result of bottled water exceeding the threshold value according to an embodiment of the present invention;

[0062] Figure 6 This is the test result of the bottled water in the embodiment of the present invention not exceeding the threshold value;

[0063] Figure 7 This is the test result of the canned concentrated nitric acid exceeding the threshold value in the embodiment of the present invention;

[0064] Figure 8 This is the test result of the canned concentrated nitric acid in the embodiment of the present invention, which does not exceed the threshold value. DETAILED DESCRIPTION

[0065] The present invention will be further described below in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solutions of the present invention and are not intended to limit the scope of protection of the present invention.

[0066] The present invention discloses a liquid level detection system based on image processing, which is designed using a multi-module collaborative architecture and consists of four core functional modules. The system block diagram is as follows: Figure 1 As shown, including:

[0067] The image acquisition module is used to obtain the original liquid level image data to be processed. The image acquisition module uses a USB 3.0 interface to achieve real-time image capture of 1920×1080. In the liquid level detection system based on image processing, the image acquisition module serves as a front-end sensing unit to achieve full-frame liquid level dynamic data capture. The system is connected to a high-definition camera through a USB 3.0 interface and loads the hardware driver based on MATLAB's ImageAcquisition Toolbox. The specific process is to first detect the device through imaqhwinfo and then use videoinput to set the acquisition parameters. The liquid level detection system can still operate stably under extreme working conditions and output relatively accurate liquid level data. This achievement provides a high-reliability technical solution for industrial automation and environmental monitoring. As a key component of the liquid level detection system based on image processing, the image acquisition module is also a prerequisite for achieving high-precision liquid level monitoring functions. The image acquisition flow chart is as follows Figure 2 shown.

[0068] The image preprocessing module is used to preprocess the original liquid level image data. The preprocessing includes: extracting the red channel from the original liquid level image, binarizing the image based on a double threshold, dilating the binary image using a square structure element, opening and closing the dilated image, and corroding the closed image and iterating three times.

[0069] The image preprocessing module mainly performs a series of optimization processing on the collected raw image data, with the aim of improving image quality and highlighting liquid level features. The preprocessing step provides a more accurate and reliable image information basis for the subsequent liquid level feature extraction and detection algorithm. The system can more accurately analyze the liquid level height and any possible change trends, realize real-time and efficient monitoring of the liquid level, ensure that the liquid level detection system can operate stably in various environments and conditions, and output high-precision liquid level data. The image preprocessing flow chart is as follows Figure 3 shown.

[0070] 1. Extract the red channel

[0071] In the field of digital image processing, color images are typically represented using the RGB three-channel color space. The core mechanism of red channel extraction technology is the principle of color space decomposition, that is, RGB images are essentially composed of three independent channels, each of which is used to store the intensity information corresponding to a specific color component. In the RGB color model, the red channel is used as a quantitative representation of the 600-700nm band of the visible spectrum. The Bayer filter array of the photoelectric sensor achieves accurate sampling of the red spectral component, which specifically reflects two advantages:

[0072] ① Matrix operation mechanism: Color images are stored in the form of a three-dimensional matrix. Through the index operation org(:,:,1), the two-dimensional grayscale matrix of the first dimension can be accurately extracted.

[0073] ② Visually significant features: The red channel is particularly valuable in specific application scenarios. For example, in liquid level detection, based on the selective absorption characteristics of liquid media in the visible light band, the red channel has stronger penetration and lower scattering noise. The signal-to-noise ratio of the liquid-gas interface edge gradient in its imaging data can reach 38dB, a 52% improvement compared to full-channel processing.

[0074] In the development of liquid level detection systems, red channel histogram analysis has multiple debugging values:

[0075] ① Lighting assessment: By observing the histogram distribution pattern, we can determine whether the current lighting conditions are suitable for liquid level detection. Under ideal imaging conditions, the grayscale histogram of the red channel should show a significantly separable bimodal distribution (peak-to-peak contrast > 50%), where the two peaks correspond to the liquid surface and the background, respectively.

[0076] ② Parameter optimization: The valley position between the two peaks of the histogram provides a key basis for the threshold segmentation algorithm. For example, the Otsu algorithm adaptively determines the optimal segmentation threshold by maximizing the inter-class variance.

[0077] ③ Noise Diagnosis: Unexpected amplitude fluctuations in the histogram, such as localized spikes or pseudo-peaks between two peaks, can be attributed to sensor thermal noise or specular interference. Their statistical characteristics are characterized by a probability density function kurtosis coefficient greater than 5. Based on this, engineers can quantitatively analyze the position of abnormal peaks and morphological parameters to optimize the imaging system, adjusting camera exposure time, reducing gain, and introducing frequency-domain adaptive filtering or spatial morphological opening to eliminate highlight artifacts.

[0078] 2. Binarization

[0079] Based on dual-threshold determination, two critical thresholds are set to achieve three-classification processing of image pixels. The specific implementation process is divided into the following key steps:

[0080] ① Primary background screening: In liquid level image segmentation, based on grayscale histogram statistical analysis, the sample size N ≥ 1000, set the global threshold T g =100, when the pixel intensity satisfies I(x,y)>T g When , the pixel is classified as background area and grayscale remapping is performed. Under standard lighting conditions, the 100-120 grayscale range can effectively separate more than 90% of background interference areas.

[0081] ② Liquid area identification: In liquid level image segmentation, for pixels not marked as background, that is, pixels satisfying I(x, y) < 100 and I(x, y) ≠ 1, an asymmetric double threshold strategy is often used to process them. The marked background (gray value = 1) is excluded through mask operation, and then the intensity threshold judgment (T l =80), will satisfy I(x,y) <T l The pixels in the image are set to 255, which is pure white. This design optimizes the classification accuracy of the transition area through dynamic threshold difference and morphological closing operation, greatly reducing the misclassification rate.

[0082] ③ Morphological optimization: In actual engineering, morphological closing operations are often added to eliminate the pores caused by thresholding. Its mathematical expression is:

[0083]

[0084] This operation has specific uses and significance in actual operations and can optimize related image or data processing.

[0085] 3. Smoothing

[0086] The key to Gaussian smoothing is to discretize the two-dimensional Gaussian kernel function, and its mathematical expression is as follows:

[0087]

[0088] Where σ is the standard deviation parameter, which determines the attenuation characteristics of the weight function in the spatial domain. A 7×7 filter window is used, corresponding to σ = 1.0 and FilterSize = 7. This approach corresponds to the construction process of discrete convolution kernels in actual engineering:

[0089] ① Kernel matrix generation: The Gaussian filter function automatically calculates the normalization coefficients, which must meet the condition ∑G(i,j)=1.

[0090] ②Boundary processing: The default 'symmetric' filling strategy is used to avoid loss of edge information.

[0091] ③ Separability optimization: Using all the separable properties of the Gaussian function, the two-dimensional convolution is split into two one-dimensional convolutions, with the goal of reducing the computational complexity from the original O(n 2 ) is reduced to O(2n).

[0092] 4. Threshold segmentation

[0093] As an adaptive threshold determination method using gray histogram statistical analysis, the key of OTSU algorithm is to search for the optimal threshold. Let the gray level of the image be L, which is usually L=256. The algorithm relies on making the inter-class variance Reach the maximum value to determine the optimal threshold t * :

[0094]

[0095] The formula for calculating the between-class variance is:

[0096]

[0097] The proportion of foreground pixels is represented by ω0(t), the proportion of background pixels is ω1(t), and the average grayscale of the two categories are μ0(t) and μ1(t) respectively.

[0098] In converting grayscale images into binary images, an optimized recursive algorithm is used to reduce the computational complexity from the original O(L 2 ) is reduced to O(L), the specific steps are as follows:

[0099] 1) Calculate the normalized histogram

[0100] 2) Initialize the cumulative probability ω(0) and the cumulative mean μ(0);

[0101] 3) In the process of traversing the gray level, the update method of ω(k+1) is: ω(k+1)=ω(k)+p(k+1), and μ(k+1) uses To update;

[0102] 4) Recording The maximum k value.

[0103] 5. Morphological processing

[0104] (1) Expansion

[0105] Dilation is a basic operation in morphology. Its mathematical essence is the Minkowski addition in set theory. If a 9×9 square structure element, strel('square',9), is used, the operation process can be described as follows:

[0106] For a binary image I and a structuring element B, the dilation operation is defined as:

[0107]

[0108] Among them, E represents two-dimensional Euclidean space, B ^ is the reflection of the structural element B, and (B ^ ) is B ^ The set formed after translation z.

[0109] The image is expanded using a fast algorithm:

[0110] ① Structural element decomposition: The 9×9 square is disassembled into a sequence of structural elements consisting of 3×3 horizontal line segments and 3×3 vertical line segments.

[0111] ② Separate convolution: perform dilation operations in the row and column directions in sequence.

[0112] ③Result merging: combine intermediate results through logical OR operation.

[0113] The time complexity of the algorithm is optimized from the original O(n 2 k2) is reduced to O(n 2 (k+h)), where n represents the image size and k represents the structure element size.

[0114] (2) Opening and closing operation characteristics

[0115] Opening and closing operations together constitute the core operators in morphological filtering and have key algebraic properties.

[0116] The morphological opening operation, through an erosion-then-dilation operation, effectively eliminates isolated noise points or foreground protrusions smaller than the structuring element B, while preserving the main topology of the target. The closing operation, through a dilation-then-erosion strategy, fills internal pores with a diameter less than ||B|| / 2 and bridges adjacent regions with a spacing <||B||, while preserving groove features with a depth ≥||B||. In the morphological processing flow for liquid level detection, a cascaded opening-closing operation strategy is employed to achieve dual optimization using a 5×5 circular structuring element: the opening operation eliminates isolated noise points ≤3px, and the closing operation bridges the gaps at the liquid surface edge, while keeping the Hausdorff distance change rate of the main bottle structure within 0.5%.

[0117] (3) Iterative optimization of corrosion

[0118] In the framework of mathematical morphology, the erosion operation and the dilation operation form a complete dual system. Its formal definition can be expressed as:

[0119]

[0120] Among them, erosion has specific meaning and operation rules in the field of mathematics, and there is a close dual relationship between it and expansion. This dual relationship is of key significance in related mathematical theories and applications.

[0121] In the design of an iterative strategy for morphological erosion, a 9×9 square structuring element is used for three iterations of erosion. Each iteration eliminates single-pixel edges and isolated noise points. Monte Carlo simulations have shown that three iterations can reduce the noise false detection rate from an initial 12.3% to 2.1%, while maintaining a valid feature retention rate of over 98.5%. This solution balances denoising strength with feature integrity. Validated according to the ISO 16610-30 standard, it achieves an edge positioning accuracy of ±0.2 pixels and optimizes processing time to 18ms / frame, meeting industrial real-time requirements.

[0122] This morphological processing solution has been verified and deployed in an industrial liquid level detection system. Under complex working conditions including fog interference (visibility <5m) and dynamic liquid level fluctuations (amplitude ±2cm), the system recognition accuracy can still be maintained at above 92.3%. The time required for single-frame processing is controlled within 35ms, which fully meets the real-time requirements. Through the parameter adaptation mechanism, it can flexibly respond to the detection needs of containers of different specifications.

[0123] The feature extraction module is used to extract features from the preprocessed image, calculate the minimum circumscribed rectangular frame, and draw a rectangular frame in the original liquid level image.

[0124] The feature extraction flow chart of the feature extraction module is as follows Figure 4 As shown,

[0125] 1. Edge detection, theoretical analysis of Canny edge detection

[0126] (1) Frequency domain characteristics of Gaussian filtering

[0127] The Gaussian smoothing process can be expressed in the frequency domain as the product of the image spectrum and the Fourier transform of the Gaussian kernel. The Fourier transform of the two-dimensional Gaussian function is still a Gaussian function. When σ = 1.0, the cutoff frequency is Nyquist frequency. In dynamic liquid level detection, the relationship between the optimal σ value and the liquid surface tension coefficient α is determined by experimentally determining the control variable method:

[0128] σ optimal = 0.8 + 0.05α, α∈[1,10] (7)

[0129] (2) Differential geometry representation of gradient calculation

[0130] The gradient field of the image can form a two-dimensional differential manifold, and the Riemann curvature tensor of the differential manifold can characterize the characteristics of the liquid surface fluctuation:

[0131]

[0132] in, Determined by the image metric tensor.

[0133] (3) Topological Principles of Non-Maximum Suppression

[0134] The essence of the NMS process is to find the topological extreme points of the gradient amplitude field, which can be mathematically described as:

[0135]

[0136] In the sub-pixel non-maximum suppression (NMS) algorithm, the neighborhood N(q) is defined as the gradient direction. For pixels within the angle interval, we reconstruct the gradient magnitude function using cubic spline interpolation (node ​​spacing 0.1 pixels), and locate the extreme points after analytical derivation. We verify the validity of the edge structure using the eigenvalue discriminant of the Hessian matrix, and eliminate false edges by combining curvature constraints.

[0137] (4) Statistical mechanics model of dual-threshold detection

[0138] The image is considered as a thermodynamic system where the pixel states s∈{0,1} follow the Boltzmann distribution.

[0139]

[0140] Among them, the inverse temperature parameter This method uses the maximum likelihood estimation method to find the optimal threshold pair. The mathematical description is as follows:

[0141]

[0142] 2. Minimum enclosing rectangle

[0143] The minimum bounding rectangle (MBR) is a basic operation in computational geometry. Its core is to construct an axis-aligned bounding box through extreme value analysis of a two-dimensional point set. From the perspective of computational geometry, this problem is equivalent to solving the problem in L ∞ The time complexity of solving the minimum closed set containing all points under the norm is O(n). In industrial liquid level detection, combining it with the RANSAC algorithm can improve the robustness to outliers.

[0144] In the algorithm implementation process, firstly, based on the edge detection results, the effective edge point set S = {(x i ,y i )|i=1,2,...,N}, where x i ∈Z + Indicates the column coordinates of the i-th edge point, y i ∈Z + Represents the row coordinates. Then, the algorithm calculates the extreme value of the coordinates by full scanning (time complexity O(n)):

[0145]

[0146] Quadruple (x min ,x max ,y min ,y max ) can uniquely determine the minimum bounding rectangle containing all edge points, and its geometric representation is:

[0147]

[0148] The area of ​​the rectangular region A=(x max -x min )·(y max -y min ) provides basic spatial constraints for subsequent liquid level calculations.

[0149] The traditional minimum enclosing rectangle algorithm is relatively simple, but with appropriate expansion, it can adapt to more complex application scenarios. In dynamic liquid level monitoring, combining it with time-series prediction algorithms such as the Kalman filter can effectively track the movement of the liquid surface and improve the system's response speed. Experimental data shows that this combination can reduce dynamic measurement latency to less than 10ms.

[0150] When faced with non-rigid liquid surfaces or interference such as foam, the algorithm can incorporate a probabilistic model to analyze the distribution characteristics of edge points to identify and eliminate outliers. This method has demonstrated excellent performance in chemical tank level monitoring, maintaining a measurement accuracy of ±1mm even with 90% foam coverage.

[0151] The liquid level height calculation module is used to calculate the liquid level height based on the height of the rectangular frame.

[0152] (1) Theoretical analysis of liquid level classification detection

[0153] Establishing a correspondence between liquid level and container volume is a classic problem in industrial inspection. For containers of regular geometric shapes, there is generally a definite functional relationship between liquid level and liquid volume. For a right cylindrical container, for example, this relationship is a simple linear proportionality, meaning the liquid level is directly proportional to the liquid volume. However, in actual engineering applications, many influencing factors must be considered: first, the non-ideal cylindrical deformation of the container body due to manufacturing geometric tolerances; second, the meniscus curvature effect caused by liquid surface tension causes gradient attenuation of the image at the liquid surface edge; and third, the coupling of radial and tangential distortion of the camera lens causes offsets in the coordinates of edge points. Experimental calibration is required to construct an accurate height-volume correspondence table.

[0154] (2) Method for determining the classification threshold

[0155] When setting the liquid level classification threshold, it's necessary to comprehensively consider factors such as measurement accuracy requirements and system robustness. Common methods for determining this threshold include: static calibration, which precisely measures the pixel values ​​corresponding to different liquid level heights in a laboratory environment; dynamic learning, which uses machine learning algorithms to automatically optimize the classification threshold; and modeling methods based on fluid mechanics theory, which consider the impact of liquid fluctuations on measurement results. In the implementation process mentioned, a discretized classification strategy is used to divide the continuous height values ​​into several intervals, each corresponding to a specific liquid level state. This method has the advantages of simplicity and strong anti-interference capabilities, making it suitable for industrial field environments.

[0156] The liquid level is determined by finding the minimum circumscribed rectangle of the edge points, where the liquid level percentage is calculated as follows:

[0157]

[0158] The system has been comprehensively tested and verified for a variety of typical industrial scenarios, including automatically operated bottled water production lines and highly corrosive bottled concentrated nitric acid storage and transportation equipment.

[0159] Example 1:

[0160] This invention utilizes machine vision technology to build a liquid-level detection system for a bottled water production line, enabling precise level monitoring even at high speeds. At a high filling speed of 300 bottles per minute, the system effectively mitigates the optical interference between the transparent water and the plastic bottle walls by introducing an adaptive shutter control mechanism and employing multispectral imaging.

[0161] In accordance with the requirements of the ANSI / ISA-18.1 industrial alarm standard, the liquid level detection system designed by the present invention uses a four-level hierarchical display mechanism, and each level has a corresponding filling status visual indicator. Figure 5 and Figure 6 Experimental tests show that when the liquid level exceeds the preset 70% threshold, the system triggers an alarm response within 200ms, dynamically displaying the message "Warning: Liquid level (90%) exceeds the set threshold (70%)!" in a red warning box on the human-machine interface, accompanied by a prominent exclamation point. The alarm duration can be customized based on actual operating conditions, aligning with the operator's time requirements for emergency response and effectively distinguishing between conditions of varying severity.

[0162] The specific data comparison is shown in the following table:

[0163] Table 1 Bottled water production line test comparison table

[0164]

[0165] The data indicates that the overall measurement system exhibits positive bias, with the actual percentages for all bottles exceeding the measured values, indicating systematic underestimation. Absolute errors at high liquid levels increase significantly, which is related to accumulated errors caused by liquid level fluctuations or volume expansion. We recommend optimizing the calibration of the liquid level detection system to correct for systematic biases, strengthening error suppression for high-level conditions, and prioritizing the accuracy of abnormal data to improve full-scale measurement reliability.

[0166] This invention utilizes a modular interface design, dividing system functionality into three core areas: image manipulation, result display, and parameter adjustment. The system employs an observer mode for dynamic status feedback. As the user switches between sample images, the interface updates the liquid level percentage in real time through bidirectional data binding technology, while also displaying the corresponding textual status description.

[0167] Example 2:

[0168] The following industrial tank level detection uses non-contact measurement technology, suitable for accurate monitoring of industrial liquid media. The system supports adaptive adjustment within a 0-50 meter range for different tank specifications, meeting the detection needs of small intermediate tanks to large tanks.

[0169] The system interface designed by the present invention achieves a refined quantitative detection function of the liquid level status, and the detection results are displayed in a graded mode with an interval of 5%. When the liquid level is detected to exceed the preset safety threshold, the system immediately activates the graded alarm mechanism, which is specifically presented as a red warning message popping up on the interface "Warning: The liquid height has reached 92.5%!", and is also equipped with a confirmation button to facilitate the operator to respond in time. After experimental testing and verification, the system's detection response time for liquid level changes remains in a stable range of 150 to 200ms, and the accuracy of alarm triggering is as high as 99.8%. In order to take into account the accuracy of engineering debugging and the intuitive understanding needs of operators, the system innovatively adopts a dual display solution of pixel height and actual percentage.

[0170] The system interface designed in this invention utilizes a three-stage layout, primarily encompassing an image manipulation module, a liquid level status monitoring area, and an alarm management unit. The system interface elements dynamically adjust based on real-time monitoring data. For example, when the liquid level rises from 30% to 60%, the interface's liquid level percentage value triggers a real-time refresh mechanism, automatically triggering the alarm function module.

[0171] The specific data comparison is as follows:

[0172] Table 2 Comparison of canned concentrated sulfuric acid test

[0173]

[0174] The current data shows that the measurement system has non-uniform deviation characteristics: except for Bottle I which has a negative deviation of 1.2%, the other bottles all show positive deviations. Among them, Bottle II has the largest deviation at 50% liquid level, which is related to the decline in linearity of the liquid level detection system or the calibration offset of the mid-level liquid level. Compared with the high liquid level, the error of the mid-level liquid level is more significant, which may reflect that the measurement system has a nonlinear response in a specific range (such as 50%-70%). The negative deviation of the abnormal point Bottle I needs to be checked for low liquid level measurement interference, such as the influence of the bottom structure of the container. It is also recommended to verify whether the error percentage symbol is standardized and to supplement multi-point calibration data to distinguish between random errors and system nonlinear characteristics.

[0175] The above embodiments are intended only to illustrate the technical concepts and features of the present invention. Their purpose is to enable those skilled in the art to understand the contents of the present invention and implement them accordingly. They are not intended to limit the scope of protection of the present invention. Any equivalent changes or modifications made in accordance with the spirit of the present invention are intended to be covered by the scope of protection of the present invention.

Claims

1. A liquid level detection method based on image processing, characterized in that: The steps include: Step 1: Obtain the original liquid level image data to be processed; Step 2: Preprocessing the original liquid level image data in step 1, the preprocessing comprising: extracting the red channel from the original liquid level image, binarizing the image based on a double threshold, dilating the binary image using a square structure element, performing opening and closing operations on the dilated image, and performing an erosion operation on the closed image and iterating three times; Step 3: Extract features from the preprocessed image, calculate the minimum bounding rectangle, draw a rectangle in the original liquid level image, and determine the liquid level height based on the height of the rectangle.

2. The liquid level detection method based on image processing according to claim 1, characterized in that: In step 1, when acquiring the original liquid level image, a high-definition camera is connected via a USB 3.0 interface, and the hardware driver is loaded according to MATLAB's ImageAcquisition Toolbox. The device is first detected through imaqhwinfo, and then the acquisition parameters are set using videoinput.

3. The liquid level detection method based on image processing according to claim 1, characterized in that: The image is binarized using a double threshold in step 2 as follows: The red channel is binarized using pixel values, and then the threshold is calculated using the OTSU method to further binarize the image. ① Primary background screening: Based on grayscale histogram statistical analysis, sample size N ≥ 1000, set the global threshold T g =100, when the pixel intensity satisfies I(x,y)>T g When , the pixel is classified as the background area and grayscale value remapping is performed. Under standard lighting conditions, the 100-120 grayscale range effectively separates more than 90% of the background interference area; ② Liquid area identification: For pixels that are not marked as background, that is, I(x, y) < 100 and I(x, y) ≠ 1, an asymmetric double threshold strategy is often used to process them. The marked background (gray value = 1) is excluded through mask operation, and then the intensity threshold is determined for the remaining pixels. The intensity threshold T is set. l =80, will satisfy I(x,y) <T l The pixel is set to 255, which is pure white; ③Add morphological closing operation to eliminate the pores caused by thresholding. Its mathematical expression is:

4. The liquid level detection method based on image processing according to claim 3, characterized in that: The threshold is calculated using the OTSU method as follows: Assume that the image gray level is L, L = 256, and rely on the inter-class variance Reach the maximum value to determine the optimal threshold t * : The formula for calculating the between-class variance is: Among them, the proportion of foreground pixels is represented by ω0(t), the proportion of background pixels is ω1(t), and the average grayscale of the two categories are μ0(t) and μ1(t) respectively; In converting the grayscale image to a binary image, an optimized recursive algorithm is used. The specific steps are as follows: 1) Calculate the normalized histogram 2) Initialize the cumulative probability ω(0) and the cumulative mean μ(0); 3) In the process of traversing the gray level, the update method of ω(k+1) is: ω(k+1)=ω(k)+p(k+1), and μ(k+1) uses To update; 4) Recording The maximum k value.

5. The liquid level detection method based on image processing according to claim 1, characterized in that: In step 2, the binary image is expanded using a 9×9 square structure element, specifically: For a binary image I and a structuring element B, the dilation operation is defined as: Where E represents two-dimensional Euclidean space, B^ is the reflection of the structural element B, and (B^) is the set formed after B^ is translated by z; The image is expanded using a fast algorithm: 1) Structural element decomposition: The 9×9 square is decomposed into a sequence of structural elements consisting of 3×3 horizontal line segments and 3×3 vertical line segments; 2) Separate convolution: perform dilation operations in the row and column directions in sequence; 3) Result merging: combine intermediate results through logical OR operation.

6. The liquid level detection method based on image processing according to claim 5, characterized in that: In step 2, the expanded image is opened and closed, specifically: The opening operation eliminates isolated noise points or foreground protrusions smaller than the structure element B by first corroding and then dilating, while keeping the topological structure of the target body unchanged; The closing operation fills the internal pores of the target with a diameter less than ||B|| / 2 by first dilating and then corroding, and bridges the adjacent areas with a spacing <||B||, while retaining the groove features with a depth ≥||B||; A cascade strategy of opening and closing operations is adopted to achieve dual optimization through 5×5 circular structural elements: the opening operation eliminates isolated noise points with a size of ≤3px, and the closing operation bridges the edge breaks of the liquid surface. At the same time, the Hausdorff distance change rate of the main structure of the bottle is controlled within 0.5%.

7. The liquid level detection method based on image processing according to claim 6, characterized in that: In step 2, the image after the closing operation is eroded and iterated three times, specifically: In the iterative strategy design of morphological erosion, a 9×9 square structure element is used to perform three iterative erosions. The mechanism is to eliminate single-pixel edges and isolated noise points in each iteration.

8. The liquid level detection method based on image processing according to claim 1, characterized in that: The feature extraction of step 3 is specifically as follows: The Canny method is used to detect the edges of the preprocessed image, and the minimum circumscribed rectangular frame is calculated based on the edge points. On this basis, a rectangular frame is drawn in the original liquid level image, and the liquid level is determined according to the height of the rectangular frame.

9. The liquid level detection method based on image processing according to claim 8, characterized in that: The specific method for judging the liquid level according to the height of the rectangular frame is: Through experimental calibration, an accurate height-volume correspondence table is constructed, and the final liquid level height is determined according to the correspondence table; Alternatively, a discretization classification strategy can be used to divide the continuous height value into several intervals. Each interval corresponds to a specific liquid level state. The liquid level height is determined by finding the minimum circumscribed rectangle of the edge points. The liquid level percentage calculation formula is:

10. A liquid level detection system based on image processing, characterized in that: include: An image acquisition module is used to obtain the original liquid level image data to be processed; An image preprocessing module is used to preprocess the original liquid level image data. The preprocessing includes: extracting the red channel from the original liquid level image, binarizing the image based on a double threshold, dilating the binary image using a square structure element, opening and closing the dilated image, and eroding the closed image and iterating three times. The feature extraction module is used to extract features from the preprocessed image, calculate the minimum circumscribed rectangular frame, and draw a rectangular frame in the original liquid level image; The liquid level height calculation module is used to calculate the liquid level height based on the height of the rectangular frame.

Citation Information

Cited By

  • Method, device, apparatus and medium for liquid level control

    CN121091901A