Non-invasive liquid level measurement system and method based on improved YOLO model

By improving the YOLO model and multi-source collaborative imaging technology, and combining feature optimization and cluster analysis, the problems of pollution risk, environmental interference and measurement error in traditional liquid level detection have been solved, achieving high-precision and rapid liquid level measurement.

CN121190451APending Publication Date: 2025-12-23NANJING UNIV OF SCI & TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511436130.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-10-09
Publication Date
2025-12-23

AI Technical Summary

Technical Problem

Traditional liquid level detection methods pose risks of contamination, significant environmental interference, insufficient identification accuracy, and large measurement errors, making it difficult to meet the real-time detection needs of industry.

Method used

An improved YOLO model is adopted, combined with the GAM attention module and WIOU v3 loss function. Image acquisition and enhancement are performed through multi-source collaborative imaging and liquid level feature optimization algorithm to extract clear contours. Combined with K-means clustering and regression methods, errors are dynamically compensated to achieve real-time liquid level measurement.

Benefits of technology

It achieved a liquid level detection pass rate of 99.01% and an inference speed of 2.2ms, with the measurement error controlled within 0.6mm, meeting the needs of real-time industrial detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121190451A_ABST
    Figure CN121190451A_ABST
Patent Text Reader

Abstract

The invention discloses a non-invasive liquid level measurement system and method based on an improved YOLO model, and the method comprises the steps: collecting images under different conditions through an industrial camera and a cooperative light source, and carrying out the enhancement processing to generate a data set; a GAM attention module and WIOU v3 loss function optimization are introduced into the YOLO; noise reduction is carried out on the image, differential feature enhancement is carried out on a bottle body, a bottle cap and a liquid level, and a clear contour is extracted; based on the improved YOLO positioning pixel height, establishing a real-time detection equation; classifying the sample data, and constructing each type of conversion equation; and through double-path comparison verification, the error is ensured to be within a threshold value, and the measurement accuracy is verified. According to the method, by improving a YOLO model architecture, liquid level feature extraction is enhanced, bounding box regression is optimized, and the high framing qualification rate and the high reasoning speed are both considered; the environment adaptability is high, a complex environment can be simulated by means of a multi-light-source experiment table and data enhancement, and the model generalization ability is improved; the measurement precision is high, and the liquid level measurement error can be strictly controlled through a high-precision calculation method and image processing.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application belongs to the technical field of liquid level detection based on computer vision and deep learning, and particularly relates to a non-invasive liquid level measurement system and method based on an improved YOLO model. BACKGROUND

[0002] Liquid level detection is a key technology in the fields of industrial automation, medical health and environmental monitoring, and its core is to accurately measure the height and volume parameters of the liquid in a sealed container. Traditional liquid level detection methods have significant limitations: invasive measurement (such as mechanical probes) may cause sample contamination, especially when dealing with corrosive or radioactive liquids, which poses a safety hazard; non-invasive methods (such as ultrasonic sensors) are affected by container deformation, medium characteristics and environmental temperature and humidity, with measurement errors of up to ±3mm or more, and complex installation and maintenance; in existing computer vision-based methods, traditional machine learning relies on manual feature extraction, with limited accuracy; some deep learning models (such as the basic YOLO series) have insufficient detection accuracy for liquid levels in complex lighting and noisy environments (with a frame qualification rate of less than 85%), and have long inference times, making it difficult to meet industrial real-time requirements.

[0003] To eliminate the interference of various colors on liquid level line detection, the adaptive visual liquid level recognition method patent with patent number 2025101141310 made targeted efforts: it converts color images to grayscale images by grayscale processing the input images of the detection network, thus stripping away the interference of color information on the features of the liquid level line, allowing the algorithm to focus on the brightness, edge and other essential features of the liquid level line, thereby achieving accurate recognition of the liquid level of various colored solutions and improving the method's generalization ability for different colored solutions. However, this patent has the problem of complex calculation and long time consumption when using instance segmentation algorithms. Although it implements the flexible strategy of "introducing instance segmentation when needed and not calculating when not needed" through optimization, instance segmentation itself involves pixel-level segmentation of targets in images, requiring the processing of a large number of detailed features, which makes the operation process complex and consumes a lot of computing resources. SUMMARY

[0004] The present application aims to solve the following technical problems: first, the limitations of traditional liquid level detection methods, traditional invasive methods have pollution risks, and non-invasive ultrasonic and other technologies are greatly affected by environmental interference; the existing visual detection model has insufficient recognition accuracy for liquid level (especially low liquid level and strong noise environment), the qualification rate is generally lower than 85%, and the reasoning time is long (>5ms), which is difficult to meet the real-time detection requirements of industry; second, the difficulty of feature extraction of liquid level images in complex environments, liquid level images are easily affected by uneven lighting, container materials (such as opaque bottle bodies), liquid color and radioactive noise, resulting in blurred liquid level edges and unclear features, and traditional image processing methods (such as simple threshold segmentation) cannot effectively extract liquid level contours, affecting measurement accuracy; third, the mapping relationship between liquid level pixel height and actual height is unstable, due to changes in shooting distance, focal length and viewing angle, the mapping relationship between pixel height and actual height of the liquid level in the image is different, and a single conversion model can easily lead to large measurement errors (>1mm). The present application proposes a system for non-invasive high-precision liquid level measurement by improving the YOLO model, multi-light source cooperative imaging and liquid level feature optimization algorithm, which is suitable for liquid level detection of closed containers in industrial production, nuclear environment monitoring and other scenes.

[0005] In order to achieve the purpose of the present application, a non-invasive liquid level measurement method based on an improved YOLO model is disclosed, comprising the following steps:

[0006] Step 1, image acquisition and enhancement: images under different conditions are acquired by an industrial camera and a cooperative light source, and a data set is generated after enhancement processing;

[0007] Step 2, improve the YOLO model: compare the YOLO series model, select YOLOv8n and introduce the GAM attention module and WIOU v3 loss function optimization;

[0008] Step 3, image post-processing and feature extraction: denoise the image and perform differential feature enhancement on the bottle body, cap and liquid level to extract a clear contour;

[0009] Step 4, liquid level height calculation: based on the improved YOLO positioning pixel height, combined with the "detection-enhancement-calibration-computation" closed-loop dynamic error compensation, an real-time detection equation is established;

[0010] Step 5, liquid level height fitting: use K-means to cluster the sample "pixel height-actual height" data into 3 categories, and combine the least squares method, ridge regression and Lasso regression to construct a conversion equation for each category;

[0011] Step 6, comparison and verification: compare and verify the calculation results of the two paths through the "real-time detection + clustering fitting" double-path comparison, ensure that the error is within the threshold, and verify the measurement accuracy.

[0012] Further, in step 1, an industrial camera is used to collect original images under different liquid levels, viewing angles, and liquid color conditions, ensuring that the complete bottle body, cap, and liquid level line are included, and the original images are subjected to angle rotation, color correction, and data enhancement operations such as adding noise; the liquid level covers the low liquid level area (7-11.5mm), the normal liquid level area (11.5-50.5mm), and the bottle body blocking area (32.5-35.5mm); the data set after data enhancement is divided into training set and validation set in a ratio of 4:1.

