A machine vision-based reading method for nested non-uniform scale dials
By combining the improved Hough transform and regression method with the true scale extraction algorithm, the reading problem of nested non-uniform scale dials is solved, and efficient and accurate dial reading is achieved, which is suitable for industrial automation scenarios.
Patent Information
- Application Number
- CN202411246015.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-06
- Publication Date
- 2025-10-10
- Estimated Expiration
- 2044-09-06
AI Technical Summary
Existing machine vision meter reading methods have weak robustness in dealing with light interference, nested dials and uneven scales, making it difficult to meet the reading needs of industrial automation, especially in substations, where they are inefficient and have low accuracy.
An improved Hough transform algorithm is combined with the regression method and the true scale extraction algorithm. The center of the circle is located through arc segment tracking and circle gradient. The distance method is combined to calculate the dial reading. The improved YOLOv5 network is used for instrument detection and scale line fitting, which reduces hardware requirements and improves computational efficiency.
It achieves high-precision readings on nested non-uniform scale dials, improves reading efficiency, reduces hardware requirements, and is suitable for real-time readings of lightweight equipment.
Smart Images

Figure CN119152488B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of machine vision, in particular to a nested non-uniform scale dial reading method based on machine vision. Background Art
[0002] Machine vision, with its efficient and precise features, has played a significant role in the digitalization of industrial production. Specifically, machine vision-based meter reading methods have proven effective in identifying pointer-type circular dials, addressing the numerous dials in substations, resulting in low manual reading efficiency and high false positive rates. However, mainstream dial reading methods have significant limitations, lacking robustness in situations with lighting interference, a large number of dials, and uneven scales, making them difficult to handle in more complex environments. Therefore, designing a machine reading method that can withstand external interference, nested large and small dials, and uneven scales is of great significance to the development of industrial automation.
[0003] In recent years, many scholars have conducted extensive research in the field of machine vision:
[0004] Glenn Jocher proposed the YOLOv5 network, which demonstrates powerful capabilities in image classification and localization. Its derivatives include n, s, m, l, and x, with the number of network parameters increasing from left to right. The lightweight YOLOv5s has fewer parameters, but its bounding box regression is less precise. YOLOv5l offers high object recognition and localization accuracy, but requires high hardware requirements, consumes large amounts of memory, and runs slowly.
[0005] Zhang Jin's academic paper, "An Improved YOLOv5-Based Safety Helmet Wearing Detection Algorithm," uses the K-Means++ algorithm to redesign the prior box size and match it to the corresponding feature layer. This paper also introduces a multispectral channel attention module into the feature extraction network, enabling the network to autonomously learn the weights of each channel, enhancing information propagation between features and thus strengthening the network's ability to distinguish foreground from background. However, this method has a large number of parameters, which slows down meter reading and makes it difficult to meet the heavy reading workload of substations.
[0006] Patent application CN112257676A determines the maximum angle of the pointer when it is at the zero scale line and the maximum range, as well as the deflection angle of the dial from the current position to the zero scale line. Based on the principle that the change in the reading of a dial with uniform scale is proportional to the pointer deflection angle, the method combines the range and the proportion of the deflection angle to the maximum angle to read the number pointed by the pointer. This method is simple and fast, but it cannot handle dials with uneven scales.
[0007] Wang Tuo's academic paper, "Research Based on an Improved Hough Transform Algorithm," proposes an algorithm based on a lookup table and a bit accumulator. This algorithm leverages the directional information of perpendicular lines at the circle's boundary points to quickly and accurately detect and measure circular objects, while also overcoming the computational complexity and memory consumption of the Hough transform. However, this method is only applicable to relatively regular, complete circles and is less suitable for finding circles in the presence of occlusion and missing pixels.
[0008] Yang Shiqi's academic paper, "Automatic Reading Method for Pointer Instruments Based on Deep Learning," combines average intersection-over-union (IoU) and morphological erosion methods to effectively extract scale outlines through model training. This opens up new avenues for exploring the processing of small dials and target refinement.
[0009] Although the pointer meter reading method based on machine vision has made some progress in recent years in terms of area positioning and target pixel extraction, it still has the following shortcomings:
[0010] 1. There are two representative methods for the circle detection problem. The circular Hough transform based on the entire circle regards the binary coordinates of the edge points of the circle contour as parameters, and the binary coordinates and radius of the target circle to be measured as three-dimensional vectors. The solution vector is obtained by finding the intersection of the conical surfaces with multiple parameters as vertices. This method is highly robust and not easily affected by incomplete data; however, the computational complexity and accumulator data structure of this method will increase exponentially with the increase in curve parameters. The RCD algorithm based on discrete points randomly selects three non-collinear points from the edge image to form a circle, and determines whether it is a true circle based on the ratio of the accumulated pixel points on the candidate circle to the circumference. This method takes up little memory, but it is easy to introduce a large number of invalid samples, which seriously reduces the calculation speed.
[0011] 2. A common method for line detection is the Hough transform. This method is robust and highly resistant to interference. It is insensitive to missing parts of a line in an image and coexisting non-linear components, and can detect multiple lines in a single image. However, the Hough transform has high spatial complexity, resulting in low algorithm efficiency and high memory usage. Furthermore, its detection accuracy is limited by parameters. The pointers of the subdials in different nested dials have different aspect ratios, making it difficult to fit a line using the same set of Hough transform parameters. Manual parameter adjustment cannot meet the requirements of automated inspection.
[0012] 3. Conventional instrument automatic reading schemes typically don't rely on the relationship between the pointer and the scale. Therefore, most methods only extract a portion of the scale outline, ignoring some minor scale lines. However, for dials with uneven scales, extracting only the primary scale outline will severely impair reading accuracy. Furthermore, most scale extraction methods use Canny edge detection to obtain the outline, then use the intersection-of-union ratio of overlapping outlines to filter out the true scale. Small dials nested within larger instruments have densely packed scale lines, and the scale fitting rectangles have a high overlap rate and are extremely close together. Using the intersection-of-union ratio as a screening metric makes it difficult to effectively remove redundant rectangles.
[0013] 4. Most instrument reading methods use the angle method, which calculates the instrument reading by multiplying the range by the ratio of the deflection angle between the pointer and the zero scale line to the angle between the maximum scale fitting line and the zero scale line. However, the angle method, based on the principle that the length of the arc drawn by the pointer is proportional to the deflection angle, has limited applicability and cannot handle instruments with uneven scales. Summary of the Invention
[0014] In order to address the shortcomings of the above-mentioned existing technologies, the present invention proposes a nested non-uniform scale dial reading method based on machine vision, so as to improve reading efficiency and reduce the required hardware conditions while ensuring the reading accuracy, so that it can be widely used in real-time reading work scenarios relying on lightweight equipment.
[0015] In order to achieve the above-mentioned object, the present invention adopts the following technical solutions:
[0016] The method for reading a meter using a nested non-uniform scale dial based on machine vision is characterized by the following steps:
[0017] Step 1. Build a collection of instrument images and train an instrument detection model ;
[0018] Step 2. Input the instrument image to be tested into the instrument detection model Processed in Single dial rectangular image ;in, Represents the i-th single dial rectangular image in the instrument picture to be tested, Represents the total number of single dial rectangular images;
[0019] Step 3. Perform preprocessing operations, including grayscale, median filtering, and image enhancement, to obtain the preprocessed i-th single dial rectangular image ,by The lower left corner is the origin, and the horizontal right is Axis, vertical upward Axis, thereby establishing the image coordinate system;
[0020] Step 4. Obtain based on the improved Hough transform algorithm The coordinates of the dial center and radius ;
[0021] Step 5. Obtain based on regression method The pointer fitting straight line equation is: , and satisfies ,in, express The slope of the pointer fitting straight line equation, express The intercept of the pointer fitting line equation, express The horizontal coordinate of the pixel point in the pointer domain, express The vertical coordinate of the pixel point in the pointer domain;
[0022] Step 6. Acquire based on the true scale extraction algorithm The ordered real scale line fitting rectangle information set ;
[0023] Step 7. Based on the distance method, the straight line equation is fitted according to the pointer Get in sequence Dial reading ;
[0024] Step 8. Dial reading Perform linear operations to obtain the final reading of the instrument image to be tested .
[0025] The method for reading a meter using a nested non-uniform scale dial based on machine vision according to the present invention is also characterized in that step 1 includes the following steps:
[0026] Step 1.1: Collect nested non-uniform scale instrument images in the substation to construct an instrument image set ;
[0027] Step 1.2: Instrument image collection The instrument area in the image is marked to obtain a set of instrument images with labels. ;
[0028] Step 1.3: Collect the labeled instrument images Input into the improved YOLOv5 network for training to obtain the instrument detection model .
[0029] Furthermore, the improved Hough transform algorithm in step 4 includes the following steps:
[0030] Step 4.1: Use arc tracking algorithm to obtain in Discrete arcs:
[0031] Step 4.2: Based on the circle gradient, obtain multiple candidate circle centers from the discrete arc segments;
[0032] Step 4.3: Introduce a lookup table and a bit accumulator to vote on candidate circle centers to determine the target circle center;
[0033] Give each candidate circle a different center Bit binary lookup table, and each candidate circle center corresponds to In the binary lookup table, only one bit is 1, and the rest are 0;
[0034] remember The coordinates are The number of votes for the candidate center in binary, Indicates the The binary values of candidate circle centers, where ;
[0035] Traverse each candidate circle center in turn and use the bit accumulator to endowment , thus obtaining the final number of votes for each candidate center, and The candidate center with the largest number of 1s is set as the target center ,in, Represents a bitwise OR operation.
[0036] Furthermore, the step 4.1 includes the following steps:
[0037] Step 4.1.1: Perform binarization to obtain a binary image with a grayscale value of 255 for the edge pixels and a grayscale value of 0 for the rest of the pixels. ;
[0038] Define and initialize the number of discrete arcs , define and initialize the current point is empty;
[0039] Step 4.1.2: Scan the binary image in a certain order If the pixel with grayscale value of 255 is scanned, the first pixel with grayscale value of 255 is used as the starting point. , and set the current point Starting point , define and initialize the marker Then, execute step 4.1.3, otherwise, save For each arc segment, execute step 4.2;
[0040] Step 4.1.3: Assign to , the starting point Join In the arc segment;
[0041] Step 4.1.4: The grayscale value of the newly added coordinate points in the arc segment is set to 0;
[0042] Step 4.1.5: Traverse the current point clockwise Among the 4 4-adjacent points, determine whether there is a 4-adjacent point with a grayscale value of 255. If so, set the first 4-adjacent point with a grayscale value of 255 read as the current point. , and the current point Join If there is no arc segment, execute step 4.1.4; if not, execute step 4.1.6;
[0043] Step 4.1.6: Traverse the current point clockwise Among the four 8-adjacent oblique points, determine whether there is an 8-adjacent oblique point with a grayscale value of 255. If so, set the first 8-adjacent oblique point with a grayscale value of 255 read as the current point. , and the current point Join If there is no arc, execute step 4.1.4; if it does not exist, then determine Is it true? If so, go to step 4.1.7; otherwise, go to step 4.1.2;
[0044] Step 4.1.7: Set the starting point For the current point , will order Then, proceed to step 4.1.5.
[0045] Furthermore, the step 4.2 includes the following steps:
[0046] Step 4.2.1: Calculate binary image The horizontal gradient vector of each point in and vertical gradient vector ;
[0047] The number of arcs traversed is , and initialize ; Define the number of candidate circles as , and initialize , set the maximum number of candidate circles to ;remember The center coordinates are ; recorded as the first The coordinates of the center of the candidate circle are ;
[0048] Step 4.2.2: Define and initialize variables ; Record The total number of points in an arc segment is ;
[0049] Step 4.2.3: The first arc Points are recorded as ; Select any point from other arc segments and record it as , and satisfy: ;
[0050] from Select the point that satisfies the first change rule As The first change rule is:
[0051] like , from Change to ;
[0052] like , from Change to ;in, is a given constant;
[0053] like In the process of moving along the first change rule, if equation (1) is satisfied, then Set as symmetrical point, and Set as , execute step 4.2.4; otherwise, execute step 4.2.8;
[0054] (1)
[0055] In formula (1), 、 Respectively 、 The horizontal gradient vector, 、 Respectively 、 The vertical gradient vector of
[0056] Step 4.2.4: and its symmetric point Substituting into formula (2), we can get Middle The coordinates of candidate circle centers and its corresponding radius :
[0057] (2)
[0058] In formula (2), int() represents the rounding operation;
[0059] Step 4.2.5: If , then Assign to , on the contrary, Assign to ;
[0060] like , then endowment If yes, go to step 4.2.6; otherwise, go to step 4.2.7;
[0061] Step 4.2.6: If , then execute step 4.2.4; otherwise, save The coordinates of candidate circle centers;
[0062] Step 4.2.7: If , then endowment Then, execute step 4.2.3; otherwise, judge If so, endowment Then, execute step 4.2.2, otherwise, save The coordinates of candidate circle centers and Assign to ;
[0063] Step 4.2.8. Select any point from other arc segments and record it as , and satisfy: ;
[0064] from Select the point that satisfies the second change rule As Another preliminary point, the second change rule is:
[0065] like , from Change to ;
[0066] like , from Change to ;in, is a given constant;
[0067] like In the process of moving along the second change rule, if equation (3) is satisfied, then Set as symmetrical point, and Set to , execute step 4.2.9; otherwise, execute step 4.2.7;
[0068] (3)
[0069] In formula (3), 、 Respectively 、 The horizontal gradient vector, 、 Respectively 、 The vertical gradient vector of
[0070] Step 4.2.9: and its symmetric point Substituting into formula (4), we can get Middle candidate center points and their corresponding radius :
[0071] (4)
[0072] Step 4.2.10: If , then Assign to , on the contrary, Assign to ;
[0073] like , then endowment If yes, go to step 4.2.11; otherwise, go to step 4.2.7;
[0074] Step 4.2.11: If , then execute step 4.2.9; otherwise, save The coordinates of the candidate circle centers.
[0075] Furthermore, the step 5 comprises the following steps:
[0076] Step 5.1: Make a A first mask of the same size, wherein the first mask is is the center of the circle and the radius is × The circle area is set to white, and the rest of the area is set to black; represents the first radius scaling factor, ;
[0077] Step 5.2: Place the first mask with Perform a bitwise AND operation to obtain a pointer image without scale ;
[0078] Step 5.3: After binarization, corrosion, and expansion operations, the image is obtained , and then the image Extract and obtain Pointer connected domain pixel set :
[0079]
[0080] in, express The mth pixel point in the pointer connected domain, express The total number of pixels in the connected domain of the pointer;
[0081] Step 5.4: Given Learning rate , the absolute value of the threshold ;
[0082] Step 5.5: endowment ;
[0083] Step 5.6: If , then it means that The pointer fitting straight line equation is: ; Otherwise, return to 5.5 and execute sequentially.
[0084] Furthermore, the step 6 includes the following steps:
[0085] Step 6.1: Make a A second mask of the same size, wherein the second mask is is the center of the circle and the radius is × to The circle area is set to white, and the rest of the area is set to black; represents the second radius scaling factor, ;
[0086] Step 6.2: Place the second mask with Perform bitwise AND operation to obtain the scale image ;
[0087] Step 6.3: Scale image according to the true scale extraction algorithm Extract and obtain the ordered real scale line fitting rectangular frame information set .
[0088] Furthermore, the true scale extraction algorithm in step 6.3 includes the following steps:
[0089] Step A: Use the improved Canny edge detection algorithm to Process and obtain All rectangular boxes in ;
[0090] Step A1: Given parameters, including: low threshold , low threshold single cycle increase , lower threshold upper limit , the difference between the high and low thresholds , the minimum area of the rectangular frame , maximum area , minimum aspect ratio , maximum aspect ratio , lower limit of the number of intersecting rectangles ; The lower limit of the number of actual scale lines , distance threshold ;
[0091] Will The number of edge detections is recorded as , and initialized to =1;
[0092] Step A2: If , then execute step A3; otherwise, it means that Rectangular frame information collection = , and execute step B, wherein, express The total number of rectangular frame information contained, express The Rectangular frame information, and the Rectangular frame information Contains the center coordinates of a rectangular box and its width ,high and rotation angle , ;
[0093] Step A3: according to , , the first edge detection is performed to obtain the first detected edge image ; according to , , , , , , , a certain number of rectangular frame information is obtained, and is assigned to , and is assigned to , and step A2 is executed;
[0094] Step B: remove the redundant rectangular frame in to obtain the pre-screened rectangular frame information set :
[0095] Step B1: if the number of elements in is greater than , the first rectangular frame information is taken out from , step B2 is executed, otherwise, the pre-screened rectangular frame information set is obtained:
[0096] , and step C is executed, wherein represents the th rectangular frame information in , and represents the total number of rectangular frame information contained in ;
[0097] Step B2: find the number of rectangular frames intersecting from ; if , step B3 is executed; otherwise, is removed from , and is reordered, and then step B1 is returned for sequential execution; Step B3: arrange the
[0098] rectangular frame information in descending order according to the area of the rectangular frame itself, and store the th rectangular frame information in the arrangement in ; then remove the rectangular frame information from , and reorder After reordering, return to step B1 and execute sequentially;
[0099] Step C: Extraction After sorting the real scale in the , we can get the ordered real scale line fitting rectangle information set ;
[0100] Step C1: If If it is empty, go to step C4, otherwise go to step C2;
[0101] Step C2: From Take out the first rectangular box information ,Pass The center coordinates of Draw a straight line parallel to the long side of its own rectangle , thus calculating the center of the circle To the straight line distance , calculate the center of the circle arrive distance , calculate the direction of the center of the circle The angle between the vector of the circle and the vector pointing to the right horizontally ;
[0102] Step C3: If , then 、 、 Deposit as a whole , and from After removing from the list, execute step C1, otherwise, directly from Remove it and execute step C1;
[0103] Step C4: From Find the distance from the center of the circle to the center coordinate with the highest frequency A rectangular frame will be aligned according to the angle After the rectangular boxes are arranged in descending order, the ordered real scale line fitting rectangular box information set is obtained. :
[0104] ;in, express Middle Rectangular frame information, express points within To the center distance, Indicates the direction of the center of the circle points within The angle between the vector pointing to the right and the horizontal vector pointing to the center of the circle.
[0105] Furthermore, the step 7 includes:
[0106] Step 7.1: Make a A third mask of the same size, wherein the third mask is is the center of the circle and the radius is The circle area is set to white, and the rest of the area is set to black;
[0107] Step 7.2: Place the third mask with Perform bitwise AND operation to obtain a circular instrument image ,and The coordinate points within Coordinate points of the inner rectangle and the equation of the fitted line with the pointer The coordinate point of
[0108] Step 7.3: Create The dial polar coordinate system is the origin and the horizontal right is the polar axis;
[0109] Step 7.4: Expand the dial polar coordinate system to the set size The horizontal axis of the rectangular area is denoted as , the vertical axis of the rectangular area is denoted as ;
[0110] Use formula (1) to convert the dial polar coordinate system into The coordinates of any point in Map to the rectangular area and get the corresponding new coordinate point ; Thus, all new coordinate points constitute an ordered real scale line fitting rectangle information set , and get the new pointer fitting straight line equation ;in, Indicates the new pointer fitting line equation axis coordinates;
[0111] (1)
[0112] In formula (2), is the width of the rectangular area, is the height of the rectangular area, and 、 ;
[0113] Step 7.5: Based on the known instrument range, we can get The absolute value of the difference between adjacent scale readings ;
[0114] Step 7.6: Use formula (2) to calculate Dial reading ;
[0115] (2)
[0116] In formula (2), Indicates the The equation of the straight line from the scale line to the new pointer distance, and , Indicates the The equation of the straight line from the scale line to the new pointer distance, and ,in, yes Middle The coordinates of the center of the fitted rectangle of each scale line on the horizontal axis; yes Middle The coordinates of the center of the fitted rectangle of each tick mark on the horizontal axis.
[0117] The electronic device of the present invention includes a memory and a processor, wherein the memory is used to store a program that supports the processor to execute the nested non-uniform scale dial reading method, and the processor is configured to execute the program stored in the memory.
[0118] Compared with the prior art, the beneficial effects of the present invention are embodied in:
[0119] 1. The automatic meter reading method of the present invention utilizes an improved circular gradient symmetric Hough transform. This method obtains arc segments by tracing image edges, avoiding the problem of severe noise interference on low-resolution images and ensuring the method's high robustness. Using arc segments to find target points eliminates the need to traverse all pixels, significantly improving the computational speed for high-resolution images. Based on the symmetry of the circular gradient, the relationship between the perpendicular bisector of the symmetric point and the circle center is utilized to quickly locate the circle center range while avoiding the problem of the normal direction of a single point easily deviating from the circle center, thus balancing the method's speed and accuracy. A bit accumulator is introduced to perform the circle center voting task based on a bitwise OR operation, which consumes little memory and requires relatively low hardware requirements.
[0120] 2. The automatic meter reading method of the present invention determines the pointer fitting line based on regression. This regression method is highly adaptable and can fit lines under different pixel distributions without manual parameter adjustment, meeting the needs of automated detection. It avoids the situation where the fitting line is located at the edge of the pointer image, thereby improving the fitting accuracy. The introduction of the center coordinate transforms the binary regression problem into a univariate regression problem, thereby improving the calculation speed. At the same time, the fixed point is used to reduce the error range of the fitting line, further improving the fitting accuracy.
[0121] 3. The automatic meter reading method of the present invention utilizes a loop statement to sequentially change the set threshold of Canny edge detection, thereby obtaining all fitted rectangular frames on the dial and avoiding the problem of limited scale outline extraction capability caused by a single threshold. Furthermore, using the number of overlapping rectangular frames as the evaluation criterion avoids the problem of overlapping rectangular frames with similar intersection-to-union ratios, making screening difficult, and effectively distinguishes candidate scale lines from interference information. Furthermore, based on the geometric conditions that the scale lines are aligned with the center of the circle and that the distance from the center of each scale line to the center of the circle is the same, the distance from the center of the circle to the line and the distance from the center of the circle to the center of the rectangular frame are introduced as further screening criteria, resulting in more accurate scale line information.
[0122] 4. The present invention's automatic meter reading method utilizes the distance method to calculate the dial reading. This method determines the actual reading based on the positional relationship between the pointer and the ordered scale lines, resolving the issue of unevenly scaled instruments, which the angle method cannot address. Furthermore, this method uses coordinate transformation to map the circular scale line area to a rectangular area, accurately determining the distance between the pointer's fitted line and two adjacent scale rectangles, thereby precisely calculating the distance between the pointer's fitted line and adjacent scale lines. BRIEF DESCRIPTION OF THE DRAWINGS
[0123] Figure 1 Flow chart of the steps of the present invention;
[0124] Figure 2 This is the improved YOLOv5 network structure diagram of the present invention;
[0125] Figure 3 This is a structural diagram of the improved CBAM module of the present invention;
[0126] Figure 4 The working principle diagram of the SPD module introduced in the present invention;
[0127] Figure 5 This is a flow chart of the arc segment tracking algorithm of the present invention;
[0128] Figure 6 This is a flow chart of the improved Hough transform algorithm of the present invention;
[0129] Figure 7 This is the flow chart of the true scale extraction algorithm of the present invention. DETAILED DESCRIPTION
[0130] In this embodiment, a nested non-uniform dial reading method based on machine vision has the characteristics of high accuracy and strong robustness, and can complete the reading of various dials. The main steps include: 1. constructing an instrument image set and performing model training; 2. obtaining a single dial image; 3. obtaining the dial center and radius; 4. obtaining a fitting line for the dial pointer; 5. obtaining the dial scale fitting rectangle information; 6. calculating the reading. Specifically, Figure 1As shown, the method is carried out in the following steps:
[0131] Step 1. Build a collection of instrument images and train an instrument detection model ;
[0132] Step 1.1: Collect nested non-uniform scale instrument images in the substation to construct an instrument image set ;
[0133] Step 1.2: Use Labelimg to analyze the instrument image collection The instrument area in the image is marked to obtain a set of instrument images with labels. and a .txt file with the labeled rectangle information;
[0134] Step 1.3: Configure the .yaml file to collect labeled instrument images Input into the improved YOLOv5 network for training to obtain the instrument detection model .
[0135] In order to enable the network to recognize objects with lower resolution, retain deep feature information of the image, and avoid interference from other objects on the detection target, such as Figure 2 As shown, the YOLOv5 network used in this embodiment makes the following improvements:
[0136] Improvement 1: Replace the C3 module in the backbone network with an improved C3 module. In the improved C3 module, each CBS is connected to an SPD module. The function of SPD is as follows: Figure 4 As shown: Given a feature map X of arbitrary size S×S×C, SPD maps the sub-features of the feature map X into a square area with [0,0] and [scale-1,scale-1] as diagonal vertices as follows:
[0137]
[0138] and Represents the same type of feature information, ,satisfy:
[0139]
[0140] The scale of the new feature map obtained after SPD processing is: ; Then the number of channels of the mosaic image The number of the original network is converted to the number that should be in the original network through the subsequent CBS module; Figure 4 As shown, in this embodiment Taking 2, this method not only meets the requirements of feature extraction and information retention, but also avoids the huge amount of calculation caused by doubling the number of channels; in other embodiments, the SPD module can also be added to other C3 modules in the YOLOv5 network;
[0141] Improvement 2: Extend the FPN structure of the neck network, connecting CBS, UpSample, Concat, and C3 in sequence from the top of the FPN. Extend the PAN structure of the neck network, connecting C3, Concat, and CBS in sequence from the top of the PAN. Connect the C3 module at the top of the improved FPN structure to the CBS module at the top of the improved PAN structure. Add a new detection head to the top of the FPN structure of the neck network, so that the network can detect small targets with a resolution of at least 16 pixels.
[0142] Improvement 3: In the original YOLOv5 network, the improved CBAM module is introduced on the connection path between the C3 module of the backbone network and the Concat of the neck network, such as Figure 3 As shown; Among them, the improved CBAM module adopts the following operation process: input a The image In is processed by CAM (channel attention module) and SAM (spatial attention module) to obtain Result graph and Result graph ; The result graphs are and the resulting graph Multiply it with the image In to get the result image and the resulting graph ;Will and Multiply by the weights Adding them together, ; Then perform batch normalization to obtain the output graph Out. In this embodiment, and The value of is obtained by network training. Figure 3 As shown in the figure: a and b in the module name C3ab are both numbers, where a takes the value of 1 and 2, respectively indicating that the BottleNect1 module and BottleNect2 are used in the C3 module; b represents the number of BottleNeck modules connected in sequence in the C3 module, and its value can be 3, 6, or 9.
[0143] The automatic meter reading method in this embodiment is based on an improved YOLOv5 network for recognizing meter images. The improvements have the following beneficial effects: extending the neck network and adding a new probe can extract and output shallow image information; introducing an improved CBAM module in the connection path between the C3 module of the backbone network and the Concat of the neck network. The improved CBAM module uses a parallel structure to exchange channel and spatial feature information of the image and obtains the output image through weighted fusion, effectively addressing the different preferences of different network layers for feature information. At the same time, batch normalization is used after weighted fusion to regularize the data and alleviate the problems of internal covariate shift and model overfitting; and embedding the SPD module within the C3 module of the backbone network can perform convolution downsampling on the feature map, reducing the feature information loss caused by convolution when detecting small objects.
[0144] Step 2. Input the 640×640×3 image to be tested into the instrument detection model Processed in Single dial rectangular image ;in, represents the i-th single dial rectangular image, and N represents the total number of single dial rectangular images;
[0145] Step 3. Perform preprocessing operations, including grayscale, median filtering, and image enhancement; then The lower left corner is the origin, and the horizontal right is Axis, vertical upward Axis, thereby establishing an image coordinate system. In other embodiments, the system can also be established according to other rules.
[0146] Step 4. Obtain based on the improved Hough transform algorithm The coordinates of the dial center and radius Specifically, the improved Hough transform algorithm is performed as follows:
[0147] Step 4.1: Use arc tracking algorithm to obtain Discrete arc segments in :
[0148] Step 4.1.1: If Figure 5 As shown, first Perform binarization to obtain a binary image with a grayscale value of 255 for the edge pixels and a grayscale value of 0 for the rest of the pixels. In this embodiment, the grayscale value of the edge pixel is set to 255, and the grayscale value of the other pixel points is set to 0. In other embodiments, different binarization methods can also be used, but the starting point The judgment conditions also change due to different binarization methods;
[0149] Redefine and initialize the number of discrete arc segments , define and initialize the current point Empty; front point The position of will change continuously during the tracking process, with the aim of extending the arc segment in a certain direction.
[0150] Step 4.1.2: Scan the binary image in a certain order Here, in the order from top to bottom and from left to right, if the pixel with gray value of 255 is scanned, the first pixel with gray value of 255 is used as the starting point. , and set the current point Starting point ,, starting point Record the entry position of the current arc. When the arc extends to the end in a certain direction, the current point Return to the starting point , so that the arc segment extends in another direction; define and initialize the marker Then execute step 4.1.3, otherwise, save For each arc segment, execute step 4.2; The function is to record whether the starting point has been returned during the tracking process ,if Description: Has not returned to the starting point yet ,if Indicates that you have returned to the starting point .
[0151] Step 4.1.3: Assign to , the starting point Join In the arc segment;
[0152] Step 4.1.4: The grayscale value of the newly added coordinate points in each arc segment is set to 0; this step is to prevent the pixel points from being tracked repeatedly;
[0153] Step 4.1.5: Traverse the current point clockwise Among the four 4-adjacent points, determine whether there is a 4-adjacent point with a grayscale value of 255. The 4-adjacent points refer to the adjacent points in the horizontal and vertical directions. Here, the traversal starts from the adjacent point in the vertical direction. If it exists, the first 4-adjacent point with a grayscale value of 255 read is set as the current point. , and the current point Join If there is an arc segment, execute step 4.1.4; if it does not exist, execute step 4.1.6.
[0154] Step 4.1.6: Traverse the current point clockwise Among the four 8-adjacent oblique points, determine whether there is an 8-adjacent oblique point with a grayscale value of 255. The 8-adjacent point is the adjacent point in the diagonal direction. Here, the traversal starts from the 8-adjacent point in the lower left corner; if it exists, the first 8-adjacent oblique point with a grayscale value of 255 read is set as the current point , and the current point Join If there is no arc, execute step 4.1.4; if it does not exist, then determine Is it true? If so, go to 4.1.7. Here, it means that the arc segment is extended in only one direction and needs to return to the starting point. Start extending in the other direction; otherwise, go to step 4.1.2, which means the arc has been extended and you need to find the next arc to be traced.
[0155] Step 4.1.7: Set the starting point For the current point , will order Then, proceed to step 4.1.5.
[0156] Step 4.2: Determine the candidate circle center based on the circle gradient:
[0157] Step 4.2.1: If Figure 6 As shown, calculate the binary image The horizontal gradient vector of each point in and vertical gradient vector According to the system construction rules of the embodiment, the horizontal right direction and the vertical upward direction are respectively defined as the vector in the positive direction of x and y;
[0158] The number of arcs traversed is , and initialize ; Define the number of candidate circles as , and initialize , set the maximum number of candidate circles to ;remember The center coordinates are ; recorded as the first The coordinates of the center of the candidate circle are ; Set here is 64.
[0159] Step 4.2.2: Define and initialize variables ; Record The total number of points in an arc segment is ;
[0160] Step 4.2.3: The first arc Points are recorded as ; Select any point from other arc segments and record it as , and satisfy: ;
[0161] from Select the point that satisfies the first change rule As The first change rule is:
[0162] like , from Change to ;
[0163] like , from Change to ; here Set to 4;
[0164] like When moving along the first change rule, the formula (1) is satisfied. Set as symmetrical point, and Set as , execute step 4.2.4; otherwise, execute step 4.2.8;
[0165] (1)
[0166] In formula (1), 、 Respectively 、 The horizontal gradient vector, 、 Respectively 、 The vertical gradient vector of the target is obtained from the discrete arc segment, without traversing all the pixels in the same line. The operation speed is fast when processing higher resolution images. At the same time, different system construction rules need to be adjusted. rules of change.
[0167] Step 4.2.4: and its symmetric point Substituting into formula (2), we can get Middle The coordinates of candidate circle centers and its corresponding radius :
[0168] (2)
[0169] In formula (2), int() represents an integer operation;
[0170] Step 4.2.5: If , then is assigned to , otherwise, is assigned to ;
[0171] If , then is assigned to , and step 4.2.6 is executed; otherwise, step 4.2.7 is executed.
[0172] Step 4.2.6: If , then step 4.2.4 is executed; otherwise, the coordinates of the candidate circle center are saved.
[0173] Step 4.2.7: If , then is assigned to , and step 4.2.3 is executed; otherwise, it is determined whether ; if yes, then is assigned to , and step 4.2.2 is executed, otherwise, the coordinates of the candidate circle center are saved, and is assigned to .
[0174] Step 4.2.8. Select an arbitrary point from other arc segments as , and satisfy: ;
[0175] Select a point from as another preparatory point of , which satisfies the second change rule, and the second change rule is:
[0176] If , changes from to ;
[0177] If , changes from to ; here is set to 4;
[0178] If satisfies formula (3) during movement along the second change rule, then is set as the symmetric point of , and Set to , execute step 4.2.9; otherwise, execute step 4.2.7;
[0179] (3)
[0180] In formula (3), 、 Respectively 、 The horizontal gradient vector, 、 Respectively 、 The vertical gradient vector needs to be adjusted for different system building rules. rules of change.
[0181] Step 4.2.9: and its symmetric point Substituting into formula (4), we can get Middle candidate center points and their corresponding radius :
[0182] (4)
[0183] Step 4.2.10: If , then Assign to , on the contrary, Assign to ;
[0184] like , then endowment If yes, go to step 4.2.11; otherwise, go to step 4.2.7;
[0185] Step 4.2.11: If , then execute step 4.2.9; otherwise, save The center coordinates of the candidate circles.
[0186] 4.3: Introduce a lookup table and bit accumulator to vote for candidate circle centers and determine the target circle center:
[0187] Give each candidate circle a different center Bit binary lookup table, and each candidate circle center corresponds to In the binary lookup table, only one bit is 1, and the rest are 0;
[0188] remember The coordinates are The number of votes for the candidate center of the circle in binary is presented in the form of a binary number table in this embodiment. Indicates the The binary values of candidate circle centers, where .
[0189] Traverse each candidate circle center in turn, such as Figure 6 As shown, and through the bit accumulator endowment , thus obtaining the final number of votes for each candidate center, and The candidate center with the largest number of 1s is set as the target center ,in, Represents a bitwise OR operation. For example, suppose there are two candidate circle centers 、 , there are 5 points pointing to the coordinates , the corresponding lookup table bits are: [00000001], [00000010], [00000100], [00001000], [00010000], there are 3 points pointing to the coordinates, and the corresponding lookup tables are: [00100000], [01000000], [10000000]. Through the above operations, is [00011111], is [11100000], so the target center is .
[0190] Step 5. Obtain based on regression method The pointer fitting straight line equation is: , and satisfies ,in, express The slope of the pointer fitting straight line equation, express The intercept of the pointer fitting line equation, express The horizontal coordinate of the pixel point in the pointer domain, express The vertical coordinate of the pixel point in the pointer domain;
[0191] Step 5.1: Make a The first mask of the same size is made by is the center of the circle and the radius is × The circle area is set to white, and the rest of the area is set to black; represents the first radius scaling factor, .
[0192] Step 5.2: Place the first mask with Perform a bitwise AND operation to obtain a pointer image without scale ;
[0193] Step 5.3: After binarization, corrosion, and expansion operations, the image is obtained , and then the image Extract and obtain Pointer connected domain pixel set :
[0194]
[0195] in, express The mth pixel point in the pointer connected domain, express The total number of pixels in the connected domain of the pointer.
[0196] Step 5.4: Given Learning rate , the absolute value of the threshold ; here Set to 0.001, set is 0.2;
[0197] Step 5.5: will be given ;in, It is obtained by the following steps: Setting the loss function , among which This is to make the loss function The coefficient of the result after derivation is 1; the coordinates of the center of the circle Substitute the pointer into the fitting straight line equation ,get , we can get:
[0198]
[0199] Taking the derivative of the loss function, we get:
[0200]
[0201] Step 5.6: If , then it means that The pointer fitting straight line equation is: ; Otherwise, return to 5.5 and execute sequentially.
[0202] Step 6. Acquire based on the true scale extraction algorithm The ordered real scale line fitting rectangle information set ;
[0203] Step 6.1: Make a A second mask of the same size, wherein the second mask is made by is the center of the circle and the radius is × to The circle area is set to white, and the rest of the area is set to black; represents the second radius scaling factor, ;
[0204] Step 6.2: Place the second mask with Perform bitwise AND operation to obtain the scale image .
[0205] Step 6.3: Scale image according to the true scale extraction algorithm Extract and obtain the ordered real scale line fitting rectangular frame information set Among them, Figure 7 As shown in Figure 2, the true scale extraction algorithm follows the following process:
[0206] Step A: Utilize the improved Edge detection algorithm Process and obtain All rectangular boxes in ;
[0207] Step A1: Given parameters, including: low threshold , low threshold single cycle increase , lower threshold upper limit , the difference between the high and low thresholds , the minimum area of the rectangular frame , maximum area , minimum aspect ratio , maximum aspect ratio , lower limit of the number of intersecting rectangles ; The lower limit of the number of actual scale lines , distance threshold ;
[0208] In this embodiment, the parameters are substituted as follows: 、 、 、 、 、 、 、 、 、 、 ;at the same time, Edge detection requires input of low threshold and high threshold. As a high threshold input;
[0209] Will The number of edge detections is recorded as , and initialized to =1.
[0210] Step A2: If , then execute step A3; otherwise, it means that Rectangular frame information collection = , and execute step B, wherein, express The total number of rectangular frame information contained, express The Rectangular frame information, and the Rectangular frame information Contains the center coordinates of a rectangular box and its width ,high and rotation angle , ;
[0211] Step A3: According to 、 ,right Carry out the Second-rate Edge detection, get the Detected edge image ,like Figure 7 As shown, the above process is encapsulated into ; then Substitute the minimum bounding rectangle algorithm to get all the rectangles, and then according to the parameters 、 、 、 Filter to get multiple target rectangles, such as Figure 7 As shown, the above process is encapsulated into ,in, Represents multiple target rectangles; such as Figure 7 As shown, the above process is encapsulated into ; Afterwards endowment ,Will endowment , proceed to step A2.
[0212] Step B: Elimination The redundant rectangular boxes in the pre-screened rectangular box information set is obtained :
[0213] Step B1: If The number of elements in is greater than the threshold , then from Take out the first rectangular box information , execute step B2, otherwise, obtain the pre-screened rectangular frame information set:
[0214]
[0215] And execute step C, wherein, express Middle Rectangular frame information, express The total number of rectangular frame information included; such as Figure 7 As shown, the judgment process of B1 is encapsulated into whether it is established;
[0216] Step B2: From Find the Number of intersecting rectangles ;like , then execute step B3; otherwise, from Eliminate and After reordering, return to step B1 and execute sequentially;
[0217] Step B3: The rectangular frame information is sorted in descending order according to the area of its own rectangular frame, and the first The rectangular frame information of the bit is stored in ; then Rectangular frame information from Eliminate and After reordering, return to step B1 and execute sequentially; Figure 7 As shown, the rectangular frame removal and sorting process of step B2 is encapsulated into .
[0218] Step C: Extraction After sorting the real scale in the , we can get the ordered real scale line fitting rectangle information set ;
[0219] Step C1: If If it is empty, go to step C4, otherwise go to step C2;
[0220] Step C2: From Take out the first rectangular box information ,Pass The center coordinates of Draw a straight line parallel to the long side of its own rectangle , thus calculating the center of the circle To the straight line distance , calculate the center of the circle arrive distance , calculate the direction of the center of the circle The angle between the vector of the circle and the vector pointing to the right horizontally ;like Figure 7 As shown, step C2 is encapsulated as The purpose of step C2 is to eliminate the rectangular frame with the wrong direction according to the characteristic that the dial scale line points to the center of the circle; in this embodiment, the center of the circle is calculated by To the straight line distance In other embodiments, the angle between the line connecting the rectangular frame and the center of the circle and the long side of the rectangular frame may be used as a judgment condition.
[0221] Step C3: If , then 、 、 Deposit as a whole , and from After removing from the list, execute step C1, otherwise, directly from Remove it and execute step C1;
[0222] Step C4: From Find The highest frequency A rectangular frame will be right After the rectangular boxes are arranged in descending order, the ordered real scale line fitting rectangular box information set is obtained. :
[0223] ;
[0224] in, express Middle Rectangular frame information, express points within To the center distance, Indicates the direction of the center of the circle points within The angle between the vector of the circle and the vector pointing to the right horizontally. Figure 7 As shown, in step C3 、 、 Deposit as a whole and step C4 is encapsulated into .
[0225] Step 7. Based on the distance method, the straight line equation is fitted according to the pointer Get in sequence Dial reading ;
[0226] Step 7.1: Make a A third mask of the same size, wherein the third mask is made by is the center of the circle and the radius is The circle area is set to white, and the rest of the area is set to black;
[0227] Step 7.2: Place the third mask with Perform bitwise AND operation to obtain a circular instrument image ,and The coordinate points within Coordinate points of the inner rectangle and the equation of the fitted line with the pointer The coordinates of the points;
[0228] Step 7.3: In this embodiment, establish The dial polar coordinate system is the origin and the horizontal right is the polar axis;
[0229] Step 7.4: Expand the dial polar coordinate system to the set size In this embodiment, the rectangular area Take 250, Take 50; where the horizontal axis of the rectangular area is recorded as , the vertical axis of the rectangular area is denoted as ;
[0230] Use formula (1) to convert the dial polar coordinate system into The coordinates of any point in Map to the rectangular area and get the corresponding new coordinate point ; Thus, all new coordinate points constitute an ordered real scale line fitting rectangle information set , and get the new pointer fitting straight line equation ;in, Indicates the new pointer fitting line equation axis coordinates;
[0231] (1)
[0232] In formula (2), is the width of the rectangular area, is the height of the rectangular area, and 、 .
[0233] Step 7.5: Based on the known instrument range, we can get The absolute value of the difference between adjacent scale readings , in this embodiment is 0.2;
[0234] Step 7.6: Use formula (2) to calculate Dial reading ;
[0235] (2)
[0236] In formula (2), Indicates the The equation of the straight line from the scale line to the new pointer distance, and , Indicates the The equation of the straight line from the scale line to the new pointer distance, and ,in, yes Middle The coordinates of the center of the fitted rectangle of each scale line on the horizontal axis; yes Middle The coordinates of the center of the fitted rectangle of each tick mark on the horizontal axis.
[0237] Step 8. Dial reading Perform linear operations to obtain the final reading of the instrument image to be tested .
[0238] In this embodiment, an electronic device includes a memory and a processor, wherein the memory is used to store a program that supports the processor to execute the above method, and the processor is configured to execute the program stored in the memory.
[0239] In this embodiment, a computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above method are executed.
[0240] The above are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention description and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A nested non-uniform scale dial reading method based on machine vision, characterized in that: Follow these steps: Step 1. Build a collection of instrument images and train an instrument detection model ; Step 2. Input the instrument image to be tested into the instrument detection model Processed in Single dial rectangular image ;in, Represents the i-th single dial rectangular image in the instrument picture to be tested, Represents the total number of single dial rectangular images; Step 3. Perform preprocessing operations, including grayscale, median filtering, and image enhancement, to obtain the preprocessed i-th single dial rectangular image ,by The lower left corner is the origin, and the horizontal right is Axis, vertical upward Axis, thereby establishing the image coordinate system; Step 4. Obtain based on the improved Hough transform algorithm The coordinates of the dial center and radius ; Step 4.1: Use arc segment tracking algorithm to obtain in Discrete arcs: Step 4.2: Based on the circle gradient, use discrete arc segments to obtain multiple candidate circle centers; Step 4.3: Introduce a lookup table and a bit accumulator to vote on candidate circle centers to determine the target circle center; Give each candidate circle a different center Bit binary lookup table, and each candidate circle center corresponds to In the binary lookup table, only one bit is 1, and the rest are 0; remember The coordinates are The number of votes for the candidate center in binary, Indicates the The binary values of candidate circle centers, where ; Traverse each candidate circle center in turn and use the bit accumulator to endowment , thus obtaining the final number of votes for each candidate center, and The candidate center with the largest number of 1s is set as the target center ,in, Represents a bitwise OR operation; Step 5. Obtain based on regression method The pointer fitting straight line equation is: , and satisfies ,in, express The slope of the pointer fitting straight line equation, express The intercept of the pointer fitting line equation, express The horizontal coordinate of the pixel point in the pointer domain, express The vertical coordinate of the pixel point in the pointer domain; Step 5.1: Make a The first mask of the same size, wherein the first mask is made by is the center of the circle and the radius is × The circle area is set to white, and the rest of the area is set to black; represents the first radius scaling factor, ; Step 5.2: Place the first mask with Perform a bitwise AND operation to obtain a pointer image without scale ; Step 5.3: After binarization, corrosion, and expansion operations, the image is obtained , and then the image Extract and obtain Pointer connected domain pixel set ,in, express The mth pixel point in the pointer connected domain, express The total number of pixels in the connected domain of the pointer; Step 5.4: Given Learning rate , the absolute value of the threshold ; Step 5.5: endowment ; Step 5.6: If , then it means that The pointer fitting straight line equation is: ; Otherwise, return to 5.5 and execute sequentially; Step 6. Acquire based on the true scale extraction algorithm The ordered real scale line fitting rectangle information set ; Step 6.1: Make a A second mask of the same size, wherein the second mask is made by is the center of the circle and the radius is × to The circle area is set to white, and the rest of the area is set to black; represents the second radius scaling factor, ; Step 6.2: Place the second mask with Perform bitwise AND operation to obtain the scale image ; Step 6.3: Scale image according to the true scale extraction algorithm Extract and obtain the ordered real scale line fitting rectangular frame information set ; Step A: Use the improved Canny edge detection algorithm to Process and obtain All rectangular boxes in ; Step A1: Given parameters, including: low threshold , low threshold single cycle increase , lower threshold upper limit , the difference between the high and low thresholds , the minimum area of the rectangular frame , maximum area , minimum aspect ratio , maximum aspect ratio , lower limit of the number of intersecting rectangles ; The lower limit of the number of actual scale lines , distance threshold ; Will The number of edge detections is recorded as , and initialized to =1; Step A2: If , then execute step A3; otherwise, it means that Rectangular frame information collection = , and execute step B, wherein, express The total number of rectangular frame information contained, express The Rectangular frame information, and the Rectangular frame information Contains the center coordinates of a rectangular box and its width ,high and rotation angle , ; Step A3: According to 、 ,right Carry out the Second-rate Edge detection, get the Detected edge image ;according to 、 、 、 、 After getting a certain number of rectangular frame information, endowment ,Will endowment , execute step A2; Step B: Elimination The redundant rectangular boxes in the pre-screened rectangular box information set is obtained : Step B1: If The number of elements in is greater than , then from Take out the first rectangular box information , execute step B2, otherwise, obtain the pre-screened rectangular frame information set: , and execute step C, wherein, express Middle Rectangular frame information, express The total number of rectangular frame information included; Step B2: From Find the Number of intersecting rectangles ;like , then execute step B3; otherwise, from Eliminate and After reordering, return to step B1 and execute sequentially; Step B3: The rectangular frame information is sorted in descending order according to the area of its own rectangular frame, and the first The rectangular frame information of the bit is stored in ; then Rectangular frame information from Eliminate and After reordering, return to step B1 and execute sequentially; Step C: Extraction After sorting the real scale in the , we can get the ordered real scale line fitting rectangle information set ; Step C1: If If it is empty, go to step C4, otherwise go to step C2; Step C2: From Take out the first rectangular box information ,Pass The center coordinates of Draw a straight line parallel to the long side of its own rectangle , thus calculating the center of the circle To the straight line distance , calculate the center of the circle arrive distance , calculate the direction of the center of the circle The angle between the vector of the circle and the vector pointing to the right horizontally ; Step C3: If , then 、 、 Deposit as a whole , and from After removing from the list, execute step C1, otherwise, directly from Remove it and execute step C1; Step C4: From Find the distance from the center of the circle to the center coordinate with the highest frequency A rectangular frame will be right After the rectangular boxes are arranged in descending order, the ordered real scale line fitting rectangular box information set is obtained. : ;in, express Middle Rectangular frame information, express points within To the center distance, Indicates the direction of the center of the circle points within The angle between the vector and the horizontal rightward vector of the center of the circle; Step 7. Based on the distance method, the straight line equation is fitted according to the pointer Get in sequence Dial reading ; Step 8. Dial reading Perform linear operations to obtain the final reading of the instrument image to be tested .
2. The nested non-uniform scale dial reading method based on machine vision according to claim 1 is characterized in that: The step 1 comprises the following steps: Step 1.1: Collect nested non-uniform scale instrument images in the substation to construct an instrument image set ; Step 1.2: Instrument image collection The instrument area in the image is marked to obtain a set of instrument images with labels. ; Step 1.3: Collect the labeled instrument images Input into the improved YOLOv5 network for training to obtain the instrument detection model .
3. The nested non-uniform scale dial reading method based on machine vision according to claim 2, characterized in that: The step 4.1 comprises the following steps: Step 4.1.1: Perform binarization to obtain a binary image with a grayscale value of 255 for the edge pixels and a grayscale value of 0 for the rest of the pixels. ; Define and initialize the number of discrete arcs , define and initialize the current point is empty; Step 4.1.2: Scan the binary image in a certain order If the pixel with grayscale value of 255 is scanned, the first pixel with grayscale value of 255 is used as the starting point. , and set the current point Starting point , define and initialize the marker Then, execute step 4.1.3, otherwise, save For each arc segment, execute step 4.2; Step 4.1.3: Assign to , the starting point Join In the arc segment; Step 4.1.4: The grayscale value of the newly added coordinate points in the arc segment is set to 0; Step 4.1.5: Traverse the current point clockwise Among the 4 4-adjacent points, determine whether there is a 4-adjacent point with a grayscale value of 255. If so, set the first 4-adjacent point with a grayscale value of 255 read as the current point. , and the current point Join If there is no arc segment, execute step 4.1.4; if not, execute step 4.1.6; Step 4.1.6: Traverse the current point clockwise Among the four 8-adjacent oblique points, determine whether there is an 8-adjacent oblique point with a grayscale value of 255. If so, set the first 8-adjacent oblique point with a grayscale value of 255 read as the current point. , and the current point Join If there is no arc, execute step 4.1.4; if it does not exist, then determine Is it true? If so, proceed to 4.1.7; Otherwise, proceed to step 4.1.2; Step 4.1.7: Set the starting point For the current point , will order Then, proceed to step 4.1.
5.
4. The nested non-uniform scale dial reading method based on machine vision according to claim 3 is characterized in that: The step 4.2 comprises the following steps: Step 4.2.1: Calculate binary image The horizontal gradient vector of each point in and vertical gradient vector ; The number of arcs traversed is , and initialize ; Define the number of candidate circles as , and initialize , set the maximum number of candidate circles to ;remember The center coordinates are ; recorded as The coordinates of the center of the candidate circle are ; Step 4.2.2: Define and initialize variables ; Record The total number of points in an arc segment is ; Step 4.2.3: The first arc Points are recorded as ; Select any point from other arc segments and record it as , and satisfy: ; from Select the point that satisfies the first change rule As The first change rule is: like , from Change to ; like , from Change to ;in, is a given constant; like In the process of moving along the first change rule, if equation (1) is satisfied, then Set as symmetrical point, and Set as , execute step 4.2.4; otherwise, execute step 4.2.8; (1) In formula (1), 、 Respectively 、 The horizontal gradient vector, 、 Respectively 、 The vertical gradient vector of Step 4.2.4: and its symmetric point Substituting into formula (2), we can get Middle The coordinates of candidate circle centers and its corresponding radius : (2) In formula (2), int() represents the rounding operation; Step 4.2.5: If , then Assign to , on the contrary, Assign to ; like , then endowment If yes, go to step 4.2.6; otherwise, go to step 4.2.7; Step 4.2.6: If , then execute step 4.2.4; otherwise, save The coordinates of candidate circle centers; Step 4.2.7: If , then endowment Then, execute step 4.2.3; otherwise, judge If so, endowment Then, execute step 4.2.2, otherwise, save The coordinates of candidate circle centers and Assign to ; Step 4.2.
8. Select any point from other arc segments and record it as , and satisfy: ; from Select the point that satisfies the second change rule As Another preliminary point, the second change rule is: like , from Change to ; like , from Change to ;in, is a given constant; like In the process of moving along the second change rule, if equation (3) is satisfied, then Set as symmetrical point, and Set to , execute step 4.2.9; otherwise, execute step 4.2.7; (3) In formula (3), 、 Respectively 、 The horizontal gradient vector, 、 Respectively 、 The vertical gradient vector of Step 4.2.9: and its symmetric point Substituting into formula (4), we can get Middle candidate center points and their corresponding radius : (4) Step 4.2.10: If , then Assign to , on the contrary, Assign to ; like , then endowment If yes, go to step 4.2.11; otherwise, go to step 4.2.7; Step 4.2.11: If , then execute step 4.2.9; otherwise, save The center coordinates of the candidate circles.
5. The nested non-uniform scale dial reading method based on machine vision according to claim 4 is characterized in that: The step 7 comprises: Step 7.1: Make a A third mask of the same size, wherein the third mask is made by is the center of the circle and the radius is The circle area is set to white, and the rest of the area is set to black; Step 7.2: Place the third mask with Perform bitwise AND operation to obtain a circular instrument image ,and The coordinate points within Coordinate points of the inner rectangle and the equation of the fitted line with the pointer The coordinate point of Step 7.3: Create The dial polar coordinate system is the origin and the horizontal right is the polar axis; Step 7.4: Expand the dial polar coordinate system to the set size The horizontal axis of the rectangular area is denoted as , the vertical axis of the rectangular area is denoted as ; Use formula (1) to convert the dial polar coordinate system into The coordinates of any point in Map to the rectangular area and get the corresponding new coordinate point ; Thus, all new coordinate points constitute an ordered real scale line fitting rectangle information set , and get the new pointer fitting straight line equation ;in, Indicates the new pointer fitting line equation axis coordinates; (1) In formula (2), is the width of the rectangular area, is the height of the rectangular area, and 、 ; Step 7.5: Based on the known instrument range, we can get The absolute value of the difference between adjacent scale readings ; Step 7.6: Use formula (2) to calculate Dial reading ; (2) In formula (2), Indicates the The equation of the straight line from the scale line to the new pointer distance, and , Indicates the The equation of the straight line from the scale line to the new pointer distance, and ,in, yes Middle The coordinates of the center of the fitted rectangle of each scale line on the horizontal axis; yes Middle The coordinates of the center of the fitted rectangle of each tick mark on the horizontal axis.
6. An electronic device comprising a memory and a processor, characterized in that: The memory is used to store a program that supports the processor to execute the nested non-uniform scale dial meter reading method according to any one of claims 1 to 5, and the processor is configured to execute the program stored in the memory.
Citation Information
Patent Citations
Pointer type instrument reading method and system and inspection robot
CN112257676A
Automatic pointer type instrument reading identification method based on scale searching
CN109993166A
Instrument identification method based on improved u 2 network
WO2024093287A1