A hydraulic gauge reading method, device, equipment and medium
By constructing a hydraulic gauge image dataset with pre-defined anchor points and training a YOLO detection model, the problems of hydraulic gauge reading accuracy and adaptability were solved, achieving high-precision readings in complex environments and making it suitable for automatic hydraulic gauge readings in industrial settings.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- WINDEY ENERGY TECHNOLOGY GROUP CO LTD
- Filing Date
- 2026-03-06
- Publication Date
- 2026-06-09
AI Technical Summary
Existing automatic reading methods for hydraulic gauges suffer from insufficient positioning accuracy, poor adaptability, and weak ability to capture dial features, resulting in inaccurate readings.
We constructed a dataset of original hydraulic gauge images, labeled preset anchor points and trained a YOLO detection model. We accurately located physical boundary points through the feature vertex extraction matrix, used online data augmentation techniques to improve the model's generalization ability, and calculated the rotation angle ratio to obtain accurate readings.
It improves the accuracy and robustness of hydraulic gauge readings, enabling accurate readings in complex environments, reducing the impact of installation tilt and image rotation on readings, and meeting the precision monitoring needs of industrial sites.
Smart Images

Figure CN122176678A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method, apparatus, device, and medium for reading hydraulic gauges. Background Technology
[0002] Currently, hydraulic gauges are core instruments for monitoring pressure status in industrial production, energy extraction, and wind power operation and maintenance, and the accuracy of their readings directly affects the operational safety of equipment. In complex industrial environments, manual inspection and reading suffer from low efficiency and large subjective errors. Traditional reading methods mostly rely on computer vision libraries such as OpenCV (Open Source Computer Vision Library), using Hough Transform or piecewise binarization to extract pointers and scales. However, the complex industrial environment (uneven lighting, tilted dials, severe background interference) poses significant challenges to these methods in practical applications. With the development of computer vision technology in deep learning, automatic reading technology based on image recognition is gradually becoming the key to intelligent inspection.
[0003] Current methods for automatically reading hydraulic gauges have many limitations, including insufficient positioning accuracy, weak adaptability to different types of dials, and poor ability to capture dial features. To address these limitations, hydraulic gauge readings are often achieved by combining target detection algorithms with Hough lines or key point detection, but the accuracy and robustness remain to be considered.
[0004] In summary, improving the accuracy of hydraulic gauge readings is a pressing issue that needs to be addressed. Summary of the Invention
[0005] In view of this, the purpose of this invention is to provide a method, apparatus, device, and medium for reading hydraulic gauges, which can improve the accuracy of hydraulic gauge readings. The specific solution is as follows:
[0006] In a first aspect, this application discloses a method for reading a hydraulic gauge, including:
[0007] Construct a dataset of original hydraulic gauge images; each original hydraulic gauge image in the dataset is marked with a preset anchor point; the preset anchor point includes a preset zero-scale position located at the first preset corner of the zero-scale annotation box, a preset full-scale position located at the second preset corner of the full-scale annotation box, a preset pointer tip position located at the third preset corner of the pointer annotation box, and a preset pointer rotation center position located at the center of the pointer rotation center annotation box.
[0008] A YOLO detection model was trained using the original hydraulic gauge image dataset to obtain a hydraulic gauge reading detection model based on optimal weights;
[0009] The target hydraulic gauge image is processed using the hydraulic gauge reading detection model to obtain the target coordinates; the target coordinates include the target zero-scale coordinates, the target full-scale coordinates, the target pointer tip coordinates, and the target pointer rotation center coordinates;
[0010] The rotation angle ratio corresponding to the target angle is calculated based on the target coordinates, with the target pointer rotation center coordinates as the origin. The final hydraulic gauge value is obtained by multiplying the rotation angle ratio with the full-scale physical value of the hydraulic gauge. The target angle is the angle from zero scale to the pointer tip. The rotation angle ratio is the proportion of the target angle in the total rotation angle of the hydraulic gauge.
[0011] Optionally, training a YOLO detection model using the original hydraulic gauge image dataset to obtain a hydraulic gauge reading detection model based on optimal weights includes:
[0012] The original hydraulic gauge images in the original hydraulic gauge image dataset are randomly augmented using online data augmentation techniques in the YOLO detection model.
[0013] The YOLO detection model is trained using the data augmented image and based on preset rounds and preset batches to obtain a hydraulic gauge reading detection model.
[0014] Optionally, the step of calculating the rotation angle ratio corresponding to the target angle with the target pointer rotation center coordinate as the origin based on the target coordinates includes:
[0015] With the target pointer rotation center coordinate as the origin, calculate the zero-point absolute angle of the target zero-scale coordinate relative to the target pointer rotation center coordinate, calculate the full-scale absolute angle of the target full-scale coordinate relative to the target pointer rotation center coordinate, and calculate the pointer absolute angle of the target pointer tip coordinate relative to the target pointer rotation center coordinate;
[0016] Using the zero-point absolute angle as the reference angle, the full-scale absolute angle and the pointer absolute angle are normalized to obtain the total rotation angle and target angle of the hydraulic gauge.
[0017] The ratio of the target angle to the total rotation angle of the hydraulic gauge is calculated to obtain the rotation angle ratio corresponding to the target angle.
[0018] Optionally, when taking the target pointer rotation center coordinate as the origin, calculating the absolute zero-point angle of the target zero-scale coordinate relative to the target pointer rotation center coordinate, calculating the absolute full-scale angle of the target full-scale coordinate relative to the target pointer rotation center coordinate, and calculating the absolute pointer angle of the target pointer tip coordinate relative to the target pointer rotation center coordinate, includes:
[0019] A zero-point vector is constructed with the target pointer rotation center coordinates as the origin and based on the target zero-scale coordinates; a full-scale vector is constructed with the target pointer rotation center coordinates as the origin and based on the target full-scale coordinates; and a pointer vector is constructed with the target pointer rotation center coordinates as the origin and based on the target pointer tip coordinates.
[0020] Calculate the absolute zero angle between the zero point vector and the positive X-axis, the absolute full-scale angle between the full-scale vector and the positive X-axis, and the absolute pointer angle between the pointer vector and the positive X-axis.
[0021] Optionally, calculating the absolute zero angle between the zero-point vector and the positive X-axis, the absolute full-scale angle between the full-scale vector and the positive X-axis, and the absolute pointer angle between the pointer vector and the positive X-axis includes:
[0022] The absolute zero angle between the zero vector and the positive X-axis, the absolute full-scale angle between the full-scale vector and the positive X-axis, and the absolute pointer angle between the pointer vector and the positive X-axis are calculated using the two-parameter arctangent function.
[0023] Optionally, the step of processing the target hydraulic gauge image using the hydraulic gauge reading detection model to obtain the target coordinates includes:
[0024] The target hydraulic gauge image is processed using the hydraulic gauge reading detection model to determine the target zero-scale coordinates, target full-scale coordinates, and target pointer tip coordinates located at the corresponding detection frame corners, and to determine the coordinates of the four frame corners of the pointer rotation center detection frame;
[0025] The coordinates of the target pointer rotation center are calculated based on the four frame corner coordinates.
[0026] Optionally, the step of calculating the product of the rotation angle ratio and the full-scale physical value of the hydraulic gauge to obtain the final hydraulic gauge value includes:
[0027] The temporary hydraulic gauge value is obtained by multiplying the rotation angle ratio value by the full-scale physical value of the hydraulic gauge.
[0028] If the temporary hydraulic gauge value is within a preset value range, then the temporary hydraulic gauge value will be used as the final hydraulic gauge value; the preset value range is from zero to the full-scale physical value of the hydraulic gauge.
[0029] If the temporary hydraulic gauge value is not within the preset value range, the temporary hydraulic gauge value is processed using a truncation function to obtain the final hydraulic gauge value within the preset value range.
[0030] Secondly, this application discloses a hydraulic gauge reading device, comprising:
[0031] A dataset construction module is used to construct an original hydraulic gauge image dataset. Each original hydraulic gauge image in the original hydraulic gauge image dataset is marked with a preset anchor point. The preset anchor point includes a preset zero-scale position located at the first preset corner of the zero-scale annotation box, a preset full-scale position located at the second preset corner of the full-scale annotation box, a preset pointer tip position located at the third preset corner of the pointer annotation box, and a preset pointer rotation center position located at the center of the pointer rotation center annotation box.
[0032] The model training module is used to train the YOLO detection model using the original hydraulic gauge image dataset to obtain a hydraulic gauge reading detection model based on the optimal weights.
[0033] The image processing module is used to process the target hydraulic gauge image using the hydraulic gauge reading detection model to obtain the target coordinates; the target coordinates include the target zero-scale coordinates, the target full-scale coordinates, the target pointer tip coordinates, and the target pointer rotation center coordinates;
[0034] The hydraulic gauge reading module is used to calculate the rotation angle ratio corresponding to the target angle when the target pointer rotation center coordinate is taken as the origin, and to calculate the product of the rotation angle ratio and the full-scale physical value of the hydraulic gauge to obtain the final hydraulic gauge value; the target angle is the angle from zero scale to the pointer tip; the rotation angle ratio is the proportion of the target angle in the total rotation angle of the hydraulic gauge.
[0035] Thirdly, this application discloses an electronic device, including:
[0036] Memory, used to store computer programs;
[0037] A processor is configured to execute the computer program to implement the aforementioned disclosed method for reading hydraulic gauges.
[0038] Fourthly, this application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned hydraulic gauge reading method.
[0039] As can be seen, this application constructs a dataset of original hydraulic gauge images; each original hydraulic gauge image in the dataset is marked with a preset anchor point; the preset anchor point includes a preset zero-scale position at the first preset corner of the zero-scale annotation box, a preset full-scale position at the second preset corner of the full-scale annotation box, a preset pointer tip position at the third preset corner of the pointer annotation box, and a preset pointer rotation center position at the center of the pointer rotation center annotation box; a YOLO detection model is trained using the original hydraulic gauge image dataset to obtain a hydraulic gauge degree detection model based on optimal weights; the target hydraulic gauge image is processed using the hydraulic gauge degree detection model to obtain target coordinates; the target coordinates include target zero-scale coordinates, target full-scale coordinates, target pointer tip coordinates, and target pointer rotation center coordinates; the rotation angle ratio corresponding to the target angle with the target pointer rotation center coordinates as the origin is calculated based on the target coordinates, and the product of the rotation angle ratio and the full-scale physical value of the hydraulic gauge is calculated to obtain the final hydraulic gauge value; the target angle is the angle from zero scale to pointer tip; the rotation angle ratio is the proportion of the target angle in the total rotation angle of the hydraulic gauge. Therefore, this application intentionally marks the zero mark, full mark, and pointer tip at the corners of the annotation box when annotating the image. The subsequent model coordinate extraction can be directly obtained based on the corner coordinates without calculating the center point coordinates. This method accurately locks the physical boundary points to obtain coordinates for slender or small targets, eliminates the centroid offset caused by fluctuations in the size of the annotation box, and improves the accuracy of coordinate extraction. This application calculates the final hydraulic gauge value by rotating the angle ratio. At this time, even if there are problems such as installation tilt, overall image rotation, or camera shooting angle tilt, as long as these problems fall within the scope of rigid body rotation, the accuracy of the calculation results can be ensured. Attached Figure Description
[0040] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0041] Figure 1 This application discloses a flowchart of a method for reading a hydraulic gauge.
[0042] Figure 2 This is a schematic diagram of an image annotation for a hydraulic gauge disclosed in this application;
[0043] Figure 3 This is a specific illustration of the annotation disclosed in this application;
[0044] Figure 4This is a schematic diagram of the structure of a hydraulic gauge reading device disclosed in this application;
[0045] Figure 5 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation
[0046] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0047] Current methods for automatically reading hydraulic gauges have many limitations, including insufficient positioning accuracy, weak adaptability to different types of dials, and poor ability to capture dial features. To address these limitations, hydraulic gauge readings are often achieved by combining target detection algorithms with Hough lines or key point detection, but the accuracy and robustness remain to be considered.
[0048] Therefore, this application proposes a hydraulic gauge reading scheme that can improve the accuracy of hydraulic gauge readings.
[0049] This application discloses a method for reading a hydraulic gauge; see [link to relevant documentation]. Figure 1 As shown, the method includes:
[0050] Step S11: Construct the original hydraulic gauge image dataset; each original hydraulic gauge image in the original hydraulic gauge image dataset is marked with a preset anchor point; the preset anchor point includes a preset zero scale position located at the first preset corner of the zero scale annotation frame, a preset full scale position located at the second preset corner of the full scale annotation frame, a preset pointer tip position located at the third preset corner of the pointer annotation frame, and a preset pointer rotation center position located at the center of the pointer rotation center annotation frame.
[0051] In this embodiment, the hydraulic gauge image dataset is a high-precision labeled dataset based on specific physical characteristics. The labelme tool can be used to label the five key targets (dial, pointer, pointer center, zero mark, and full mark) with rectangular boxes.
[0052] It should be noted that when the first preset corner of the zero-scale annotation box is the upper right corner, the second preset corner of the full-scale annotation box is the upper left corner; when the first preset corner of the zero-scale annotation box is the lower left corner, the second preset corner of the full-scale annotation box is the lower right corner.
[0053] In one specific embodiment, in order to simulate the real physical scale position and reduce offset error, the preset anchor point logic in the annotation stage is as follows: For a zero-scale target, the upper right corner coordinate of the annotation box (located at the preset zero-scale position of the first preset corner of the zero-scale annotation box) is selected as the scale calculation anchor point to simulate the physical scale start position; for a full-scale target, the upper left corner coordinate of the annotation box (located at the preset full-scale position of the second preset corner of the full-scale annotation box) is selected as the calculation anchor point to simulate the physical scale end position; for a pointer, the upper left or upper right corner coordinate of the annotation box (located at the preset pointer tip position of the third preset corner of the pointer annotation box) is selected as the calculation anchor point to simulate the pointer tip on the physical feature.
[0054] See Figure 2 The image shown is a schematic diagram of a hydraulic gauge image annotation, with five annotation boxes labeled: dial, pointer, pointer center, zero mark, and full scale; see also... Figure 3 The diagram shows a specific annotation display. In Figure a, the upper right corner of the annotation box indicates the starting position of the physical scale. In Figure b, the upper left corner of the annotation box indicates the ending position of the physical scale.
[0055] It should be noted that existing deep learning methods typically use the center point of the bounding box directly for calculation. However, for slender pointers and scale lines, the center point is easily affected by annotation errors, leading to deviations in vector angle calculations and consequently, reading errors. This application does not directly use the center coordinates of the rectangular box output by the detection head for regression. Instead, it defines a set of feature vertex extraction matrices based on the physical orientation of different target categories. This logic aims to eliminate the positioning jitter of slender targets in complex backgrounds by utilizing the geometric coincidence between the boundary of the detection box and the tangent point of the dial scale. Compared to traditional methods that directly use the center point of the detection box for calculation, this application's unique feature anchor point selection can accurately lock the physical boundary points (such as the upper right or upper left corner) of slender and small targets such as pointer tips and zero-gradient starting lines. This strategy eliminates the centroid shift caused by fluctuations in the size of the bounding box, making the input data for geometric modeling more physically and statistically significant.
[0056] It should be noted that not only can the corners of the frame be used as the starting or ending positions of the physical scale, but any point on the line connecting the corners of a single annotation frame can also be used as the corresponding position, provided that the two corresponding positions between the two annotation frames are aligned. For example, the upper right corner of the zero-scale annotation frame corresponds to the upper left corner of the full-scale annotation frame; the lower left corner of the zero-scale annotation frame corresponds to the lower right corner of the full-scale annotation frame. Therefore, these can be used as the corresponding starting and ending positions of the physical scale. Since the aforementioned corners are aligned, the first line connecting the upper right and lower left corners of the zero-scale annotation frame and the second line connecting the upper left and lower right corners of the full-scale annotation frame also correspond. The points on these lines correspond sequentially, so the corresponding points on the first and second lines can be used as the starting or ending positions of the physical scale, respectively. It should be noted that the coordinates of the points on these lines can be calculated from the coordinates of the frame corners.
[0057] Step S12: Train the YOLO detection model using the original hydraulic gauge image dataset to obtain a hydraulic gauge reading detection model based on the optimal weights.
[0058] It should be noted that the label format of the dataset labeled by labelme is JSON (JavaScript Object Notation). For the YOLO (You Only Look Once) model, the labels of the dataset should be in txt format. Therefore, the labels need to be converted by code after the labeling is completed.
[0059] It should be noted that during the training process, the dataset is divided into training set, validation set and test set in a ratio of 7:1:2.
[0060] In this embodiment, training the YOLO detection model using the original hydraulic gauge image dataset to obtain a hydraulic gauge reading detection model based on optimal weights includes: randomly performing data augmentation operations on the original hydraulic gauge images in the original hydraulic gauge image dataset using online data augmentation techniques in the YOLO detection model; and training the YOLO detection model using the data-augmented images and based on a preset number of rounds and a preset batch to obtain the hydraulic gauge reading detection model.
[0061] It should be noted that YOLO11 (or other YOLO series versions; this method is based on YOLO11) is used as the basic detection framework. No image preprocessing is introduced; instead, the online data augmentation technology of the YOLO model itself is utilized to randomly perform operations such as optical distortion, cropping, and horizontal flipping during training, improving the model's generalization ability to complex backgrounds. The number of rounds is set to 300, the batch size to 16, and the input image size is uniformly adjusted to 640×640 pixels for model training.
[0062] It should be noted that traditional image preprocessing methods (such as grayscale conversion, binarization, edge detection, etc.) often rely on specific parameters. Since the background environment of each image is different, a single preprocessing operator often fails to address all aspects, resulting in the originally clear image becoming blurry after processing. However, this application does not require cumbersome image binarization, denoising, or edge detection preprocessing. Relying on the powerful online data augmentation capabilities of YOLO11, it achieves a fully automatic closed loop from the original image input to the result output, which greatly reduces the difficulty of transferring the algorithm to different devices and improves the system's survival rate in harsh lighting environments.
[0063] It should be noted that when the dial contains two rings of different unit scales, the traditional annotation method makes it difficult for the model to effectively capture the features of the 0-scale and full-scale due to the small pixel ratio of the scale lines, easily leading to missed detections. This application achieves extremely high accuracy in the detection stage, as shown in Table 1 below based on experimental data. After 300 training rounds, the model's average detection accuracy mAP50(B) (mean Average Precision at IoU 0.5 (Bounding Box)) for each target reached 0.995, close to the theoretical peak. In several (e.g., 22) complex images in the actual test set, 90.9% of the recognition results were within the extremely low error range (0-3 measurement units), with 54.5% of the readings completely consistent with manual verification. This level of accuracy is similar to the visual error of manual inspection, meeting the needs of precise monitoring in industrial settings. Here, Bounding Box represents the bounding box, and mAP50 represents the target detection accuracy when the IoU (Intersection over Union) is 0.5.
[0064] Table 1
[0065]
[0066] Step S13: Process the target hydraulic gauge image using the hydraulic gauge reading detection model to obtain the target coordinates; the target coordinates include the target zero scale coordinates, the target full scale coordinates, the target pointer tip coordinates, and the target pointer rotation center coordinates.
[0067] In this embodiment, the step of processing the target hydraulic gauge image using the hydraulic gauge degree detection model to obtain the target coordinates includes: processing the target hydraulic gauge image using the hydraulic gauge degree detection model to determine the target zero-scale coordinates, target full-scale coordinates, and target pointer tip coordinates located at the corresponding detection frame corners, and determining the coordinates of the four frame corners of the pointer rotation center detection frame; and calculating the target pointer rotation center coordinates based on the four frame corner coordinates.
[0068] It should be noted that this application uses the hydraulic gauge reading detection model with the best weight in the training results (best.pt) to infer and predict the image to be detected, and outputs the prediction results of all targets in parallel. This includes the following steps: 1. Traversing the detection result tensor (the content corresponding to each detection box) Boxes( , , , The tensor is converted into a NumPy array on the CPU (Central Processing Unit). Here, `conf` represents the confidence level, and `class_id` represents a unique numerical identifier. 2. Based on the class mapping, select the feature vertex with the highest overlap with the physical meaning from the four vertices of the predicted bounding box: Zero-scale anchor point 0_top_right: Extract the coordinates of the top-right corner of its predicted bounding box (…). , ); Full-scale anchor point max_top_left: Extracts the coordinates of the top left corner of its prediction box ( , ); pointer tip anchor point needle_top_left: Based on the physical characteristics of the pointer within the measurement range, extract the coordinates of the upper left corner of the prediction box ( , ); pointer center_center: calculates the coordinates of the center point based on the predicted bounding box coordinates (( + ) / 2, ( + ) / 2). 3. Map the extracted coordinate data to structured data in .txt format and save it, while simultaneously performing visual annotation output in conjunction with the original image.
[0069] Step S14: Calculate the rotation angle ratio corresponding to the target angle when the target pointer rotation center coordinate is taken as the origin, based on the target coordinates, and calculate the product of the rotation angle ratio and the full-scale physical value of the hydraulic gauge to obtain the final hydraulic gauge value; the target angle is the angle from zero scale to the pointer tip; the rotation angle ratio is the proportion of the target angle in the total rotation angle of the hydraulic gauge.
[0070] In this embodiment, the step of calculating the rotation angle ratio corresponding to the target angle with the target pointer rotation center coordinate as the origin, based on the target coordinates, includes: calculating the zero-point absolute angle of the target zero-scale coordinate relative to the target pointer rotation center coordinate when the target pointer rotation center coordinate is taken as the origin; calculating the full-scale absolute angle of the target full-scale coordinate relative to the target pointer rotation center coordinate; calculating the pointer absolute angle of the target pointer tip coordinate relative to the target pointer rotation center coordinate; using the zero-point absolute angle as the reference angle, performing angle normalization processing on the full-scale absolute angle and the pointer absolute angle respectively to obtain the total rotation angle and the target angle of the hydraulic gauge; and calculating the ratio of the target angle to the total rotation angle of the hydraulic gauge to obtain the rotation angle ratio corresponding to the target angle.
[0071] In this embodiment, when the target pointer rotation center coordinates are taken as the origin, the calculation of the absolute zero-point angle of the target zero-scale coordinates relative to the target pointer rotation center coordinates, the calculation of the absolute full-scale angle of the target full-scale coordinates relative to the target pointer rotation center coordinates, and the calculation of the absolute pointer angle of the target pointer tip coordinates relative to the target pointer rotation center coordinates include: constructing a zero-point vector based on the target zero-scale coordinates, constructing a full-scale vector based on the target full-scale coordinates, and constructing a pointer vector based on the target pointer rotation center coordinates; calculating the absolute zero-point angle between the zero-point vector and the positive X-axis direction, the absolute full-scale angle between the full-scale vector and the positive X-axis direction, and the absolute pointer angle between the pointer vector and the positive X-axis direction.
[0072] In this embodiment, calculating the absolute zero angle between the zero point vector and the positive X-axis, the absolute full-scale angle between the full-scale vector and the positive X-axis, and the absolute pointer angle between the pointer vector and the positive X-axis includes: using a two-parameter arctangent function to calculate the absolute zero angle between the zero point vector and the positive X-axis, the absolute full-scale angle between the full-scale vector and the positive X-axis, and the absolute pointer angle between the pointer vector and the positive X-axis.
[0073] In one specific embodiment, based on the target coordinates obtained in step S14, the detected zero, full-scale, and pointer positions are uniformly converted into vector representations with the center of the dial (the coordinates of the target pointer rotation center) as the origin. The polar angle is calculated using atan2, and then normalized using the zero point direction as the angle reference to obtain the relative angle of the pointer within the dial scanning range. The angle and its proportion are then calculated, and the dial reading result is obtained. The specific process is as follows: 1. Define the zero scale of each coordinate point. (0_top_right), full scale (max_top_left), the tip of the pointer (needle_top_left), pointer center (center_center); 2. Construct a vector with the pointer center as the origin: zero-point vector. = - Full-scale vector = - pointer vector = - 3. Calculate the absolute angles of the three vectors relative to the center point using atan2 (arc tangent of two variables). , , The returned result is in radians; 4. According to the formula (angle- )%(2 (where % represents the modulo operation (remainder), the core function of which is to limit the angle difference to [0, 2).) Angle normalization is performed within the range of ) to Establish a new 0-radian baseline and convert the angle calculation results to [0, 2]. Within the range, obtain angle 1 (the angle from zero to the pointer) and angle 2 (the total angle from zero to full scale); 5. Calculate the rotation angle ratio of the pointer relative to zero.
[0074] In this embodiment, the step of calculating the product of the rotation angle ratio value and the full-scale physical value of the hydraulic gauge to obtain the final hydraulic gauge value includes: calculating the product of the rotation angle ratio value and the full-scale physical value of the hydraulic gauge to obtain a temporary hydraulic gauge value; if the temporary hydraulic gauge value is within a preset value range, then the temporary hydraulic gauge value is used as the final hydraulic gauge value; the preset value range is from zero to the full-scale physical value of the hydraulic gauge; if the temporary hydraulic gauge value is not within the preset value range, then the temporary hydraulic gauge value is processed using a truncation function to obtain a final hydraulic gauge value within the preset value range.
[0075] It should be noted that this application dynamically loads the full-scale physical value full_scale by combining the preset dial unit parameters (MPa or psi), calculates the final reading based on the obtained ratio (rotation angle ratio) and the formula reading=ratio×full_scale, and strictly limits the output result to the range [0, full_scale] through the clip (truncation function) mechanism to prevent readings from going out of bounds due to image edge distortion or other reasons.
[0076] It should be noted that this application constructs three sets of correlation vectors through extracted feature points: zero-position vector. Full-scale vector and pointer vector A relative angle adaptive algorithm is constructed based on the atan2 function. This algorithm automatically cancels out interference from rigid body rotation of the dial by calculating the projection ratio of the pointer vector in the zero-to-full position vector space. Any technical logic that achieves adaptive reading by calculating relative angles rather than absolute coordinates falls within the scope of this protection. Furthermore, this application utilizes a vector angle calculation model that possesses rotation invariance. By establishing a relative coordinate system with the dial center as the origin, even if the dial is tilted during installation, the overall image is rotated, or the camera shooting angle is skewed, as long as it falls within the scope of rigid body rotation, the relative angle ratio remains constant. This effectively solves the problem of reading deviation caused by non-standard instrument installation in industrial scenarios.
[0077] It should be noted that, in order to address potential image distortion or detection fluctuations in industrial readings, this application introduces a constraint algorithm based on physical range. The c1ip function processing logic introduced at the end of the geometric calculation, that is, based on the user-preset full_scale unit parameter, forcibly truncates and corrects the output reading within the range of [0, full_scale], ensuring that the system will not output abnormal values that violate physical common sense under extreme operating conditions.
[0078] As can be seen, this application constructs a dataset of original hydraulic gauge images; each original hydraulic gauge image in the dataset is marked with a preset anchor point; the preset anchor point includes a preset zero-scale position at the first preset corner of the zero-scale annotation box, a preset full-scale position at the second preset corner of the full-scale annotation box, a preset pointer tip position at the third preset corner of the pointer annotation box, and a preset pointer rotation center position at the center of the pointer rotation center annotation box; a YOLO detection model is trained using the original hydraulic gauge image dataset to obtain a hydraulic gauge degree detection model based on optimal weights; the target hydraulic gauge image is processed using the hydraulic gauge degree detection model to obtain target coordinates; the target coordinates include target zero-scale coordinates, target full-scale coordinates, target pointer tip coordinates, and target pointer rotation center coordinates; the rotation angle ratio corresponding to the target angle with the target pointer rotation center coordinates as the origin is calculated based on the target coordinates, and the product of the rotation angle ratio and the full-scale physical value of the hydraulic gauge is calculated to obtain the final hydraulic gauge value; the target angle is the angle from zero scale to pointer tip; the rotation angle ratio is the proportion of the target angle in the total rotation angle of the hydraulic gauge. Therefore, this application intentionally marks the zero mark, full mark, and pointer tip at the corners of the annotation box when annotating the image. Subsequent model coordinate extraction can be directly based on these corner coordinates, eliminating the need to calculate the center point coordinates. This method accurately locks the physical boundary points of slender or small targets to obtain their coordinates, eliminating centroid shift caused by fluctuations in the size of the annotation box and improving the accuracy of coordinate extraction. This application calculates the final hydraulic gauge value using a rotation angle ratio. Even with installation tilt, overall image rotation, or camera angle tilt, as long as these issues fall within the scope of rigid body rotation, the accuracy of the calculation results can be ensured. Furthermore, this application strictly limits the output results to a predetermined range using a truncation function, preventing readings from exceeding the limits due to image edge distortion or other reasons.
[0079] Accordingly, this application also discloses a hydraulic gauge reading device, see [link to relevant documentation]. Figure 4 As shown, the device includes:
[0080] The dataset construction module 11 is used to construct the original hydraulic gauge image dataset; each original hydraulic gauge image in the original hydraulic gauge image dataset is marked with a preset anchor point; the preset anchor point includes a preset zero scale position located at the first preset corner of the zero scale annotation box, a preset full scale position located at the second preset corner of the full scale annotation box, a preset pointer tip position located at the third preset corner of the pointer annotation box, and a preset pointer rotation center position located at the center of the pointer rotation center annotation box;
[0081] Model training module 12 is used to train a YOLO detection model using the original hydraulic gauge image dataset to obtain a hydraulic gauge reading detection model based on the optimal weights.
[0082] Image processing module 13 is used to process the target hydraulic gauge image using the hydraulic gauge reading detection model to obtain target coordinates; the target coordinates include target zero scale coordinates, target full scale coordinates, target pointer tip coordinates, and target pointer rotation center coordinates;
[0083] The hydraulic gauge reading module 14 is used to calculate the rotation angle ratio corresponding to the target angle when the target pointer rotation center coordinate is taken as the origin, and calculate the product of the rotation angle ratio and the full-scale physical value of the hydraulic gauge to obtain the final hydraulic gauge value; the target angle is the angle from zero scale to the pointer tip; the rotation angle ratio is the proportion of the target angle in the total rotation angle of the hydraulic gauge.
[0084] The more specific working process of each of the above modules can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.
[0085] As can be seen, this application constructs a dataset of original hydraulic gauge images; each original hydraulic gauge image in the dataset is marked with a preset anchor point; the preset anchor point includes a preset zero-scale position at the first preset corner of the zero-scale annotation box, a preset full-scale position at the second preset corner of the full-scale annotation box, a preset pointer tip position at the third preset corner of the pointer annotation box, and a preset pointer rotation center position at the center of the pointer rotation center annotation box; a YOLO detection model is trained using the original hydraulic gauge image dataset to obtain a hydraulic gauge degree detection model based on optimal weights; the target hydraulic gauge image is processed using the hydraulic gauge degree detection model to obtain target coordinates; the target coordinates include target zero-scale coordinates, target full-scale coordinates, target pointer tip coordinates, and target pointer rotation center coordinates; the rotation angle ratio corresponding to the target angle with the target pointer rotation center coordinates as the origin is calculated based on the target coordinates, and the product of the rotation angle ratio and the full-scale physical value of the hydraulic gauge is calculated to obtain the final hydraulic gauge value; the target angle is the angle from zero scale to pointer tip; the rotation angle ratio is the proportion of the target angle in the total rotation angle of the hydraulic gauge. Therefore, this application intentionally marks the zero mark, full mark, and pointer tip at the corners of the annotation box when annotating the image. The subsequent model coordinate extraction can be directly obtained based on the corner coordinates without calculating the center point coordinates. This method accurately locks the physical boundary points to obtain coordinates for slender or small targets, eliminates the centroid offset caused by fluctuations in the size of the annotation box, and improves the accuracy of coordinate extraction. This application calculates the final hydraulic gauge value by rotating the angle ratio. At this time, even if there are problems such as installation tilt, overall image rotation, or camera shooting angle tilt, as long as these problems fall within the scope of rigid body rotation, the accuracy of the calculation results can be ensured.
[0086] Furthermore, embodiments of this application also provide an electronic device. Figure 5 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.
[0087] Figure 5 This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. Specifically, the electronic device 20 may include: at least one processor 21, at least one memory 22, a display screen 23, an input / output interface 24, a communication interface 25, a power supply 26, and a communication bus 27. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the hydraulic gauge reading method disclosed in any of the foregoing embodiments. Alternatively, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0088] In this embodiment, the power supply 26 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 25 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 24 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0089] Furthermore, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk, or optical disk, etc. The resources stored thereon may include computer programs 221, and the storage method may be temporary storage or permanent storage. In addition to including a computer program capable of performing the hydraulic gauge reading method executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 221 may further include computer programs capable of performing other specific tasks.
[0090] Furthermore, embodiments of this application also disclose a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned hydraulic gauge reading method.
[0091] The specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.
[0092] The various embodiments in this application are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. For the same or similar parts between the various embodiments, refer to each other. As for the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple, and relevant parts can be referred to in the method section.
[0093] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0094] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0095] Finally, it should be noted that in this document, relational terms such as "first" and "first" 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 a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0096] The above provides a detailed description of a hydraulic gauge reading method, apparatus, device, and storage medium provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A method of reading a hydraulic gauge, characterized in that, include: Construct the original hydraulic gauge image dataset; Each original hydraulic gauge image in the original hydraulic gauge image dataset is marked with a preset anchor point; The preset anchor points include a preset zero-scale position located at the first preset corner of the zero-scale annotation frame, a preset full-scale position located at the second preset corner of the full-scale annotation frame, a preset pointer tip position located at the third preset corner of the pointer annotation frame, and a preset pointer rotation center position located at the center of the pointer rotation center annotation frame. A YOLO detection model was trained using the original hydraulic gauge image dataset to obtain a hydraulic gauge reading detection model based on optimal weights; The target hydraulic gauge image is processed using the hydraulic gauge reading detection model to obtain the target coordinates; the target coordinates include the target zero-scale coordinates, the target full-scale coordinates, the target pointer tip coordinates, and the target pointer rotation center coordinates; The rotation angle ratio corresponding to the target angle is calculated based on the target coordinates, with the target pointer rotation center coordinates as the origin. The final hydraulic gauge value is obtained by multiplying the rotation angle ratio with the full-scale physical value of the hydraulic gauge. The target angle is the angle from zero scale to the pointer tip. The rotation angle ratio is the proportion of the target angle in the total rotation angle of the hydraulic gauge.
2. The hydraulic gauge reading method of claim 1, wherein, The process of training a YOLO detection model using the original hydraulic gauge image dataset to obtain a hydraulic gauge reading detection model based on optimal weights includes: The original hydraulic gauge images in the original hydraulic gauge image dataset are randomly augmented using online data augmentation techniques in the YOLO detection model. The YOLO detection model is trained using the data augmented image and based on preset rounds and preset batches to obtain a hydraulic gauge reading detection model.
3. The hydraulic gauge reading method of claim 1, wherein, The step of calculating the rotation angle ratio corresponding to the target angle with the target pointer rotation center coordinate as the origin based on the target coordinates includes: With the target pointer rotation center coordinate as the origin, calculate the zero-point absolute angle of the target zero-scale coordinate relative to the target pointer rotation center coordinate, calculate the full-scale absolute angle of the target full-scale coordinate relative to the target pointer rotation center coordinate, and calculate the pointer absolute angle of the target pointer tip coordinate relative to the target pointer rotation center coordinate; Using the zero-point absolute angle as the reference angle, the full-scale absolute angle and the pointer absolute angle are normalized to obtain the total rotation angle and target angle of the hydraulic gauge. The ratio of the target angle to the total rotation angle of the hydraulic gauge is calculated to obtain the rotation angle ratio corresponding to the target angle.
4. The hydraulic gauge reading method according to claim 3, characterized in that, When the target pointer rotation center coordinate is taken as the origin, the calculation includes: the absolute angle of the target zero-scale coordinate relative to the target pointer rotation center coordinate; the absolute angle of the target full-scale coordinate relative to the target pointer rotation center coordinate; and the absolute angle of the target pointer tip coordinate relative to the target pointer rotation center coordinate. A zero-point vector is constructed with the target pointer rotation center coordinates as the origin and based on the target zero-scale coordinates; a full-scale vector is constructed with the target pointer rotation center coordinates as the origin and based on the target full-scale coordinates; and a pointer vector is constructed with the target pointer rotation center coordinates as the origin and based on the target pointer tip coordinates. Calculate the absolute zero angle between the zero point vector and the positive X-axis, the absolute full-scale angle between the full-scale vector and the positive X-axis, and the absolute pointer angle between the pointer vector and the positive X-axis.
5. The hydraulic gauge reading method according to claim 4, characterized in that, The calculation of the absolute zero-point angle between the zero-point vector and the positive X-axis, the absolute full-scale angle between the full-scale vector and the positive X-axis, and the absolute pointer angle between the pointer vector and the positive X-axis includes: The absolute zero angle between the zero vector and the positive X-axis, the absolute full-scale angle between the full-scale vector and the positive X-axis, and the absolute pointer angle between the pointer vector and the positive X-axis are calculated using the two-parameter arctangent function.
6. The hydraulic gauge reading method according to claim 1, characterized in that, The process of processing the target hydraulic gauge image using the hydraulic gauge reading detection model to obtain the target coordinates includes: The target hydraulic gauge image is processed using the hydraulic gauge reading detection model to determine the target zero-scale coordinates, target full-scale coordinates, and target pointer tip coordinates located at the corresponding detection frame corners, and to determine the coordinates of the four frame corners of the pointer rotation center detection frame; The coordinates of the target pointer rotation center are calculated based on the four frame corner coordinates.
7. The method for reading a hydraulic gauge according to any one of claims 1 to 6, characterized in that, The calculation of the product of the rotation angle ratio value and the full-scale physical value of the hydraulic gauge to obtain the final hydraulic gauge value includes: The temporary hydraulic gauge value is obtained by multiplying the rotation angle ratio value by the full-scale physical value of the hydraulic gauge. If the temporary hydraulic gauge value is within a preset value range, then the temporary hydraulic gauge value will be used as the final hydraulic gauge value; the preset value range is from zero to the full-scale physical value of the hydraulic gauge. If the temporary hydraulic gauge value is not within the preset value range, the temporary hydraulic gauge value is processed using a truncation function to obtain the final hydraulic gauge value within the preset value range.
8. A hydraulic gauge reading device, characterized in that, include: The dataset construction module is used to construct the original hydraulic gauge image dataset; Each original hydraulic gauge image in the original hydraulic gauge image dataset is marked with a preset anchor point; The preset anchor points include a preset zero-scale position located at the first preset corner of the zero-scale annotation frame, a preset full-scale position located at the second preset corner of the full-scale annotation frame, a preset pointer tip position located at the third preset corner of the pointer annotation frame, and a preset pointer rotation center position located at the center of the pointer rotation center annotation frame. The model training module is used to train the YOLO detection model using the original hydraulic gauge image dataset to obtain a hydraulic gauge reading detection model based on the optimal weights. The image processing module is used to process the target hydraulic gauge image using the hydraulic gauge reading detection model to obtain the target coordinates; the target coordinates include the target zero-scale coordinates, the target full-scale coordinates, the target pointer tip coordinates, and the target pointer rotation center coordinates; The hydraulic gauge reading module is used to calculate the rotation angle ratio corresponding to the target angle when the target pointer rotation center coordinate is taken as the origin, and to calculate the product of the rotation angle ratio and the full-scale physical value of the hydraulic gauge to obtain the final hydraulic gauge value; the target angle is the angle from zero scale to the pointer tip; the rotation angle ratio is the proportion of the target angle in the total rotation angle of the hydraulic gauge.
9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the hydraulic gauge reading method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, Used to store a computer program; wherein, when the computer program is executed by a processor, it implements the hydraulic gauge reading method as described in any one of claims 1 to 7.