[0013] Further, in step 2, a GAM attention module is embedded in the Backbone of YOLOv8n to enhance the feature extraction capability of the liquid level area; the channel attention submodule of the GAM module converts the input feature dimension to , processes it through MLP, restores the dimension, and generates channel attention weights through sigmoid; the spatial attention submodule uses a 7x7 convolutional network to generate spatial attention weights, and the two types of weights are fused with the original feature tensor;

[0014] At the same time, the WIoU v3 loss function is used to replace the original CIoU loss function of YOLOv8n, the anchor box outlying degree (the smaller the value, the higher the anchor box quality) is calculated, combined with hyperparameters α, , and a non-monotonic focusing coefficient is constructed to optimize the bounding box regression accuracy, and the formula is:

[0015]

[0016]

[0017]

[0018] wherein, is the monotonic focusing coefficient; is the exponential moving average value with momentum m.

[0019] Further, in step 3, the positioning frame region image output by the YOLO model, which contains the bottle body, cap, and liquid level, is classified and post-processed to accurately extract features and provide pixel-level data, and the specific processing is as follows:

[0020] Liquid level: convert the liquid level area color image to a grayscale image, enhance the contrast with CLAHE, denoise with 3x3 median filtering, and adaptively binarize with Otsu's algorithm; fill the holes through elliptical structure element closing operation, eliminate noise points by connected region area threshold screening, and extract the liquid level contour through Canny edge detection.

[0021] Body: Convert the color image of the bottle body area to a grayscale image after CLAHE processing; Sobel operator calculates the gradient to highlight the edges, and Otsu's method threshold segmentation generates a binary image of the bottle body contour.

[0022] Cap: Convert the color image of the bottle cap area to a grayscale image, and denoise with 5x5 median filtering; enhance the contrast with CLAHE, and extract the cap contour with Canny edge detection.

[0023] Further, in step 4, through the closed-loop design of "detection-enhancement-calibration-computation", combined with dynamic compensation of the difference in shooting conditions by modifying parameters, real-time liquid level height measurement is finally realized, which is specifically:

[0024] Step 4-1, improved YOLO pixel coordinate output: improve the YOLO model to identify the input image, output the left upper corner and right lower corner pixel coordinates of the positioning frame of three types of targets, and calculate the original positioning frame height;

[0025] Step 4-2, differential pixel coordinate output: based on the three types of positioning frames output by the improved YOLO, differential enhancement processing is performed respectively, and the processed pixel height is extracted:

[0026] Step 4-3, pixel height confirmation: taking "the relative deviation of the processed height and the original positioning frame height ≤10%" as the judgment condition, when the condition is met, the processed height is used; otherwise, the original positioning frame pixel height is used;

[0027] Step 4-4, calculation of correction parameters and conversion ratio: through the calculation of correction parameters compensate for the mapping deviation of "pixel height-real height" caused by the change of shooting conditions, so as to obtain the accurate conversion coefficient of pixel height and actual height, and the calculation formula is as follows:

[0028]

[0029] Conversion ratio

[0030] Step 4-5, output liquid actual height:

[0031] Step 4-6, real-time detection equation: form the real-time detection equation by integrating steps 4-1 to 4-5:

[0032]

[0033]

[0034]

[0035] Wherein, N is the pixel height and the real height of the bottle body, the cap of the cross calculation of the deviation term, reflecting the mapping difference between the two due to the change of shooting conditions; D is the real height difference between the bottle body and the cap, used to normalize the deviation term.

[0036] Further, in step 5, the specific process of clustering grouping and fitting equation construction is as follows: through systematic data processing and model optimization, the problem of unstable "pixel height-actual height" mapping relationship caused by shooting distance and focal length change is solved:

[0037] Step 5-1, sample data preparation and pretreatment: 300 samples are selected to form "pixel height-actual height" sample pairs (actual height is measured by electronic vernier caliper at 90° around the bottle for 4 times to take the average value), and the data is standardized by StandardScaler;

[0038] Step 5-2, K-means clustering algorithm implementation: K-means clustering (candidate k=2~5), Euclidean distance, iteration 500 times or center change less than 1e-4 stop, calculate the silhouette coefficient s of each k value clustering result, select the highest result of the silhouette coefficient, the calculation formula is:

[0039]

[0040] Wherein, is the average distance between sample and other samples in the same cluster, is the average distance between sample and the nearest sample in the different cluster; The overall silhouette coefficient is the average value of all samples , the value range is [-1, 1], the closer to 1 indicates the better clustering effect;

[0041] Step 5-3, fitting equation construction application: for each clustering sample, respectively adopt least square method, ridge regression, Lasso regression to construct linear conversion equation, calculate and RMSE root mean square error to evaluate the fitting effect, select the optimal equation, after 5-fold cross-validation, the new sample calls the corresponding equation according to the clustering.

[0042] Further, in step 6, the "real-time detection and clustering fitting" double-path comparison method proposed by fitting the liquid level height gets two measured height values, which not only uses dynamic correction parameters to adapt to the change of shooting conditions, but also guarantees the reliability of the theoretical model based on clustering fitting equation, and the comparison of the two realizes the double verification of the measurement accuracy;

[0043] Step 6-1, double-path result acquisition:

[0044] Real-time detection path: based on the real-time detection equation in step 4, the actual height of liquid level is output: ;

[0045] Cluster fitting path: based on step 5 cluster analysis and fitting equation, output the optimal fitting equation liquid actual height: ;

[0046] Step 6-2, comparison and verification logic:

[0047] Calculate the absolute difference between the results of the two paths: ;

[0048] When , output the final liquid level height: when , determine that there is an anomaly, trigger the secondary verification mechanism: re-execute step 3 and cluster attribution determination, still over limit, output the result with small deviation from the historical value and mark "to be manually checked".

[0049] In order to achieve the purpose of the application, the application discloses a non-invasive liquid level measurement system based on an improved YOLO model, the system is based on the non-invasive liquid level measurement system and method based on the improved YOLO model in any one of claims 1-7, characterized in that, comprising:

[0050] Image acquisition and enhancement module; through industrial camera and cooperative light source, images under different conditions are collected, and data sets are generated through angle rotation, color correction and enhancement processing;

[0051] YOLO model improvement module; compared with YOLO series model, YOLOv8n is selected and GAM attention module and WIOU v3 loss function are introduced for optimization;

[0052] Liquid level height fitting module; image noise reduction and differential feature enhancement for bottle body, bottle cap and liquid level are carried out, and clear contour is extracted;

[0053] Image post-processing and feature extraction module; the sample "pixel height-actual height" data is clustered into 3 categories by K-means, and each category conversion equation is constructed by combining the optimal regression of each cluster;

[0054] Liquid level height calculation module; based on the liquid level pixel height output by the improved YOLO, the actual height is calculated through real-time detection calibration and cluster equation two paths;

[0055] Contrast verification module: compare the calculation results of the two paths to ensure that the error is within the threshold, and verify the measurement accuracy.

