An image processing method for tubular level vial angle measurement
Through image processing technology, the automatic measurement of the axial movement distance of the tubular level bubble is realized, which solves the problems of large errors and low efficiency in manual measurement, improves measurement accuracy and efficiency, and is suitable for machine vision.
Patent Information
- Application Number
- CN202411463434.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-21
- Publication Date
- 2025-10-24
- Estimated Expiration
- 2044-10-21
AI Technical Summary
In the prior art, there are few automatic measurement methods for the axial movement distance of a tubular vial bubble, and manual measurement results in large errors. Image processing methods fail to effectively consider the impact of the vial tilt on the measurement results.
The image processing method is used to automatically measure the axial movement distance of the bubble through binarization, line search, tilt correction and pixel distance calculation, avoiding manual intervention and improving measurement accuracy and efficiency.
It enables non-contact automatic measurement, reduces human error, improves measurement accuracy and efficiency, and lowers labor costs for enterprises. It is suitable for machine vision automatic measurement.
Smart Images

Figure CN119359810B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image processing, in particular to an image processing method for calculating the axial movement of a tubular bubble level. BACKGROUND
[0002] A level is a measuring instrument that uses the principle of liquid level to directly display the angular displacement of the bubble level, and measures the relative horizontal position, vertical position and inclination position of the measured surface. The measurement accuracy of the angular value directly affects the measurement effect of the level. According to the national standard GB / T1146-2009, the definition of the angular value of the tubular bubble level is "the inclination angle of the bubble level when the bubble moves 2mm along the axis". In order to obtain this inclination angle, the distance of the bubble moving along the axis needs to be accurately obtained.
[0003] At present, there are few automatic measurement methods for the axial movement distance of the bubble in the bubble level at home and abroad, and most of them still use manual methods, and a small part uses image processing technology, but there are still drawbacks. For example, in the "Level Bubble Offset Detection System Based on Image Processing" by Shan Xiaohang, the bubble offset is measured by using an edge recognition method, but the disadvantage is that the inclination of the bubble level is not considered. Therefore, it is necessary to provide a novel image processing method for measuring the axial movement of the bubble in the tubular bubble level to improve the measurement accuracy and efficiency of the axial movement distance of the bubble. SUMMARY
[0004] In view of the deficiencies in the background art, the purpose of the present application is to provide an image processing method for measuring the axial movement distance of the bubble in the tubular bubble level, which can correct the inclination of the bubble level while avoiding manual intervention, and improve the measurement accuracy and efficiency.
[0005] To achieve the above-mentioned purpose, the present application adopts the following technical solutions:
[0006] An image processing method for measuring the angular value of a tubular bubble level is implemented according to the following steps:
[0007] Step S1: performing binaryzation processing on the original image of the tubular bubble level to obtain a binary image bw;
[0008] Step S2: performing a first line search in the binary image bw to obtain two lines of the tubular bubble level;
[0009] Step S3: performing inclination correction on the binary image bw according to the direction angle of the two lines to obtain an inclination-corrected binary image rtBw;
[0010] Step S4: performing a second line search in the binary image rtBw to obtain the two centroids and two minimum circumscribed regular rectangles of the left and right line respectively;
[0011] Step S5: determining a bubble left endpoint search area based on the two minimum circumscribed rectangles of the left and right engraved lines, and obtaining the bubble left endpoint by searching;
[0012] Step S6: Calculate the image distance from the left endpoint of the bubble to the main axis of the left scale line, and then use the pixel equivalent to further calculate the physical distance from the left endpoint of the bubble to the main axis of the left scale line;
[0013] Step S7: collecting an image of the vial when the bubble is at its initial position and an image of the vial when the bubble is moved, and calculating the distance the bubble has moved along the axial direction.
[0014] The steps of obtaining the two engraved lines of the tubular vial in step S2 specifically include the following steps:
[0015] Step S21: using the run length encoding concept to search for zero runs in the binary image bw, and retaining zero runs whose lengths meet the set conditions; the zero runs are a set of pixels in a row of pixels in the binary image bw where the grayscale values of consecutive pixels are all 0;
[0016] Step S22: construct a zero-stroke image with the same size as the binary image bw and a black background, and set the grayscale value of all pixels with zero stroke that meet the conditions to 255;
[0017] Step S23: perform contour search in the 0-stroke image, calculate the area and direction angle of the area corresponding to each contour, and determine the contour whose direction angle meets the set conditions as the candidate scribed line contour; the specific process of calculating the direction angle of the area corresponding to the contour is: let contour C i The pixels in the corresponding area are p1(x1,y1),p2(x2,y2),…,p m (x m ,y m ), m is the number of pixels, then the contour C i The centroid coordinates of the corresponding area (x c ,y c ) can be calculated by the following two formulas:
[0018] x c =(x1+x2+…+x m ) / m
[0019] y c =(y1+y2+…+y m ) / m
[0020] Then calculate a, b and c using the following three formulas:
[0021] a = (x1x1 + x2x2 +... + x m x m ) / m-x c x c
[0022] b = 2[(x1y1 + x2y2 +... + x m y m ) / m-x c y c ]
[0023] c = (y1y1 + y2y2 +... + y m y m ) / m-y c y c
[0024] Finally, the contour C is calculated by a, b and c i The direction angle θ of the corresponding area is: θ = arctan[b / (a-c)] / 2, and its range is (-90°, 90°];
[0025] Step S24: The candidate graduation line contours are arranged in descending order according to the areas of the corresponding areas of the candidate graduation line contours;
[0026] Step S25: The two contours arranged at the front are taken as the graduation line contours, and two graduation lines of the tubular bubble level are obtained.
[0027] In step S3, the specific steps of the tilt correction of the binary image bw are as follows:
[0028] Step S31: The mean value θ L =(θ R +θ mean ) / 2 of the direction angle θ L of the left graduation line and the direction angle θ R of the right graduation line is calculated;
[0029] Step S32: The correction angle α is calculated:
[0030]
[0031] Step S33: The correction matrix M is constructed:
[0032] Where (x img , y img ) is the center coordinate of the binary image bw;
[0033] Step S34: The pixel coordinates in the binary image bw are converted by using the correction matrix M:
[0034] Wherein (x, y) is the pixel coordinate in the binary image bw; (x', y') is the pixel coordinate in the corrected image rtBw0, the pixel value corresponding before and after coordinate transformation remains unchanged;
[0035] Step S35: using the mean value interpolation method to normalize the pixel in the corrected image rtBw0 to the integer coordinate, taking (x img ,y img ) as the center, and the region with the same size as the binary image bw, to obtain the final corrected image rtBw, wherein (x img ,y img ) is the center of the binary image bw.
[0036] The specific method of searching for the left end point of the bubble in step S5 is: in the left end point search area range of the bubble in the inclined corrected binary image rtBw, the first pixel value of 0 searched in the order from bottom to top and from left to right is taken as the left end point of the bubble.
[0037] The left graduation line main axis in step S6 is a straight line passing through the centroid of the left graduation line and being in a vertical state; the calculation method of the pixel equivalent is: using the physical distance of the left and right graduation lines, divided by the absolute value of the difference of the horizontal coordinates of the centroids of the left and right graduation lines obtained in step S4, to obtain the pixel equivalent, with the unit of mm / px.
[0038] The specific method of step S7 for calculating the distance of the bubble moving along the axial direction is: by collecting the bubble level bubble image at the initial position and the bubble level bubble image at the position after the bubble moves, using steps 1 to 6 to process the two collected bubble level bubble images respectively, to obtain the physical distance from the left end point of the bubble to the left graduation line main axis, and the absolute value of the difference of the two is the distance of the bubble moving along the axial direction.
[0039] Compared with the background art, the gain effect of the present application is:
[0040] 1. The present application realizes non-contact automatic measurement of the axial distance from the left end point of the bubble to the graduation line of the tubular bubble level by using image processing technology, which can effectively avoid large measurement errors caused by human factors compared with manual measurement.
[0041] 2. The present application performs one-time tilt correction on the bubble level image according to the direction angle of the graduation line, which can eliminate the measurement error caused by the tilt of the bubble level compared with directly measuring the bubble level image, solves the drawbacks of other image processing methods, and makes the result more accurate.
[0042] 3. The level bubble end point acquisition of the present application is obtained by acquiring the centroid of the left and right scale lines and the circumscribed rectangle, which can more accurately determine the axial distance from the left end point of the bubble to the left scale line main shaft than searching the entire image, laying a foundation for obtaining more accurate angle values.
[0043] 4. Compared with other image processing methods, the present application completely eliminates the problems of time-consuming, laborious and poor reliability caused by manual intervention. The method can be applied to machine vision to automatically measure the level bubble angle value instead of human beings, greatly improving the measurement efficiency and reducing the labor cost of related enterprises. BRIEF DESCRIPTION OF DRAWINGS
[0044] Figure 1 is an image processing flowchart;
[0045] Figure 2 is a tubular level bubble original image;
[0046] Figure 3 is a tubular level bubble binary image;
[0047] Figure 4 is a 0-stroke result image with a length meeting the set condition;
[0048] Figure 5 is a candidate scale line detection result schematic diagram;
[0049] Figure 6 is a schematic diagram of two scale lines obtained by the first search;
[0050] Figure 7 is a binary image after inclination correction;
[0051] Figure 8 is the left and right scale lines obtained by the second search;
[0052] Figure 9 is a bubble left end point search area schematic diagram;
[0053] Figure 10 is the left scale line main shaft and bubble left end point marking result. DETAILED DESCRIPTION
[0054] The present application will be further described below in combination with the drawings and specific embodiments (examples), but it is not used as the basis for limiting the present application.
[0055] As shown in Figure 1 , the steps of the present application method are:
[0056] Step 1: Binaryzation processing of the tubular level bubble original image
[0057] Read the tubular level bubble original image, and the obtained tubular level bubble original image is as shown inFigure 2 The original image of the tubular vial is binarized using a fixed segmentation threshold, and the resulting tubular vial binary image bw is as follows: Figure 3 As shown, white is the background, and the fixed segmentation threshold adopted is determined according to experiments. In this embodiment, the segmentation threshold is set to 150.
[0058] Step 2: Perform the first line search and obtain two lines
[0059] Using the idea of run length encoding, we search for zero runs consisting of pixels with consecutive grayscale values of 0 in the binary image bw, and retain zero runs with a length within a certain interval. In this embodiment, the length interval is [16, 30], and the length unit is px. This interval is determined experimentally based on actual needs. Then, we construct a zero run image with the same size as the binary image bw and a black background. We set the grayscale value of all pixels in the zero run that meet the length requirement to 255, as shown in the following example: Figure 4 shown.
[0060] Contour search is performed in the 0-stroke image. The area and direction angle of the area corresponding to each contour are calculated. The contours whose direction angles meet the set conditions are determined as candidate scribed line contours. The candidate scribed line contours are sorted in descending order according to the area of the area corresponding to the candidate scribed line contours. The two contours arranged in the front are taken as the scribed line contours to obtain the two scribed lines of the tubular vial. The candidate scribed line detection results are shown as follows: Figure 5 shown.
[0061] The specific process of calculating the direction angle of the area corresponding to the contour is: let the contour C i The pixels in the corresponding area are p1(x1,y1),p2(x2,y2),…,p m (x m ,y m ), m is the number of pixels, then the contour C i The centroid coordinates of the corresponding area (x c ,y c ) can be calculated by formula (1) and formula (2):
[0062] x c =(x1+x2+…+x m ) / m (1)
[0063] y c =(y1+y2+…+y m ) / m (2)
[0064] Then a, b and c are calculated using equations (3), (4) and (5):
[0065] a=(x1x1+x2x2+…+x m xm ) / m-x c x c (3)
[0066] b = 2[(x1y1+x2y2+…+x m y m ) / m-x c y c ] (4)
[0067] c = (y1y1+y2y2+…+y m y m ) / m-y c y c (5)
[0068] Finally, the profile C is calculated by a, b and c i The direction angle θ of the corresponding area is:
[0069] θ=arctan[b / (a-c)] / 2,
[0070] which ranges from (-90°, 90°].
[0071] In this embodiment, the condition for determining the direction angle of the candidate ruling profile is: 45°<θ≤90° and -90°<θ<-45°.
[0072] Step 3: According to the direction angles of the two ruling lines, the binary image is corrected for inclination
[0073] First, the mean value θ mean of the left ruling line direction angle θ L and the right ruling line direction angle θ R is calculated by formula (6):
[0074] θ mean = (θ L + θ R ) / 2 (6)
[0075] Secondly, the correction angle α is calculated by formula (7):
[0076]
[0077] Then, the correction matrix M is constructed by formula (8):
[0078]
[0079] where (x img ,y img ) is the center coordinate of the binary image bw. The pixel coordinates in the binary image bw are converted by formula (9) using the correction matrix M:
[0080]
[0081] where (x, y) is the pixel coordinate in the binary image bw; (x', y') is the pixel coordinate in the corrected image rtBw0, and the pixel values before and after the coordinate transformation remain unchanged.
[0082] Finally, the pixel in the corrected image rtBw0 is normalized to an integer coordinate by using the mean value interpolation method, and a region with the same size as the binary image bw is taken as the center of (x img ,y img ), to obtain the final corrected image rtBw, where (x img ,y img ) is the center of the binary image bw. The final corrected image rtBw is shown in Figure 7 .
[0083] Step 4: Perform a second line search to obtain the centroids and circumscribed rectangles of the left and right lines
[0084] In the corrected image rtBw, a second line search is performed to obtain two centroids of the left and right lines and the minimum circumscribed rectangles of the two lines. The centroids and circumscribed rectangles of the left and right lines obtained by the second search are shown in Figure 8 , where the centroid of the line is represented by “×”.
[0085] Step 5: Determine the bubble left endpoint search area and obtain the bubble left endpoint
[0086] The right upper corner point P1 and the right lower corner point P2 of the minimum circumscribed rectangle of the left line and the left upper corner point P3 and the left lower corner point P4 of the minimum circumscribed rectangle of the right line obtained in step 4 are obtained, and then the minimum circumscribed rectangle bRect of the four corner points P1, P2, P3 and P4 is constructed. The upper half of the minimum circumscribed rectangle bRect is obtained, and the upper edge is moved downward by a set distance, which is set to 6 pixels in this embodiment. The obtained rectangular region is the bubble left endpoint search area bubRect. The schematic diagram of the bubble left endpoint search area is shown in Figure 9 .
[0087] In the bubble left endpoint search area bubRect in the corrected image rtBw, the first pixel with a gray value of 0 obtained in the order from bottom to top and from left to right is the bubble left endpoint. The bubble left endpoint marking result is shown in Figure 10 with a circle and a “×” mark.
[0088] Step 6: Determine the physical distance from the bubble left endpoint to the left line main axis
[0089] The image distance d from the bubble left endpoint to the left line main axis is calculatedimg (unit: mm / px), and then the pixel equivalent v px (unit: mm / px) is calculated by formula (10) real (unit: mm):
[0090] d real = d img × v px (10)
[0091] wherein the pixel equivalent v px is calculated by formula (11)
[0092] v px = d Lreal / d Limg (11)
[0093] wherein d Lreal is the physical distance between the left and right graduation lines of the bubble (unit: mm), and d Limg is the absolute value of the difference between the horizontal coordinates of the centroids of the left and right graduation lines obtained in step 4 (unit: px).
[0094] The main axis of the left graduation line is a straight line passing through the centroid of the left graduation line and in a vertical state, as shown by the middle vertical line of the left graduation line in Figure 10 .
[0095] In this embodiment, the pixel equivalent v px = 0.028 mm / px, and the physical distance d real = 2.575 mm from the left end point of the bubble to the main axis of the left graduation line.
[0096] Step 7: Calculate the axial moving distance of the bubble of the bubble level
[0097] By collecting the bubble level image of the bubble in the initial position and the bubble level image of the bubble in the position after moving, the two bubble level images collected are processed by steps 1 to 6, respectively, to obtain the physical distances from the left end point of the bubble to the main axis of the left graduation line, and the absolute value of the difference between them is the axial moving distance of the bubble.
[0098] The above merely describes the preferred embodiments of the present application, but the protection scope of the present application is not limited thereto, and any changes or replacements within the technical scope disclosed by the present application can be easily thought of by those skilled in the art, which should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. An image processing method for tubular vial bubble angle measurement, characterized by: The method comprises the following steps: Step S1: binaryzation processing is performed on the tubular bubble original image to obtain a binary image bw; Step S2: a first line search is performed on the binary image bw to obtain two lines of the tubular bubble; Step S3: according to the direction angle of the two lines, the binary image bw is subjected to an inclination correction to obtain a binary image rtBw after the inclination correction; Step S4: a second line search is performed on the binary image rtBw to obtain two centroids and two minimum circumscribed rectangles of the left line and the right line respectively; Step S5: the left end point search area of the bubble is determined according to the two minimum circumscribed rectangles of the left line and the right line, and the left end point of the bubble is searched; Step S6: the image distance from the left end point of the bubble to the main axis of the left line is calculated, and then the pixel equivalent is used to further calculate the physical distance from the left end point of the bubble to the main axis of the left line; Step S7: the bubble image at the initial position and the bubble image at the position after the bubble moves are collected, and the distance of the bubble moving along the axial direction is calculated; In the step S2, the specific steps for obtaining the two lines of the tubular bubble include: Step S21: the 0 run in the binary image bw is searched by using the run length encoding idea, and the 0 run with a length meeting the set condition is retained; Step S22: a 0 run image with the same size as the binary image bw and a black background is constructed, and the gray value of all pixels of the 0 run meeting the condition is set to 255; Step S23: contour finding is performed on the 0 run image, the area and the direction angle of the region corresponding to each contour are calculated, and the contour with the direction angle meeting the set condition is determined as the candidate line contour; Step S24: the candidate line contour is arranged in descending order according to the area of the region corresponding to the candidate line contour; Step S25: the two contours arranged at the front are taken as the line contours, and the two lines of the tubular bubble are obtained; In the step S3, the specific steps for performing the inclination correction on the binary image bw include: Step S31: Calculate the average of the left ruling direction angle θ L and the right ruling direction angle θ R θ mean =(θ L +θ R ) / 2; Step S32: the correction angle α is calculated: Step S33: the correction matrix M is constructed: where (x img ,y img ) are the center coordinates of the binary image bw; Step S34: the pixel coordinates in the binary image bw are converted by using the correction matrix M: where (x, y) is the pixel coordinate in the binary image bw; (x', y') is the pixel coordinate in the corrected image rtBw0, the pixel values corresponding before and after the coordinate transformation remain unchanged; Step S35: using mean value interpolation method to regularize the pixels in the corrected image rtBw0 to integer coordinates, taking the region with (x img ,y img ) as the center and with the same size as the binary image bw to obtain the final corrected image rtBw, wherein (x img ,y img ) is the center of the binary image bw; In the step S5, the specific steps for determining the left end point search area of the bubble include: Step S51: the right upper corner point P1 and the right lower corner point P2 of the minimum circumscribed rectangle of the left line and the left upper corner point P3 and the left lower corner point P4 of the minimum circumscribed rectangle of the right line obtained in the step S4 are obtained; Step S52: the minimum circumscribed rectangle bRect of the four corner points P1, P2, P3 and P4 is constructed; Step S53: the upper half of the minimum circumscribed rectangle bRect is obtained, and the upper edge thereof is moved downward by a set distance, and the obtained rectangular area is the left end point search area of the bubble.
2. The image processing method for measuring the angle value of the tubular bubble according to claim 1, characterized in that: In the step S21, the 0 run is a pixel set in which the gray values of the continuous pixels in a row of the binary image bw are all 0.
3. The image processing method for measuring the angle value of the tubular bubble according to claim 1, characterized in that: The specific process of calculating the direction angle of the region corresponding to the contour C in step S23 is as follows: assuming that the contour C is C(x, y), the region corresponding to the contour C is R(x, y), and the direction angle of the region R(x, y) is θ, then the specific process is as follows: i The pixels of the region corresponding to the contour are p1(x1, y1), p2(x2, y2), …, p m (x m ,y m ), and m is the number of pixels, then the contour C i The centroid coordinates (x c ,y c ) of the region corresponding to the contour C can be calculated by the following two formulas: x c = (x1+x2+…+x m ) / m y c = (y1 + y2 +... + y m ) / m Then a, b and c are calculated by the following three equations: a = (x1x1 + x2x2 +... + x m x m ) / m-x c x c b = 2[(xl yl + x2y2+... + xnyn) / m - x m y m ) / m - x c y c ] c = (y1y1 + y2y2 +... + y m y m ) / m - y c y c Finally, the profile C is calculated from a, b and c i The orientation angle Θ of the corresponding area is Θ = arctan[b / (a-c)] / 2, which ranges from (-90°, 90°].
4. The image processing method for measuring the angle of a tubular vial according to claim 1, characterized in that: In step S5, the specific method for searching the left end point of the bubble is as follows: in the left end point searching area of the bubble in the binary image rtBw after the inclination correction, the first pixel with a pixel value of 0 is searched in the order from bottom to top and from left to right, and the position of the pixel is the left end point of the bubble.
5. The image processing method for measuring the angle of a tubular vial according to claim 1, characterized in that: In step S6, the left graduation main axis is a straight line passing through the center of the left graduation and in a vertical state.
6. The image processing method for measuring the angle of a tubular vial according to claim 1, characterized in that: In step S6, the calculation method of the pixel equivalent is as follows: the physical distance between the left and right graduations is divided by the absolute value of the difference between the horizontal coordinates of the centers of the left and right graduations obtained in step S4 to obtain the pixel equivalent, which is in the unit of mm / px.
7. The image processing method for measuring the angle of a tubular vial according to claim 1, characterized in that: In step S7, the specific method is as follows: two vial images are collected, one of which is when the bubble is in the initial position and the other of which is when the bubble is in the moved position, and steps 1 to 6 are used to process the two collected vial images respectively to obtain the physical distances from the left end point of the bubble to the left graduation main axis, and the absolute value of the difference between the two distances is the distance of the bubble moving along the axial direction.
Citation Information
Patent Citations
Level bubble scribed line width measuring method based on image processing technology
CN109883396A
Tubular level position precision measuring method based on image processing
CN113124898A