[0056] Compared with the prior art, the significant progress of the present application is that: by improving the YOLO model architecture, the GAM attention module is introduced to strengthen the liquid level feature extraction capability, and the WIOU v3 loss function is combined to optimize the boundary box regression, realizing the liquid level frame qualified rate of 99.01% and the inference speed of 2.2ms; based on the multi-light source cooperative strategy, a rectangular + bar light source experiment table is designed, and data enhancement technologies such as angle rotation and noise addition are applied, which effectively simulates complex environments such as nuclear radiation to improve the model generalization ability; a high-precision liquid level calculation method is adopted, a pixel-actual height mapping equation is constructed through clustering analysis and Lasso regression, combined with image noise reduction and edge detection processing, the measurement error is strictly controlled within 0.6mm.

[0057] To make the functional characteristics and structural parameters of the present application clearer, the following further describes the present application in combination with the drawings and specific embodiments. BRIEF DESCRIPTION OF DRAWINGS

[0058] The drawings described herein are used to provide further understanding of the present application, and form a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application, and do not constitute an improper limitation on the present application. In the drawings:

[0059] Figure 1 is a schematic diagram of a non-invasive liquid level measurement system based on an improved YOLO model;

[0060] Figure 2 is a schematic diagram of a GAM attention module architecture;

[0061] Figure 3 is a comparison line graph of model performance;

[0062] Figure 4 is a schematic diagram of the specific height condition of the experimental bottle;

[0063] Figure 5 is a schematic diagram of the shooting area of the sample image. DETAILED DESCRIPTION

[0064] The technical solutions in the embodiments of the present application will be described clearly and completely below in combination with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, not all the embodiments of the present application; based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.

[0065] A non-invasive liquid level measurement method based on an improved YOLO model comprises the following steps:

[0066] Step 1: Image Acquisition and Enhancement; Images under different conditions are acquired using an industrial camera and a collaborative light source, and then enhanced to generate a dataset;

[0067] Step 2: Improve the YOLO model; compare with the YOLO series models, select YOLOv8n and introduce the GAM attention module and WIOU v3 loss function for optimization;

[0068] Step 3: Image post-processing and feature extraction; Denoise the image and perform differential feature enhancement on the bottle body, cap, and liquid level to extract clear contours;

[0069] Step 4: Liquid level height calculation; Based on the improved YOLO positioning pixel height, and combined with the closed-loop dynamic compensation error of "detection-enhancement-calibration-calculation", a real-time detection equation is established;

[0070] Step 5: Liquid level height fitting; use K-means to cluster the sample "pixel height - actual height" data into 3 classes, and combine the least squares method, ridge regression and Lasso regression to construct the transformation equation for each class;

[0071] Step 6: Comparison and verification: By comparing the calculation results of the two paths through "real-time detection + cluster fitting", the error is ensured to be within the threshold, thus verifying the accuracy of the measurement.

[0072] Specifically, in one implementation, the image acquisition and enhancement steps in step 1 are as follows:

[0073] Step 1-1: Construct a multi-light source collaborative experimental platform consisting of an industrial camera (HT-UBS502C), a rectangular light source (10cm×15cm), a strip light source (2cm×14cm), and a light source controller. The rectangular light source is used to uniformly illuminate the experimental bottle, and the strip light source can be adjusted to focus on the low liquid level area. The brightness of both is adjusted synchronously through the light source controller.

[0074] Steps 1-2: Image acquisition. Due to the limitation of small capacity of the experimental bottles in the study, after multiple experiments, 0.4ml and 0.5ml were determined as the minimum liquid level. The specific liquid level heights are shown in the figure, where a is the highest liquid level of 50.5mm, b is the area of ​​the bottle body obstructed by the obstruction of the person, 32.5-35.5mm, c is the low liquid level area, 7-11.5mm, d is the bottle height of 72.5mm, and e is the bottle cap height of 17.5mm.

[0075] Using opaque experimental bottles as the subject, the liquid volume (range 1ml to 8ml) was controlled by a syringe with an accuracy of 0.2ml, and the liquid level was adjusted in 0.2ml increments. In the horizontal direction, the container was rotated 15° to 60° to the right from the center of the container. In the vertical direction, three viewing angles were set: downward, level, and upward (angle change of 5°). The shooting distance was controlled within the range of 20 to 50cm. Images of transparent liquids were mainly collected, and a small number of images of dark liquids were collected.

[0076] The area where excellent sample images were ultimately captured in this study is as follows: As shown; the shooting area L is the range of distances from the camera directly in front of it (20-50cm); K is the camera shooting boundary with a distance of 20cm as the reference, 18cm high and 55mm wide.

[0077] Steps 1-3: Use an industrial camera to capture original images under different liquid levels, viewing angles, and liquid colors to ensure that the entire bottle body, cap, and liquid level line are included and there is no glare interference. A total of 1180 original images were captured.

[0078] Steps 1-4: Perform data augmentation operations on the original image, including angle rotation, color correction, and noise reduction.

[0079] Specifically, the angle rotation process involved extracting 200 original images and rotating them clockwise by 5°, resulting in 200 new samples; the color correction process involved adjusting the colors of some images, specifically increasing the hue of the blue channel by 5 angular units, decreasing the saturation by 25 units and the brightness by 10 units, while increasing the contrast by 50%, resulting in 150 new samples; and the noise addition process simulated radioactive noise in a nuclear environment by adding Gaussian noise and salt-and-pepper noise to the images, resulting in 100 new samples each.

[0080] Steps 1-5: Integrate the original images with the enhanced images to form a dataset containing 1730 images for model training and validation.

[0081] Final formation Sample shown:

[0082] Table 2 Sample Set

[0083]

[0084] Specifically, in one implementation, such as Figure 2As shown, in step 2, a GAM attention module is embedded in the YOLOv8n Backbone to enhance the feature extraction capability of the liquid level region. The YOLOv8n Backbone uses the C2f module as the core unit and gradually extracts multi-scale features through convolutional layers and downsampling operations. In the deep feature extraction stage of the Backbone, i.e., after the output of the C2f module before the SPPF module, a GAM attention module is embedded. This module consists of a channel attention submodule and a spatial attention submodule connected in series. The channel attention submodule amplifies the global interaction between channels through 3D arrangement and two layers of multilayer perceptron (MLP). First, the dimension of the input features is converted from C×W×H to W×H×C. After MLP processing, the dimension is restored and channel attention weights are generated using the sigmoid function. The spatial attention submodule removes the traditional pooling operation and uses a 7×7 convolutional network to enhance spatial information fusion. It further generates spatial attention weights for the features after channel attention processing. Finally, the two types of weights are fused with the original features through tensor multiplication. This adaptively enhances the feature response of liquid level regions (such as liquid level edges and the junction of the liquid surface and the bottle body), suppresses irrelevant background interference, and improves the model's ability to capture liquid level features in complex scenarios such as low liquid levels and blurred edges.

[0085] Meanwhile, the WIoU v3 loss function is used to replace the original CIoU loss function of YOLOv8n in order to optimize the bounding box regression accuracy;

[0086] WIoU v3 adds a focusing mechanism based on v1 by constructing a method for calculating gradient gain and dynamic non-monotonic coefficients:

[0087]

[0088]

[0089]

[0090] in, This represents the outlier of the anchor frame; the smaller the value, the higher the quality of the anchor frame. It is the monotonic focusing coefficient; It is an exponential moving average with momentum m; It is a non-monotonic focusing coefficient; For hyperparameters;

[0091] WIoU v3 introduces a dynamic non-monotonic focusing mechanism based on WIoU v1, which calculates the anchor frame outlier β, where β is the monotonic focusing coefficient. With exponential moving average The ratio of β, ranging from (0, +∞), is used in conjunction with hyperparameters α and δ to construct a non-monotonic focusing coefficient r. This coefficient allocates a smaller gradient gain to high-quality anchor boxes (with smaller β values, typically β < 1), allowing model training to focus on the bounding box regression of ordinary-quality anchor boxes and reducing harmful gradient interference from low-quality samples (such as liquid level box offsets caused by uneven lighting). In this embodiment, α = 0.5, δ = 3.

[0092] By embedding the GAM attention module into the Backbone to enhance liquid level feature extraction and combining the WIoU v3 loss function to optimize bounding box regression, the improved YOLOv8n model increases the qualified rate of liquid level identification from the original 80.18% to 99.01%, and reduces the inference time per image to 2.2ms, significantly enhancing the feature extraction capability and detection accuracy of liquid level areas in complex scenes.

[0093] Specifically, in one implementation, step 3 involves post-processing the image of the location bounding box region, including the bottle body, cap, and liquid level, output by the YOLO model to accurately extract features and provide pixel-level data for subsequent height calculation. This includes:

[0094] Step 3-1: Obtain the positioning bounding box region; based on the pixel coordinates (top left corner, bottom right corner) of the positioning bounding box of the bottle body, bottle cap, and liquid level output by the YOLO model, crop out the corresponding local image region as the object for subsequent processing;

[0095] Step 3-2: Classification image processing;

[0096] Liquid level analysis: The cropped color image of the liquid level region is first converted to grayscale, and then local contrast is enhanced by adaptive histogram equalization (CLAHE) with contrast limitation. Salt-and-pepper noise is removed by 3×3 median filtering, and adaptive binarization is achieved by Otsu's algorithm. Holes in the region are filled by morphological closing operation of elliptical structuring elements, residual noise points are eliminated by screening based on the area threshold of connected regions, and finally, the complete liquid level contour is extracted by Canny edge detection.

[0097] Bottle body: For the color image of the bottle body area, first use CLAHE processing to suppress highlight overexposure and improve the contrast of low-light areas, and then convert it to grayscale; use the Sobel operator to calculate the gradient in the horizontal and vertical directions to highlight edge details, and finally use Otsu's method to perform adaptive threshold segmentation to generate a binary image of the bottle body outline.

[0098] Bottle cap: The color image of the bottle cap area is directly converted to grayscale and then a 5×5 median filter is used to remove noise and smooth the texture. The contrast is enhanced by CLAHE to strengthen edge features, and finally the complete outline of the bottle cap is extracted by Canny edge detection.

[0099] Step 3-3: Output processing results: Output the clear outline pixel positions of the processed liquid level, bottle body, and bottle cap in real time. Combined with the original positioning box coordinates, it provides accurate feature data for subsequent pixel calculation of liquid level height.

[0100] Specifically, in one implementation, in step 4, the pixel positions of the liquid level, bottle body, and bottle cap are obtained based on the liquid level positioning bounding box output by the improved YOLO model and feature extraction processing; simultaneously, using the pixel height of the bottle body and bottle cap positioning bounding boxes as a reference, and through a closed-loop design of "detection-enhancement-calibration-calculation," combined with dynamic compensation for differences in shooting conditions using correction parameters, real-time liquid level height measurement is finally achieved, specifically as follows:

[0101] Step 4-1, Detection Stage: Improve YOLO localization and pixel coordinate output; improve the YOLO model (YOLOv8n+GAM+WIOU v3) to recognize the input image and output the pixel coordinates of the localization boxes for three types of targets, with the top left corner as the target. bottom right corner Specifically:

[0102] Bottle positioning frame: , ;

[0103] Bottle cap positioning frame: , ;

[0104] Liquid level positioning frame: , .

[0105] Calculate the original positioning frame height:

[0106] Original bottle height in pixels: ;

[0107] Original bottle cap pixel height: ;

[0108] Original liquid level pixel height: .

[0109] Step 4-2, Enhancement: Optimization of image features in the bounding box region;

[0110] Based on the positioning bounding box output by YOLO, partial images of the liquid level, bottle body, and bottle cap are cropped, and differential enhancement processing is performed on each. See step 3 for image post-processing, and extract the pixel height after processing.

[0111] The processed bottle height in pixels; the "vertical pixel difference of the bottle outline" is obtained through Sobel gradient calculation and edge extraction. .

[0112] in, Let y be the bottom coordinate of the bottle's outline. Let y be the y-coordinate of the top of the bottle's outline.

[0113] Processed bottle cap pixel height: Obtained through Canny edge detection, yielding the "vertical pixel difference of the bottle cap outline". .

[0114] in, Let y be the bottom edge of the bottle cap outline. Let y be the y-coordinate of the top of the bottle cap outline.

[0115] Processed liquid level pixel height: The "vertical pixel difference of the liquid level contour" is obtained through Canny edge detection and morphological closing operation. .

[0116] in, The y-coordinate of the bottom of the liquid level profile. The y-coordinate is the top edge of the liquid level profile.

[0117] Step 4-3, First calibration step: Pixel height confirmation; To balance positioning stability and feature accuracy, when the difference between the processed height and the original positioning frame height is ≤10% (threshold based on experimental verification), the processed height is used; otherwise, the original positioning frame height is used.

[0118] The selection logic is as follows, using "the relative deviation between the processed height and the original positioning frame height is ≤10%" as the criterion:

[0119] Bottle height in pixels:

[0120]

[0121] Among them, relative deviation ;

[0122] Bottle cap pixel height:

[0123]

[0124] Among them, relative deviation ;

[0125] Liquid level pixel height:

[0126]

[0127] Among them, relative deviation .

[0128] Step 4-4, Second calibration stage: Calculate correction parameters and conversion ratio;

[0129] Get the actual height:

[0130] Load the actual physical height of the bottle body and cap from a preset JSON configuration file:

[0131] Actual height of the bottle: (Total height of the experimental bottle);

[0132] Actual height of bottle cap: (Physical height of bottle cap);

[0133] Calculate correction parameters :

[0134] The formula used to compensate for the "pixel height - actual height" mapping deviation caused by changes in shooting conditions (distance, focal length) is:

[0135]

[0136] Calculate the true conversion ratio :

[0137] Based on the correction parameter z, the accurate conversion coefficient between pixel height and actual height is obtained:

[0138]

[0139] Steps 4-5: Calculation: Output the actual liquid level height;

[0140] Convert the liquid level pixel height to the actual height using a conversion ratio:

[0141]

[0142] Steps 4-6: Real-time Detection Equation (Integrated Closed-Loop Process); Integrating the closed loop of "Detection (YOLO positioning) - Enhancement (image processing) - Calibration (parameter correction) - Calculation (actual height)," the final real-time detection equation is:

[0143]

[0144]

[0145]

[0146] Where N: the deviation term calculated by cross-referencing the pixel height of the bottle body and the bottle cap with the actual height, reflecting the mapping difference between the two due to changes in shooting conditions;

[0147] D: The actual height difference between the bottle body and the bottle cap (fixed value) ), used to normalize the deviation term.

[0148] The equation achieves a closed loop of "YOLO positioning (detection) → feature enhancement → bottle / cap calibration → actual height calculation", which controls the measurement error within 0.6mm and has an average calculation time of 50ms, meeting the requirements of real-time performance and accuracy.

[0149] Specifically, in one implementation, the specific process of clustering and fitting equation construction in step 5 is as follows: through systematic data processing and model optimization, the problem of unstable "pixel height - actual height" mapping relationship caused by changes in shooting distance and focal length is solved:

[0150] Step 5-1: Sample data preparation and preprocessing;

[0151] 300 high-quality samples were selected from the dataset (covering different liquid levels, shooting distances of 20–50 cm, focal length variations, and three lighting conditions) to ensure that the samples covered the low liquid level area (7–11.5 mm), normal liquid level area (11.5–50.5 mm), and bottle-covered area (32.5–35.5 mm) of the experimental bottle. Each sample was measured four times around 90° using electronic calipers, and the average value was recorded to record the actual liquid level height (true value). At the same time, the liquid level pixel height (pixel value) after feature enhancement in step 3 was extracted to form a one-to-one correspondence between "pixel height - actual height" sample pair.

[0152] Feature standardization was performed using StandardScaler to standardize the sample data and eliminate dimensional differences (pixel height range is 200-1200 pixels, actual height range is 7-50.5mm). The standardization formula is as follows:

[0153]

[0154] in, These are the original eigenvalues. The sample mean. The standard deviation of the samples is used to ensure that the contribution weights of pixel height and actual height to the clustering results are balanced.

[0155] Step 5-2: Implementation of the K-means clustering algorithm;

[0156] Initial clustering parameter settings: candidate range for the number of clusters: k=2, 3, 4, 5 (determined based on preliminary experiments, covering possible groupings of shooting parameters);

[0157] Distance metric: Euclidean distance is used to calculate the similarity between samples, reflecting the difference in the mapping relationship between "pixel height - actual height";

[0158] Iteration stopping condition: Stop when the maximum number of iterations is 500, or when the change in cluster centers is less than 1e-4;

[0159] Clustering process: First, randomly select k initial cluster centers from the standardized samples; second, calculate the Euclidean distance between each sample and each center, and assign the sample to the nearest cluster; third, recalculate the center of each cluster (sample mean), and repeat steps 2-3 until the stopping condition is met; fourth, to avoid random errors in the initial centers, run each k value 10 times independently, and select the cluster result with the highest silhouette coefficient.

[0160] Step 5-3: Determine the optimal number of clusters (based on silhouette coefficient evaluation);

[0161] Silhouette coefficient calculation: For each value of k, the silhouette coefficient s is calculated to evaluate the clustering quality. The formula is:

[0162]

[0163] in, For the sample The average distance from other samples in the same cluster (cluster compactness). For the sample The average distance to the nearest heterogeneous sample (inter-cluster separation); the overall silhouette coefficient is the average distance to all samples. The mean of the clustering, with a value range of [-1, 1], indicates a better clustering effect as it is closer to 1;

[0164] Optimal k value selection: Experimental results show:

[0165] When k=2, the profile coefficient is 0.425 (the difference within the cluster is large, and the samples at low liquid level and normal liquid level are not completely separated).

[0166] When k=3, the contour coefficient is 0.575 (high density within clusters, clear boundaries between clusters, corresponding to 3 typical shooting parameters: close distance + low focal length, medium distance + medium focal length, and long distance + high focal length).

[0167] When k=4, the silhouette coefficient is 0.510 (redundant clusters appear, some clusters have a sample size of <30, and the stability is poor).

[0168] Therefore, the optimal number of clusters, k=3, was selected, with the three clusters corresponding to the mapping patterns under different shooting parameters.

[0169] Step 5-4: Constructing the fitting equation (establishing a pixel-to-actual height conversion model by clustering).

[0170] For the sample data of each cluster, three regression methods were used to construct linear transformation equations, and the optimal model was determined through parameter tuning and performance comparison.

[0171] Regression methods and parameter optimization: Calculate from the following three types of regression models The RMSE (root mean square error) is used to evaluate the fit.

[0172]

[0173] in, This represents the actual height as the true value. For predicted values, The true value is the mean; according to experiments... This indicates that the Lasso regression model for cluster 2 has the best performance. (Most explanatory) (Minimum error), the equation is:

[0174] Table 3 Fitting equations for liquid level height calculation (blank indicates no value).

[0175]

[0176] Least squares method: No regularization, directly solves for linear regression parameters. , For actual high, The height is in pixels;

[0177] Ridge Regression: Introduction Regularization, the optimal regularization coefficient is determined through grid search. (Candidate Scope) ), balancing model complexity with the risk of overfitting;

[0178] Lasso Regression: Introduction Regularization, also using grid search to determine the optimal value. To achieve feature selection;

[0179] Step 5-5: Validation and application of the fitted model;

[0180] For the optimal equation of each cluster, 5-fold cross-validation is used (the samples are randomly divided into 5 groups, and 4 groups are used for training and 1 group for validation in turn) to ensure the generalization ability of the model. Cross-validation is performed for cluster 2. The mean value is 0.948, verifying stability;

[0181] Through the above steps, cluster analysis effectively decomposes the complex mapping relationship caused by changes in shooting distance and focal length into three groups of well-defined sub-relationships. The fitting equations constructed by combining the three regressions provide a robust theoretical model for liquid level height calculation, which complements the real-time detection equation in step 4 and together ensures measurement accuracy (error ≤ 0.6 mm).

[0182] Specifically, in one implementation, in step 6, two measured height values ​​are obtained by using the "real-time detection and cluster fitting" dual-path comparison method proposed by the liquid level height fitting. This method utilizes dynamic correction parameters to adapt to changes in shooting conditions and ensures the reliability of the theoretical model based on the cluster fitting equation. The comparison of the two methods achieves dual verification of measurement accuracy.

[0183] Step 6-1: Obtaining the results of the dual-path approach;

[0184] Real-time detection path (dynamic calibration result); Based on the real-time detection equation in step 4, output the actual liquid level height:

[0185]

[0186] Clustering fitting path (theoretical model results); Based on the clustering analysis and fitting equation in step 5, the actual liquid level height is output:

[0187] First, determine the liquid level pixel height of the current sample. Standardize the data (using the same StandardScaler parameters as in step 5); then determine the cluster to which the sample belongs using a K-means clustering model (e.g., cluster 2); finally, call the best-fit equation for the corresponding cluster (e.g., the Lasso regression equation for cluster 2):

[0188]

[0189] This result is based on the mapping pattern under fixed shooting parameters, ensuring consistency with the theory;

[0190] Step 6-2: Compare and verify the logic;

[0191] Error calculation; calculate the absolute difference between the results of the two paths:

[0192]

[0193] Threshold determination: Based on experimental verification (error ≤ 0.6 mm for 30 groups of samples), a threshold was set. Handle according to the situation:

[0194] when When the measurement result is deemed valid, the final liquid level height is output (the average of the two paths is taken to reduce random error):

[0195]

[0196] when If an anomaly is detected (such as a sudden change in shooting parameters or an error in feature extraction), a secondary verification mechanism is triggered: the feature enhancement in step 3 is re-executed (secondary CLAHE enhancement and edge refinement are performed on the liquid level area).

[0197] Next, recalculate the cluster assignment (checking if clustering errors were caused by sample anomalies); finally, if the secondary verification is successful... If the limit is still exceeded, output the result with the smaller deviation from the historical measurement value (last 5 frames) between the two paths, and mark it as "awaiting manual verification".

[0198] Through the above process, the "real-time detection path" ensures adaptability to dynamic shooting conditions, while the "cluster fitting path" provides a theoretical benchmark. The comparison between the two controls random errors (through mean output) and identifies system anomalies (through threshold judgment), achieving dual assurance of measurement accuracy and meeting the requirements of industrial scenarios for detection reliability.

[0199] A non-invasive liquid level measurement system based on an improved YOLO model includes:

[0200] Image acquisition and enhancement module: Acquires images under different conditions using an industrial camera and a collaborative light source, and generates a dataset through angle rotation, color correction and enhancement processing.

[0201] YOLO model improvement module; compared with the YOLO series models, YOLOv8n was selected and the GAM attention module and WIOU v3 loss function were introduced for optimization.

[0202] Liquid level fitting module; performs image noise reduction and differential feature enhancement for bottle body, cap, and liquid level, extracting clear contours;

[0203] Image post-processing and feature extraction module: K-means is used to cluster the sample "pixel height - actual height" data into 3 classes, and the optimal regression of each cluster is combined to construct the transformation equation for each class;

[0204] Liquid level height calculation module; based on the liquid level pixel height output by the improved YOLO, the actual height is calculated through two paths: real-time detection calibration and clustering equation;

[0205] Comparison and verification module: Compare the calculation results of the two paths to ensure that the error is within the threshold and verify the accuracy of the measurement.

[0206] Example

[0207] like Figure 1 The liquid level detection technology roadmap shown comprehensively covers the entire process from data acquisition to result output, as detailed below:

[0208] (1) First, an experimental platform was built. A multi-light source collaborative system consisting of an HT-UBS502C industrial camera, a 10cm×15cm rectangular light source and a 2cm×14cm strip light source was used. The shooting distance was controlled at 20-50cm, the horizontal viewing angle was 0°-60° and the vertical tilt / level / elevation angle was controlled. 1180 original images were collected, covering the low liquid level area (7-11.5mm), the normal liquid level area (11.5-50.5mm) and the 32.5-35.5mm obstruction area of ​​the experimental bottle. At the same time, the actual liquid level height was recorded by measuring 4 times around 90° with an electronic vernier caliper and taking the average value.

[0209] (2) Data augmentation was performed on the original images, including rotating them 5° clockwise, adding 5° to the hue of the blue channel, reducing the saturation by 25, and reducing the brightness by 10. Gaussian and salt-and-pepper noise were added to generate a dataset of 1730 images, which were then divided into a training set (1384 images) and a validation set (346 images) in a 4:1 ratio.

[0210] (3) Next, visual model selection and optimization were carried out. After comparing 14 versions of YOLOv8 to YOLOv11, YOLOv8n was selected. GAM attention module (including channel and spatial attention sub-modules) was embedded in its backbone to enhance liquid level feature capture. WIOU v3 loss function was used to replace CIOU. The model was trained for 300 epochs with cosine annealing learning rate (initial 1e-4), so that the model's bottle body frame accuracy rate reached 99.35%, bottle cap frame accuracy rate reached 99.4%, and liquid level accuracy rate reached 99.01%, and the inference time was shortened to 2.2ms.

[0211] (4) Next, the model is improved to output the pixel coordinates of the positioning boxes (including the upper left and lower right corners) of the bottle body, bottle cap, and liquid level, and the positioning box area is subjected to differential image processing:

[0212] ① Liquid level: The cropped color image of the liquid level region is first converted to grayscale, and then local contrast is enhanced by contrast-limited adaptive histogram equalization (CLAHE). Salt-and-pepper noise is removed by 3×3 median filtering, and adaptive binarization is achieved by Otsu's algorithm. Holes in the region are filled by morphological closing operation of elliptical structuring elements, residual noise points are eliminated by screening based on the area threshold of connected regions, and finally, the complete liquid level contour is extracted by Canny edge detection.

[0213] ② Bottle: For the color image of the bottle area, first use CLAHE processing to suppress highlight overexposure and improve the contrast of low-light areas, then convert it to grayscale; use the Sobel operator to calculate the gradients in the horizontal and vertical directions to highlight edge details, and finally use Otsu's method for adaptive thresholding to generate a binary image of the bottle outline.

[0214] ③ Bottle cap: The color image of the bottle cap area is directly converted to grayscale, and then a 5×5 median filter is used to remove noise and smooth the texture. The contrast is enhanced by CLAHE to strengthen the edge features, and finally the complete outline of the bottle cap is extracted by Canny edge detection.

[0215] (5) Then calculate the height of the liquid level pixel, compare the height of the processed outline with the height of the original positioning box. If the relative deviation is ≤10%, the processed height is used; otherwise, the original height is used. Based on the actual height of the bottle body (72.5mm) and the bottle cap (17.5mm), calculate the correction parameter z and the conversion ratio true_conversion_ratio to obtain the actual height of the liquid level liquid_actual_height.

[0216] (6) Liquid level height fitting calculation: K-means clustering was performed on 300 sets of “pixel height - actual height” samples. The optimal k=3 (profile coefficient 0.575) was determined by the silhouette coefficient evaluation. It corresponds to 3 shooting parameter scenarios. The least squares method, ridge regression and Lasso regression were used to construct transformation equations for each cluster and the optimal equation for each cluster was selected. Among them, the Lasso regression equation (y=0.0499x-3.3043) of cluster 2 performed best (R²=0.950052).

[0217] (7) Dual-path experimental verification: The real-time detection path outputs the dynamic calibration result, and the cluster fitting path outputs the corresponding clustering equation result. The absolute difference between the two is calculated as ΔH. If ΔH≤0.6mm, the average value is output as the final result. Otherwise, the features are enhanced and the clustering is judged again to ensure that the measurement error is controlled within 0.6mm. The average detection time is 50ms, forming a complete closed loop.

[0218] Technical effect 1: Significantly improved model detection performance

[0219] The improved YOLOv8n+GAM+WIOU v3 model was comprehensively tested on 1730 datasets (covering scenarios with complex lighting, strong noise, and different liquid levels), and its performance is as follows:

[0220] (1) Target delineation accuracy:

[0221] The bottle body positioning pass rate reached 99.35%, and it can stably output complete bottle body positioning frames even when there are scratches on the container surface or the environment is unclear.

[0222] The pass rate for bottle cap positioning was 99.4%;

[0223] The liquid level identification pass rate is as high as 99.01%. Even in difficult detection scenarios such as low liquid level (liquid level height ≤ 11.5mm) and blurred liquid level edges (due to the formation of a meniscus by liquid surface tension and the obstruction of the opaque bottle body), it can still maintain an identification pass rate of over 98%, which is a qualitative leap compared to existing technologies.

[0224] Inference speed: The average inference time per image is only 2.2ms, which can meet the high-speed detection requirements of more than 450 frames per second. This is a comparison with existing models.

[0225] Table 4 Model Performance Comparison

[0226]

[0227] like Figure 3 As shown in the comparison data, it is clear that this patented model far surpasses existing models in terms of liquid level positioning accuracy, especially in challenging scenarios such as low liquid levels and strong noise, where its advantages are even more pronounced. Simultaneously, its inference speed is also at a leading level, achieving a breakthrough in balancing accuracy and speed.

[0228] Technical benefit 2: Measurement accuracy and efficiency meet industrial needs.

[0229] Thirty different samples were selected for measurement experiments. In the low liquid level area, the recognition error was relatively large, around 0.5 mm; in the normal liquid level area, the maximum recognition error was 0.45 mm, and the average error was 0.24 mm. Overall, the test accuracy in liquid level measurement was within 0.6 mm, the training and inference time based on the recognition and positioning data was within 3 ms, and the average time for liquid level height detection calculation was within 50 ms, achieving high-speed and accurate liquid level measurement.

[0230] Table 5 Experimental Results

[0231]

[0232] Example

[0233] Taking the measurement of the liquid level of transparent liquid in an opaque experimental bottle (72.5 mm high, with a 32.5–35.5 mm obstruction area) as an example,

[0234] Step 1: Experimental setup and image acquisition

[0235] An HT-UBS502C industrial camera (1280×720 resolution) is used, fixed at a distance of 30cm from the work platform (covering an area of ​​18cm×55mm); equipped with a 10cm×15cm rectangular light source (80% brightness) and a 2cm×14cm strip light source (focusing on the low liquid level area, 70% brightness), and the light is adjusted synchronously through the light source controller.

[0236] 4.2 ml of clear liquid was injected into the experimental bottle using a syringe with a precision of 0.2 ml. The liquid level was measured four times by circling 90° with an electronic vernier caliper and the average was taken. The actual liquid level height was 39.9 mm (within the normal liquid level range).

[0237] Take RGB images at a horizontal 0° angle and eye level to ensure that the entire bottle, cap, and liquid level line are included without any glare.

[0238] Step 2: Image preprocessing (noise reduction and normalization)

[0239] A 3×3 median filter was used to remove salt-and-pepper noise, and then a Gaussian filter was used to further eliminate high-frequency noise.

[0240] The image was cropped to 224×224 pixels (matching the YOLOv8n input size), retaining the core liquid level area and removing redundant background.

[0241] Step 3: YOLOv8n model recognition (including improvements to GAM+WIOU v3)

[0242] Load the YOLOv8n+GAM+WIOU v3 model trained on a dataset of 1730 images (training parameters: epoch=300, learning rate=1e-4).

[0243] The model outputs three types of bounding boxes:

[0244] ① Bottle body: top left corner (1180,512), bottom right corner (1475,1431), pixel height 919;

[0245] ② Bottle cap: top left corner (1179,512), bottom right corner (1475,734), pixel height 222;

[0246] ③ Liquid level: top left corner (1188,921), bottom right corner (1470,1429), pixel height 507 (this is the more accurate contour height after judgment processing);

[0247] The inference time was 2.2ms, and the liquid level frame accuracy rate was 99.8% (overlap with the actual frame was 98.3%).

[0248] Step 4: Enhancement of Liquid Level Features

[0249] The feature enhancement for the three types of targets detected by YOLO is based on the core logic of "noise reduction → contrast optimization → edge extraction", but differentiated feature enhancement is performed according to the differences in target characteristics.

[0250] Step 5: Liquid level calculation and error verification

[0251] By using a real-time calibration method based on dynamic conversion ratio, the correction parameter z = -1.45 is calculated to obtain the corrected bottle body pixel height. Substituting this into the calculation, the true conversion ratio is obtained as true_conversion_ratio = 12.6958, and the actual liquid level height is obtained as liquid_actual_height = 39.93.

[0252] The K-means algorithm (k=3, silhouette coefficient 0.575) was used to determine that the sample belonged to cluster 2 (R²=0.9517), and the corresponding Lasso regression equation was applied: y=0.0499x-3.3043. Substituting the enhanced liquid level pixel height of 507, the actual height was calculated to be 0.0499×507-3.3043=21.995mm.

[0253] The two algorithms yielded different results with an error greater than 0.6 mm, triggering a secondary verification mechanism: the feature enhancement was re-executed (CLAHE enhancement and edge refinement were performed on the liquid level area), and the sample clustering was re-determined. It was found that the original clustering determination was biased—the sample actually belonged to cluster 0 (corresponding to a low pixel height scene). The ridge regression equation of cluster 0 (y=0.0578x + 2.3018) should be called, and the actual height = 0.0578×507 + 2.3018 = 31.61 mm was calculated by substituting the pixel height of 507. After a second comparison of the two paths, the difference between the real-time detection path result of 39.93 mm and the result of the cluster 0 equation of 31.56 mm still exceeded the limit. Further, the historical measurement data of the sample for 5 frames (mean 39.88 mm) was retrieved, and it was determined that the real-time detection path result was closer to the historical trend. Finally, 39.93 mm was output as the valid result.

[0254] In actual verification, the difference between the measured value and the true value (39.9 mm) was 0.03 mm, which was within the 0.6 mm error threshold, thus verifying the effectiveness of the method.

[0255] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.

[0256] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.

Claims

1. A non-invasive liquid level measurement method based on an improved YOLO model, characterized in that, Includes the following steps: Step 1, Image Acquisition and Enhancement: Images under different conditions are acquired using an industrial camera and a collaborative light source, and then enhanced to generate a dataset; Step 2: Improve the YOLO model: Compare the YOLO series models, select YOLOv8n and introduce the GAM attention module and WIOUv3 loss function for optimization; Step 3, Image Post-processing and Feature Extraction: Denoise the image and perform differential feature enhancement on the bottle body, cap, and liquid level to extract clear contours; Step 4, Liquid level height calculation: Based on the improved YOLO positioning pixel height, combined with the "detection-enhancement-calibration-calculation" closed-loop dynamic compensation error, a real-time detection equation is established; Step 5, Liquid level height fitting: Use K-means to cluster the sample "pixel height - actual height" data into 3 classes, and combine the least squares method, ridge regression and Lasso regression to construct the transformation equation for each class; Step 6: Comparison and verification: By comparing the calculation results of the two paths through "real-time detection + cluster fitting", the error is ensured to be within the threshold, thus verifying the measurement accuracy.

2. The non-invasive liquid level measurement system and method based on the improved YOLO model according to claim 1, characterized in that, In step 1, an industrial camera is used to acquire original images under different liquid levels, viewing angles, and liquid colors to ensure that the complete bottle body, cap, and liquid level line are included. Data augmentation operations such as angle rotation, color correction, and noise addition are performed on the original images. The liquid level captured in the images covers low liquid level areas, normal liquid level areas, and areas obscured by the bottle body. The data-augmented dataset is divided into training and validation sets in a 4:1 ratio.

3. The non-invasive liquid level measurement system and method based on the improved YOLO model according to claim 1, characterized in that, In step 2, a GAM attention module is embedded in the YOLOv8n backbone to enhance the feature extraction capability of the liquid level region; The channel attention submodule of the GAM module transforms the input feature dimension into... After MLP processing, the dimensions are restored and channel attention weights are generated using sigmoid; the spatial attention submodule uses a 7×7 convolutional network to generate spatial attention weights, and the two types of weights are fused with the original feature tensor. Meanwhile, the WIoU v3 loss function is used instead of the original CIoU loss function of YOLOv8n, and the outlier degree of the anchor frame is calculated. Combining hyperparameters α, Constructing non-monotonic focusing coefficients To optimize the accuracy of bounding box regression, the formula is: in, It is the monotonic focusing coefficient; It is an exponential moving average with momentum m.

4. The non-invasive liquid level measurement system and method based on the improved YOLO model according to claim 1, characterized in that, In step 3, the image of the location bounding box region containing the bottle body, cap, and liquid level output by the YOLO model is post-processed to accurately extract features and provide pixel-level data. The specific processing is as follows: Liquid level: The color image of the liquid level area is converted to grayscale and contrast is enhanced using CLAHE; noise is removed by 3×3 median filtering and adaptive binarization using Otsu's algorithm; holes are filled by elliptical structuring element closing operation, noise points are eliminated by connected region area thresholding, and liquid level contours are extracted by Canny edge detection. Bottle body: The color image of the bottle body region is processed with CLAHE and then converted to grayscale; the Sobel operator calculates the gradient to highlight the edges, and Otsu's method is used for threshold segmentation to generate a binary image of the bottle body outline; Bottle cap: Convert the color image of the bottle cap area to grayscale, use 5×5 median filtering to remove noise; use CLAHE to enhance contrast, and use Canny edge detection to extract the bottle cap outline.

5. The non-invasive liquid level measurement system and method based on the improved YOLO model according to claim 1, characterized in that, In step 4, through a closed-loop design of "detection-enhancement-calibration-calculation," combined with dynamic compensation of shooting conditions using correction parameters, real-time liquid level height measurement is ultimately achieved, specifically as follows: Step 4-1: Improve YOLO pixel coordinate output: Improve the YOLO model to recognize the input image and output the pixel coordinates of the top left and bottom right corners of the bounding boxes for the three types of targets, thereby calculating the height of the original bounding boxes; Step 4-2, Differentiated Pixel Coordinate Output: Based on the three types of bounding boxes output by the improved YOLO, perform differentiated enhancement processing on each type and extract the processed pixel height: Step 4-3, Pixel height confirmation: The judgment condition is "the relative deviation between the processed height and the original positioning frame height is ≤10%". When the condition is met, the processed height is adopted. Otherwise, use the original bounding box pixel height; Step 4-4: Calculate the correction parameters and conversion ratio: Calculate the correction parameters... To compensate for the mapping deviation between "pixel height and actual height" caused by changes in shooting conditions, an accurate conversion coefficient between pixel height and actual height is obtained. The calculation formula is as follows: Conversion ratio in, The height of the bottle in pixels; This is the actual height of the bottle. The height of the bottle cap in pixels; This is the actual height of the bottle cap; Steps 4-5: Output actual liquid level height: in, The height of the liquid level pixel; Step 4-6, Real-time Detection Equation: Combining steps 4-1 to 4-5, a real-time detection equation is formed: Where N is the deviation term calculated by cross-referencing the pixel height of the bottle body and the bottle cap with the actual height, reflecting the mapping difference between the two caused by changes in shooting conditions; D is the actual height difference between the bottle body and the bottle cap, used to normalize the deviation term.

6. The non-invasive liquid level measurement system and method based on the improved YOLO model according to claim 1, characterized in that, In step 5, the specific process of clustering and fitting equation construction is as follows: through systematic data processing and model optimization, the problem of unstable "pixel height - actual height" mapping relationship caused by changes in shooting distance and focal length is solved: Step 5-1, Sample data preparation and preprocessing: Select 300 samples to form "pixel height - actual height" sample pairs, and standardize the data using StandardScaler; Step 5-2, K-means clustering algorithm implementation: Use K-means clustering, Euclidean distance, iterate 500 times or stop when the center change is less than 1e-4, calculate the silhouette coefficient s of each k value clustering result, and select the result with the highest silhouette coefficient. The calculation formula is: in, For the sample The average distance to other samples in the same cluster, For the sample The average distance to the nearest heterogeneous sample; the overall silhouette coefficient is the average distance to all samples. The mean of the clustering, with a value range of [-1, 1], indicates a better clustering effect as it is closer to 1; Step 5-3: Construction and Application of Fitting Equations: For each cluster sample, construct linear transformation equations using least squares, ridge regression, and Lasso regression respectively, and calculate... The optimal equation is selected based on the RMSE (root mean square error) to assess the fit. After 5-fold cross-validation, the corresponding equation is applied to new samples according to clustering.

7. The non-invasive liquid level measurement system and method based on the improved YOLO model according to claim 1, characterized in that, In step 6, two measured height values ​​are obtained by the "real-time detection and cluster fitting" dual-path comparison method proposed by the liquid level height fitting. This method not only uses dynamic correction parameters to adapt to changes in shooting conditions, but also ensures the reliability of the theoretical model based on the cluster fitting equation. The comparison of the two methods achieves dual verification of measurement accuracy. Step 6-1, Obtaining Dual-Path Results: Real-time detection path: Based on the real-time detection equation in step 4, output the actual liquid level height: ; Clustering Fitting Path: Based on the clustering analysis and fitting equation in step 5, the optimal fitting equation is output: Actual liquid level height: ; Step 6-2, Comparison and verification logic: Calculate the absolute difference between the results of the two paths: T=0.6mm; when When, output the final liquid level height: If an anomaly is detected, a secondary verification mechanism is triggered: Step 3 and clustering classification are re-executed. If the result still exceeds the limit, the result with a small deviation from the historical value is output and marked "to be manually verified".

8. A non-invasive liquid level measurement system based on an improved YOLO model, the system being based on any one of claims 1-7, characterized in that, include: Image acquisition and enhancement module; Images under different conditions are acquired using industrial cameras and collaborative light sources, and then processed through angle rotation, color correction, and enhancement to generate a dataset. YOLO model improvement module; compared with the YOLO series models, YOLOv8n was selected and the GAM attention module and WIOU v3 loss function were introduced for optimization. Liquid level fitting module; performs image noise reduction and differential feature enhancement for bottle body, cap, and liquid level, extracting clear contours; Image post-processing and feature extraction module: K-means is used to cluster the sample "pixel height - actual height" data into 3 classes, and the optimal regression of each cluster is combined to construct the transformation equation for each class; Liquid level height calculation module; based on the liquid level pixel height output by the improved YOLO, the actual height is calculated through two paths: real-time detection calibration and clustering equation; Comparison and verification module: Compare the calculation results of the two paths to ensure that the error is within the threshold and verify the accuracy of the measurement.