Camera vision automated alignment of volumetric flask reticle methods, systems, devices, and media
By detecting the vertices of the upper and lower enclosure lines and the size of the enclosure openings in the grayscale image of the volumetric flask, and adjusting the camera position based on the cumulative number of times, the problem of accuracy and efficiency in aligning volumetric flask markings with industrial cameras was solved, achieving fast and accurate visual alignment.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- 青海省计量检定测试院
- Filing Date
- 2025-08-21
- Publication Date
- 2026-04-21
AI Technical Summary
In existing technologies, industrial cameras are easily affected by image noise when automatically aligning volumetric flask markings, leading to inaccurate measurements and increased processing time, making it difficult to quickly and accurately align the camera visually with the volumetric flask markings.
By acquiring grayscale images of volumetric flasks, the upper and lower vertices of the enclosure are detected within the region of interest. The size of the enclosure opening is detected by accumulating grayscale gradients along the vertical rows. Combining the size of the enclosure opening and the number of accumulations, different movement strategies are used to adjust the camera position until a level view is achieved.
This technology enables rapid and accurate alignment of volumetric flask markings even under noise interference, improving detection accuracy and efficiency while avoiding resource consumption and failure risks associated with image preprocessing.
Smart Images

Figure CN121053205B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of automatic measurement technology, specifically relating to a method, system, device, and medium for automatically aligning volumetric flask markings using camera vision. Background Technology
[0002] A volumetric flask is a measuring instrument used to accurately measure a specific volume of solution. During measurement, the correct procedure is to align your line of sight with the mark on the volumetric flask on the same horizontal plane; otherwise, angular parallax will occur, leading to inaccurate measurements.
[0003] In existing technologies, industrial cameras are used to replace human eyes in the measurement of solutions in volumetric flasks, achieving full automation. For example, Chinese patent CN113375749A uses an industrial camera to capture images of the bottle neck at different heights. Edge detection methods are used to detect the upper and lower contours of the markings in the bottle neck image. The vertex distance of the upper and lower contours is calculated based on the simulated curves of the contours. Then, based on the aperture imaging model and data from the two images, the camera's eye level is predicted, and the camera is moved to that height. Finally, the curvature of the simulated curves of the upper and lower contours and the vertex distance are detected again. When the curvature is close to 0 or the distance is less than the marking width threshold, it is determined that the camera has reached the actual eye level. However, this method is highly susceptible to image noise, producing false edge points that affect the accuracy of subsequent simulated curves. Therefore, image preprocessing and data filtering are often required, which not only increases resource consumption and time but also increases processing difficulty and the risk of failure.
[0004] Therefore, current automated metering processes cannot quickly and accurately align industrial cameras with the markings on volumetric flasks. Summary of the Invention
[0005] The purpose of this invention is to provide a method, system, electronic device, and storage medium for automatically aligning the markings on a volumetric flask using camera vision, for quickly and accurately aligning the markings on the volumetric flask using camera vision.
[0006] The first aspect of this invention discloses a method for automatically aligning volumetric flask markings using camera vision, comprising:
[0007] Acquire grayscale images of volumetric flasks;
[0008] Bottlenecks are detected and regions of interest are constructed on the grayscale image;
[0009] In the region of interest, the upper and lower boundary vertices are detected based on the cumulative gray-scale gradient of the vertical rows, and the boundary opening size is calculated based on the upper and lower boundary vertices.
[0010] When the size of the enclosure opening is less than or equal to the preset minimum size of the enclosure opening, it is determined that the camera has reached the eye level position. Otherwise, when the size of the enclosure opening is less than or equal to the maximum size of the enclosure opening, it is determined that the current enclosure opening is a reasonable enclosure opening. Based on the cumulative number of reasonable enclosure openings, the size of the enclosure opening and the size of the enclosure opening when it was last determined to be a reasonable enclosure opening, the camera's moving direction and moving distance are determined. The camera is moved according to the moving direction and moving distance, and the process returns to the step of acquiring the grayscale image of the volumetric flask, until it is determined that the camera has reached the eye level position or that the camera has failed to approach the eye level position.
[0011] In some embodiments, determining the camera's movement direction and distance based on the cumulative number of reasonable enclosure openings, the size of the enclosure opening, and the size of the enclosure opening when it was last determined to be a reasonable enclosure opening includes:
[0012] If the cumulative number is 1, the camera moves upward based on a preset first moving distance;
[0013] If the cumulative number is 2, calculate the distance and direction of the horizontal position relative to the current position based on the size and height of the enclosure opening at the current and previous times, and obtain the moving distance and the moving direction;
[0014] If the cumulative count is 3, when it is determined that the current position is close to the eye level, the movement direction is determined according to the size and height of the enclosure opening of the current and previous times, and the movement distance is the preset second movement distance. Otherwise, the current enclosure opening is determined to be invalid, the cumulative count is decremented by 1, the movement direction is the opposite of the previous movement direction, and the movement distance is the difference between the previous movement distance and the preset second movement distance.
[0015] If the cumulative number of times is greater than or equal to 4, and if the current enclosure opening size is smaller than the previous enclosure opening size, the movement direction is the same as the previous movement direction, and the movement distance is a preset third movement distance. Otherwise, if the current enclosure opening size is greater than the minimum of all previous enclosure opening sizes and does not exceed the preset maximum cumulative number of times, the movement direction is the opposite of the previous movement direction, and the movement distance is a preset fourth movement distance. Otherwise, the camera is deemed to have failed to approach the eye level position.
[0016] In some embodiments, calculating the distance and direction of the horizontal position relative to the current position based on the current and previous enclosure opening size and position height includes:
[0017] Calculate the linear change slope based on the current and previous enclosure opening size, position, and height;
[0018] Calculate the difference between the size of the enclosure opening and the minimum size of the enclosure opening, and multiply the difference by the linear change slope to obtain the distance;
[0019] Calculate the first difference between the current enclosure opening size and the previous enclosure opening size, and the second difference between the current position height and the previous position height. If both the first and second differences are positive or both are negative, set the direction to move downward; otherwise, set the direction to move upward.
[0020] In some embodiments, detecting the upper and lower boundary vertices in the region of interest based on the cumulative gray-level gradient of the vertical rows includes:
[0021] The grayscale value of each row of pixels is accumulated within the region of interest to obtain the row grayscale value of each row, and the row grayscale values of all rows are arranged into a number column according to the vertical axis.
[0022] The first-order discrete derivative and absolute value of the sequence are used to obtain the row grayscale gradient of each row.
[0023] Search the sequence from front to back, and set the ordinate of the first row with a grayscale gradient greater than or equal to the gradient threshold as the vertex of the upper boundary. Search the sequence from back to front, and set the ordinate of the first row with a grayscale gradient greater than or equal to the gradient threshold as the vertex of the lower boundary.
[0024] In some embodiments, after obtaining the upper and lower boundary vertices, the method further includes:
[0025] Calculate the first difference between the ordinate of the lower boundary vertex and the upper edge of the region of interest, and calculate the second difference between the ordinate of the lower edge of the region of interest and the upper boundary vertex.
[0026] When the first difference is less than the maximum value of the enclosure opening, it is determined that the enclosure is close to the upper edge, and the camera is moved upward based on a preset distance to return to the step of acquiring the grayscale image of the volumetric flask;
[0027] When the second difference is less than the maximum value of the enclosure opening, it is determined that the enclosure is near the lower edge, and the camera is moved downward based on a preset distance to return to the step of acquiring the grayscale image of the volumetric flask.
[0028] In some embodiments, when it is determined that the current enclosure opening is an unreasonable enclosure opening, the region of interest in the grayscale image is subjected to enhanced frequency domain processing, the upper enclosure vertex and the lower enclosure vertex are re-detected, and when the number of re-detections reaches the set maximum number, the camera is moved and the process returns to the step of acquiring the grayscale image of the volumetric flask.
[0029] In some embodiments, detecting bottlenecks and constructing regions of interest on the grayscale image includes:
[0030] The first edge point of each row is detected from left to right on the grayscale image. For the first edge points of all rows, the Hough transform method is used to detect whether there is a first vertical line.
[0031] The first second edge point of each row is detected from right to left on the grayscale image. For the second edge points of all rows, the Hough transform method is used to detect whether there is a second vertical line.
[0032] When both the first vertical line and the second vertical line exist and the distance between the first vertical line and the second vertical line is less than the maximum line distance, a bottleneck is detected, and the minimum bounding rectangle of all the first edge points used to construct the first vertical line and all the second edge points used to construct the second vertical line is set as the region of interest.
[0033] A second aspect of this invention discloses a camera-based vision-based automatic alignment system for volumetric bottle markings, comprising:
[0034] The acquisition module is used to acquire grayscale images of volumetric flasks;
[0035] A bottleneck identification module is used to detect bottlenecks and construct regions of interest on the grayscale image.
[0036] The enclosure opening detection module is used to detect the upper enclosure vertex and the lower enclosure vertex in the region of interest based on the cumulative gray-scale gradient of the vertical row, and calculate the enclosure opening size based on the upper enclosure vertex and the lower enclosure vertex;
[0037] The eye-level position approximation module is used to determine that the camera has reached the eye-level position when the size of the enclosure opening is less than or equal to a preset minimum enclosure opening value; otherwise, when the size of the enclosure opening is less than or equal to the maximum enclosure opening value, the current enclosure opening is determined to be a reasonable enclosure opening. Based on the cumulative number of reasonable enclosure openings, the size of the enclosure opening, and the size of the enclosure opening when it was previously determined to be a reasonable enclosure opening, the camera's movement direction and movement distance are determined. The camera is moved according to the movement direction and movement distance, and the process returns to the step of acquiring the grayscale image of the volumetric flask, until it is determined that the camera has reached the eye-level position or that the camera has failed to approach the eye-level position.
[0038] A third aspect of the present invention discloses an electronic device, including a memory storing executable program code and a processor coupled to the memory; the processor calls the executable program code stored in the memory to execute the camera vision automatic alignment method for calibrating volumetric flask markings disclosed in the first aspect.
[0039] The fourth aspect of the present invention discloses a computer-readable storage medium storing a computer program, wherein the computer program causes a computer to execute the camera vision automatic alignment method for volumetric flask markings disclosed in the first aspect.
[0040] The beneficial effects of this invention are that it constructs the region of interest based on the bottleneck, detects the upper and lower boundary vertices based on the cumulative gray-scale gradient of the vertical rows, and uses the size of the boundary opening to characterize the deviation of the industrial camera from the horizontal viewing position, thus avoiding edge detection problems such as large noise influence at the boundary edge, making the detection of the markings more accurate and efficient; and when moving the camera, different movement strategies are adopted in combination with different cumulative times of reasonable boundary opening, which can quickly and accurately align the camera visually with the volumetric bottle markings. Attached Figure Description
[0041] The accompanying drawings illustrate specific examples of the technical solutions described in this invention and, together with the detailed embodiments, form part of the specification, serving to explain the technical solutions, principles, and effects of this invention.
[0042] Unless otherwise specified or defined, the same reference numerals in different figures represent the same or similar technical features, and different reference numerals may be used to represent the same or similar technical features.
[0043] Figure 1 This is a flowchart of a camera vision-based automatic alignment method for volumetric bottle markings according to an embodiment of the present invention;
[0044] Figure 2 This is a schematic diagram of the upper and lower contour lines of an embodiment of the present invention almost overlapping.
[0045] Figure 3 This is a cumulative grayscale projection curve of the vertical row when the upper and lower contour lines of an embodiment of the present invention almost coincide.
[0046] Figure 4 This is a schematic diagram of an embodiment of the present invention where the upper and lower contour lines do not coincide;
[0047] Figure 5 This is a cumulative grayscale projection curve of the vertical row when the upper and lower contour lines do not coincide in an embodiment of the present invention.
[0048] Figure 6 This is a flowchart illustrating the detection of the upper and lower boundary line vertices according to an embodiment of the present invention.
[0049] Figure 7 This is a longitudinal row cumulative grayscale projection curve with high-brightness spot abrupt change characteristics according to an embodiment of the present invention;
[0050] Figure 8This is a flowchart illustrating the determination of the moving direction and moving distance of an industrial camera according to an embodiment of the present invention;
[0051] Figure 9 This is a flowchart illustrating the prediction of the head-up position according to an embodiment of the present invention;
[0052] Figure 10 This is a schematic diagram of the camera vision automatic alignment system for volumetric bottle markings according to an embodiment of the present invention;
[0053] Figure 11 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Detailed Implementation
[0054] Unless otherwise specified or defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art. When combined with the technical solutions of the invention in a real-world scenario, all technical and scientific terms used herein may also have meanings corresponding to the purpose of achieving the technical solutions of the invention. The terms "first," "second," etc., used herein are merely for distinguishing names and do not represent a specific number or order. The term "and / or," as used herein, includes any and all combinations of one or more of the associated listed items.
[0055] It should be noted that when a component is considered "fixed" to another component, it can be directly fixed to the other component or there can be an intervening component; when a component is considered "connected" to another component, it can be directly connected to the other component or there can be an intervening component; when a component is considered "mounted" on another component, it can be directly mounted on the other component or there can be an intervening component; when a component is considered "placed" on another component, it can be directly placed on the other component or there can be an intervening component.
[0056] Unless otherwise specified or defined, the terms "described" or "the" as used herein refer to the technical features or technical content mentioned or described prior to the relevant section, which may be the same as or similar to the technical features or technical content mentioned herein. Furthermore, the terms "comprising" and "having," and any variations thereof, as used herein, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the steps or units listed, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to such processes, methods, products, or apparatus.
[0057] To facilitate understanding of the present invention, specific embodiments of the present invention will be described in more detail below with reference to the accompanying drawings.
[0058] This embodiment provides a method for automatically aligning volumetric flask markings using camera vision, deployed on the control system of an industrial camera. This method is implemented through computer programming. The execution subject of this method can be an electronic device such as a computer, laptop, or tablet, or a control chip embedded in an electronic device; this invention does not limit this.
[0059] like Figure 1 As shown, the specific steps of the camera vision automatic alignment method for volumetric flask markings in this embodiment include:
[0060] Step S100: Acquire a grayscale image of the volumetric flask;
[0061] The initial position of the industrial camera is within the height range of the neck of the volumetric flask, and the specific position is not limited. Images of the volumetric flask are acquired using the industrial camera and converted to grayscale format to obtain a grayscale image. In this embodiment, a white light source is also placed below the volumetric flask to enhance the imaging display of the target contours of the volumetric flask (especially the rear contours away from the industrial camera).
[0062] Step S200: Detect bottlenecks and construct regions of interest on the grayscale image;
[0063] First, the first edge point of each row is detected from left to right on the grayscale image. The Hough transform is then applied to all first edge points in each row to detect the existence of a first vertical line (allowing for small angles of tilt). Similarly, the second edge point of each row is detected from right to left. The Hough transform is then applied to all second edge points in each row to detect the existence of a second vertical line. A bottleneck is considered detected when vertical lines are detected both from left to right and from right to left, and the distance between the first and second vertical lines is less than the maximum line distance; otherwise, no bottleneck is considered to exist in the current image.
[0064] When a bottleneck is detected, the region of interest is constructed using the minimum bounding rectangle of all the first and second edge points used in the Hough transform line. That is, the region of interest of the rectangle is constructed by taking the minimum x-coordinate, minimum y-coordinate, maximum x-coordinate, and maximum y-coordinate of the edge points as the coordinates of the upper left and lower right corners of the rectangle.
[0065] If the current grayscale image does not detect the bottleneck, the industrial camera is moved upward by a specified distance, and the process returns to step S100 to reacquire the image until the bottleneck is detected and the region of interest is constructed.
[0066] This embodiment utilizes the linear profile of the neck of a volumetric flask and employs the Hough transform method to detect the neck in the image, constructing a region of interest. Since this invention uses row cumulative grayscale statistical analysis to detect markings, detecting markings only within the region of interest is more accurate and efficient.
[0067] Step S300: Detect the upper and lower vertices of the contour line in the region of interest based on the cumulative gray-level gradient of the vertical rows, and calculate the size of the contour line opening based on the upper and lower vertices of the contour line.
[0068] The markings are distributed horizontally, while the bottlenecks are distributed vertically. In the image, this is represented by upper and lower borders, which are arranged vertically. The area enclosed by the upper and lower borders is called the border opening. The vertex of the upper border is the highest point on the upper border, and the vertex of the lower border is the lowest point on the lower border. The distance between the vertices of the upper and lower borders is the size of the border opening.
[0069] refer to Figure 2-5 , Figure 2 This is the image when the upper and lower body lines almost coincide. Figure 3 This is the cumulative grayscale projection curve of the vertical row when the upper and lower contour lines almost coincide. Figure 4 This is the image when the upper and lower contour lines do not coincide. Figure 5 This is the cumulative grayscale projection curve for the vertical rows when the upper and lower contour lines do not coincide. Figure 2-5 As can be seen, there is a vertical abrupt change in the cumulative grayscale of the rows. Therefore, this invention utilizes the feature of abrupt changes in the cumulative grayscale of the vertical rows at the markings to detect the markings, which can effectively eliminate image noise interference and eliminate the need for image preprocessing, directly obtaining the distance between the upper and lower boundary vertices of the markings.
[0070] The specific steps for detecting the upper and lower contour vertices in this embodiment are as follows: Figure 6 As shown, it includes:
[0071] Step S310: Accumulate gray values for each row of pixels within the region of interest to obtain the row gray value for each row, and arrange the row gray values of all rows into a sequence according to the vertical coordinate.
[0072] Step S320: Perform first-order discrete differentiation and absolute value calculation on the sequence to obtain the row grayscale gradient of each row;
[0073] Step S330: Search the sequence from front to back, and set the ordinate corresponding to the first row grayscale gradient that is greater than or equal to the gradient threshold as the upper boundary vertex. Search the sequence from back to front, and set the ordinate corresponding to the first row grayscale gradient that is greater than or equal to the gradient threshold as the lower boundary vertex.
[0074] Specifically, within the region of interest, the gray values of all pixels in each row are summed to obtain the row gray value. The row gray values of all rows are then arranged in order of their vertical coordinates to form a sequence. The first-order discrete derivative and absolute value of this sequence are then calculated to obtain the row gray gradient for each row.
[0075] To improve efficiency, before detecting the upper and lower boundary line vertices, it can be determined whether the kurtosis of the row grayscale gradient is greater than the threshold P0. If it is less than P0, it means that no boundary exists. After moving the camera upwards by an arbitrary distance, return to step S100 to re-acquire the grayscale image. If it is greater than P0, it means that a boundary exists, and then the upper and lower boundary line vertices are detected. Specifically: calculate the average gradient M and standard deviation σ of the sequence. Then, search from front to back for the first row grayscale gradient in the sequence that is greater than or equal to the gradient threshold G0 (in this embodiment, G0 is M+σ), and take the ordinate of the row corresponding to the grayscale gradient as the upper boundary line vertex; similarly, search from back to front, and take the ordinate of the row corresponding to the first row grayscale gradient that is greater than or equal to the gradient threshold G0 as the lower boundary line vertex.
[0076] Because the detection results for the opening of the enclosure will be incorrect when the upper enclosure line intersects with or is close to the upper edge of the bottleneck, or when the lower enclosure line intersects with or is close to the lower edge of the bottleneck. Therefore, in some embodiments, before detecting the vertices of the upper and lower enclosure lines, it is first determined whether the enclosure line is close to the edge of the bottleneck. Specifically, the vertex y of the lower enclosure line is calculated. d The first difference between the y-coordinate of the top edge ROI (top) and the y-coordinate of the bottom edge ROI (bot) of the region of interest is calculated, along with the difference between the y-coordinate of the top edge ROI (bot) and the y-coordinate of the top edge vertex. u The second difference between them; when the first difference is less than the maximum opening value D of the enclosure. max When the boundary line is near its upper edge, the camera is moved upwards by a preset distance, and the process returns to step S100 to re-acquire the grayscale image of the volumetric flask; when the second difference is less than the maximum value D of the boundary line opening... max When the boundary line is near its lower edge, the camera is moved downwards by a preset distance, and the process returns to step S100 to re-acquire the grayscale image of the volumetric flask. That is: when y d -ROI(top)≥D max If the condition is not met, determine the nearest upper edge; when ROI(bot)-y u ≥D max If the condition is not met, determine the nearest lower edge; where D max It is the maximum opening of the enclosure, y u and y dThese are the vertices of the upper and lower borders, respectively. ROI(top) and ROI(bot) represent the upper and lower edges of the region of interest, respectively. When the camera is near the upper edge, it should be moved upwards slightly; when near the lower edge, it should be moved downwards slightly to ensure that both the upper and lower borders are fully within the region of interest and can be accurately detected.
[0077] Because the reflection of ambient light by the curved surface of the bottle body easily forms bright spots during imaging, and these spots also exhibit abrupt changes in the accumulated grayscale gradient along the longitudinal lines, this will interfere with the detection of the markings. Therefore, in some embodiments, based on the difference between the abrupt change characteristics of the upper and lower contour lines of the markings and the abrupt change characteristics of the bright spots, the abrupt change characteristics formed by the bright spots are eliminated before the upper and lower contour line vertices are detected. Figure 7 The figure shows the cumulative grayscale projection curve of the vertical row with abrupt changes in brightness spots. Figure 7 The two peaks and troughs adjacent to each other on the left are abrupt changes in the upper and lower contours, while the two peaks in the same direction on the right are abrupt changes in the bright spot. This part needs to be eliminated, for example, by turning this part into a straight line.
[0078] By employing vertical row cumulative grayscale detection of the upper and lower boundary vertices, detection efficiency is significantly improved. However, existing methods, in order to reduce potential noise interference in the outer regions of the boundary lines, use a small region of interest (ROI) to search for the boundary lines by traversing the bottleneck through this ROI. This inevitably leads to time-consuming and inefficient detection, and requires frequent changes to the ROI.
[0079] Step S400: When the size of the enclosure opening is less than or equal to the preset minimum size of the enclosure opening, it is determined that the camera has reached the eye level position. Otherwise, when the size of the enclosure opening is less than or equal to the maximum size of the enclosure opening, it is determined that the current enclosure opening is a reasonable enclosure opening. Based on the cumulative number of reasonable enclosure openings, the size of the enclosure opening and the size of the enclosure opening when it was determined to be a reasonable enclosure opening last time, the camera's movement direction and movement distance are determined. The camera is moved according to the movement direction and movement distance, and the process returns to the step of acquiring the grayscale image of the volumetric flask, until it is determined that the camera has reached the eye level position or the camera has failed to approach the eye level position.
[0080] When the enclosure opening size d is less than or equal to the preset minimum enclosure opening value D min If the camera reaches eye level, the program exits. Otherwise, it continues to execute the following steps to approach eye level:
[0081] First, determine the reasonableness of the enclosure opening, i.e., whether the current enclosure opening is a reasonable enclosure opening. A reasonable enclosure opening should satisfy the following formula: d≤D max Where d represents the size of the opening of the enclosure, Dmax This represents the maximum opening value of the enclosure.
[0082] When the current enclosure opening is determined to be an unreasonable enclosure opening, it indicates an error in the detection result. In this case, the camera can be moved to a new height and the process returned to step S100 to re-acquire a grayscale image; alternatively, enhanced frequency domain processing can be performed on the region of interest in the grayscale image before re-detecting the upper and lower enclosure vertices. Enhanced frequency domain processing methods include frequency domain enhancement and neighborhood enhancement, both aimed at enhancing the grayscale features of the enclosure and reducing background interference. If the enclosure detection result is still unreasonable after image enhancement and the number of re-detections reaches the set maximum (equivalent to the maximum number of enhanced frequency domain processing operations), the camera is moved to a new height, and the process returned to step S100 to re-acquire a grayscale image of the volumetric flask.
[0083] When the enclosure opening is determined to be reasonable, the cumulative number of reasonable enclosure openings indicates different degrees of proximity to the eye level. Generally, the more reasonable enclosure openings there are, the closer to the eye level. Therefore, different approximation strategies are adopted based on the different cumulative numbers of reasonable enclosure openings. That is, the camera's movement direction and distance are determined by comprehensively considering the cumulative number of reasonable enclosure openings, the current size of the enclosure opening, and the size of the enclosure opening when it was last determined to be reasonable. Then, the industrial camera is moved, and the process returns to step S100 to re-acquire the grayscale image of the volumetric flask. When it is determined that the camera has reached the eye level or that the camera has failed to approach the eye level, the program exits. By combining the cumulative number of reasonable enclosure openings, the eye level can be approximated more quickly and accurately.
[0084] This embodiment determines the moving direction and moving distance of the industrial camera. The specific steps are as follows: Figure 8 As shown, it includes:
[0085] Step S410: If the cumulative number of times is 1, move the camera upward based on the preset first moving distance;
[0086] A cumulative count of 1 indicates that no reasonable enclosure opening was detected previously. At this point, the current position is used as the reference height, set to 0, and data such as the current height and the current enclosure opening size are recorded. Then, the camera continues to move, moving a distance movVal = δ. l The direction of movement is movDir='u', where δ l The preset first moving distance is denoted by "u", which represents upward movement, and "d" represents downward movement. In this embodiment, δ l =3mm, which is a large step size for rapid camera movement.
[0087] Step S420: If the cumulative number of times is 2, calculate the distance and direction of the horizontal position relative to the current position based on the current and previous opening size and position height of the enclosure, and obtain the moving distance and moving direction;
[0088] When the camera has not reached the eye level, after detecting two reasonable openings in the enclosure, the eye level position can be predicted based on the size and height of the openings from the two detections. The moving distance and direction can then be obtained, and the camera can be moved to approach the eye level position.
[0089] The specific steps for predicting the eye-level position in this embodiment are as follows: Figure 9 As shown, it includes:
[0090] Step S421: Calculate the linear change slope based on the current and previous enclosure opening size and position height;
[0091] Step S422: Calculate the difference between the size of the enclosure opening and the minimum size of the enclosure opening, and multiply the difference by the slope of the linear change to obtain the distance;
[0092] The prediction model for eye level is: δh=(d i -D min Slope(H, d), where δh is the height of the industrial camera relative to the eye level, i.e., the calculated distance movVal; H is an array of heights of the industrial camera relative to the reference position, including the heights of all reasonable enclosure openings; and d is an array of enclosure opening sizes for all reasonable enclosure openings. i It is the current reasonable enclosure opening size, D. min This is the minimum opening of the enclosure corresponding to the industrial camera's eye-level position. Slope(H,d) is the linear slope of the change of all effective detection points (H,d), Slope(H,d)=(H i - H i-1 ) / (d i - d i-1 ).
[0093] In this embodiment, the camera position at the moment when a reasonable enclosure opening is first detected in the acquired image is used as the reference position. Therefore, it is not necessary to know the actual height to predict the distance from the industrial camera to the eye level. However, when using the absolute height of the industrial camera to predict the eye level, the prediction model will introduce more intermediate variables and increase the input parameters, such as the vertical coordinate of the datum line in the image coordinate system.
[0094] Step S423: Calculate the first difference between the current enclosure opening size and the previous enclosure opening size, and the second difference between the current position height and the previous position height. If both the first and second differences are positive or both are negative, set the direction to move downward; otherwise, set the direction to move upward.
[0095] Calculate above = Boolean[(H i -H i-1 ) / (d i -d i-1 )≥0], where H i H represents the current position and height. i-1 d represents the previous position and height. i d represents the current enclosure opening size. i-1 This is the size of the previous border opening. When `above=False`, it means the camera is below the border and moves upwards, `movDir="u"`; when `above=True`, it means the camera is above the border and moves downwards, `movDir="d"`. The height of the camera's next position after moving is: previous height + `Sign(movDir)`. The values of movVal and Sign(movDir) are: when movDir = "u", Sign(movDir) = +1; when movDir = "d", Sign(movDir) = -1.
[0096] Step S430: If the cumulative count is 3, when it is determined that the current position is close to the eye level, the movement direction is determined according to the size of the current and previous enclosure opening and the position height, and the movement distance is the preset second movement distance; otherwise, the current enclosure opening is determined to be invalid, the cumulative count is decremented by 1, the movement direction is the opposite of the previous movement direction, and the movement distance is the difference between the previous movement distance and the preset second movement distance.
[0097] When the cumulative number of detected reasonable enclosure openings reaches 3, it indicates that 2 reasonable enclosure openings have been detected previously. At this point, the calculated eye level position is checked to determine whether it is reasonable and close to eye level, i.e., to judge d. i ≤Min(d i-1 , d i-2 ).
[0098] When the above equation holds true, it indicates that the camera is approaching eye level. Continue moving the camera to get closer to eye level, moving a distance movVal = δ. s The direction of movement is movDir = f(above), where δ s In this embodiment, δ represents the preset second moving distance. s =0.5mm is the small step size; the expression for calculating f(above) is Boolean[(H i -H i-1 ) / (d i -d i-1[≥0] is calculated based on the current and previous enclosure opening size and position height.
[0099] If the above formula is invalid, it indicates that the calculated horizontal position is unreasonable. The current enclosure opening is deemed invalid, the cumulative count is decremented by 1, and the camera is moved back to a position near the previous one. Therefore, the moving distance movVal = δ h -δ s The direction of movement is opposite to the previous direction of movement, i.e., movDir=reverse(movDir).
[0100] Step S440: If the cumulative number of times is greater than or equal to 4, and if the current enclosure opening size is smaller than the previous enclosure opening size, the movement direction is the same as the previous movement direction, and the movement distance is the preset third movement distance. Otherwise, if the current enclosure opening size is greater than the minimum of all previous enclosure opening sizes and the cumulative number of times does not exceed the preset maximum cumulative number of times, the movement direction is the opposite of the previous movement direction, and the movement distance is the preset fourth movement distance. Otherwise, it is determined that the camera has failed to approach the level position.
[0101] When the cumulative number of occurrences is greater than or equal to 4, if the current enclosure opening size d i Less than the previous value d i-1 , that is, d i <d i-1 If the camera is considered to have effectively approached the eye level, it should continue to move in the same direction for a preset third movement distance, which can be equal to the second movement distance δ. s It can also be less than the second moving distance δ s Otherwise, compare the current enclosure opening size with the minimum value Min(d) of all previous enclosure opening sizes, and check if the cumulative count exceeds the maximum cumulative count F. max If the current enclosure opening size is not only greater than the previous enclosure opening size but also greater than Min(d), and the counter is less than the maximum cumulative count F. max If it deviates from the eye-level position, and the eye-level judgment threshold (minimum opening value D of the enclosure) is met, then it is considered to be deviating from the eye-level position. min The value is too small, therefore the maximum cumulative number of times F is not reached. max Under the given conditions, move the camera in the opposite direction by a preset fourth movement distance, such as 2δ. s At the same time, the threshold for judging eye level should be appropriately increased. If the cumulative number of times reaches the limit F... max If the camera fails to approach the eye level, the program will exit.
[0102] The overall operation process of this embodiment is as follows:
[0103] First, set and initialize the detection parameters and process control variables, such as edge detection parameters (including detection window, gradient operator, edge intensity threshold, etc.), image enhancement method settings (such as transfer function and cutoff frequency for frequency domain processing, convolutional structural units and segmentation threshold for neighborhood processing, etc.), and initial and default values for some control variables, including: moving distance movVal=δ l Movement direction movDir='u', relative orientation above=False, kurtosis P0=10, maximum step size δ l =3mm, medium step length δ m =1.5mm, small step size δ s =0.5mm, eye level δ h =0, Enclosure Increment δ d =2 pixels, minimum opening value of the boundary line D min =15 pixels, maximum opening value of the boundary line D max =k [ROI(right)-ROI(left)] (viewpoint coefficient k=0.3~1.0), maximum cumulative count F max =7, where ROI(right) is the coordinate of the right edge of the region of interest, and ROI(left) is the coordinate of the left edge of the region of interest.
[0104] Image acquisition is performed using a bottom-assisted light source to detect bottlenecks and construct regions of interest. First, the earliest edge points in each row are detected from left to right on the image. The Hough transform is then used to check for the presence of vertical lines (allowing for small angles of inclination). Similarly, edge points and vertical lines are detected from right to left. If vertical lines are detected both from left to right and from right to left, and the line distances are reasonable, a bottleneck is considered detected; otherwise, no bottleneck is considered to exist in the current image, and movVal is set to δ. l `movDir='u'` returns to the image acquisition step. In the case of a bottleneck, based on all edge points used in the Hough transform line, the region of interest is constructed using its minimum bounding rectangle. Specifically, the region of interest is constructed using the minimum x-coordinate, minimum y-coordinate, maximum x-coordinate, and maximum y-coordinate of the edge points as the coordinates of the top left and bottom right corners of the rectangle.
[0105] Then, the contours are detected. For each row of pixels in the region of interest, the grayscale value is accumulated to obtain the row grayscale. All row grayscale values are arranged into a sequence according to their vertical coordinates. Then, the first-order discrete derivative and absolute value of the sequence are calculated to obtain the row grayscale gradient. Next, it is determined whether the kurtosis of the row grayscale gradient is greater than the threshold P0. If it is, the region of interest is considered to have contours, and the process continues; otherwise, the region of interest is considered to have no contours, and movVal is set to δ. l`movDir='u'` returns to the image acquisition step. If a boundary exists within the region of interest, calculate the average gradient M and standard deviation σ of the sequence. Then, search forward through the sequence for the first row of grayscale gradients that is greater than or equal to the gradient threshold G0 (G0=M+σ), and use the ordinate corresponding to that row's grayscale gradient as the vertex y of the upper boundary. u Similarly, searching backwards, the first ordinate greater than or equal to the gradient threshold is taken as the lower bound vertex y. d .
[0106] Then determine if the boundary line is close to the edge; if so, adjust the camera height. If the following expression is not true, determine if it is close to the upper edge: y d -ROI(top)≥D max When the following expression is not true, determine the nearest lower edge: ROI(bot)-y u ≥D max , where D max It is the maximum opening of the enclosure, y u and y d Here, movVal represents the ordinate of the vertices of the upper and lower borders, respectively. ROI(top) and ROI(bot) represent the upper and lower edges of the ROI, respectively. Near the upper edge, let movVal = δ. m movDir='u', return to the image acquisition step; near the bottom edge, set movVal=δ m `movDir='d'` returns the image acquisition step.
[0107] Then calculate the size of the enclosure opening d=y d -y u To determine whether the size of the enclosure opening is reasonable, a reasonable enclosure inspection result satisfies the following formula: d≤D max If the boundary detection result is reasonable, continue execution. If unreasonable, select whether and what image processing to perform based on the Retry value. When Retry=0, perform enhanced frequency domain processing on the image corresponding to the region of interest and increment Retry++; when Retry=1, perform enhanced neighborhood processing on the image corresponding to the region of interest and increment Retry++; when Retry≥2, set movVal=δ m Then set Retry to zero and return to the image acquisition step.
[0108] The criteria for determining whether a level gaze position has been reached are as follows: d≤D min If the condition is met, it indicates that the current camera has reached eye level, and the program exits. If the condition is not met, the appropriate branch is selected for operation based on the value of the counter `find`.
[0109] When find=0, let H0=0, movVal=δ lmovDir='u', insert (H0,d0) into array Array[(H,d)]; then, increment the counter find by 1 and return to the image acquisition step;
[0110] When find=1, let H i =H i-1 +Sign(movDir) movVal, when movDir='u', Sign(movDir)=﹢1; when movDir='d', Sign(movDir)=﹣1, (H i ,d i Insert the array Array[(H,d)], and increment the counter find by 1. Calculate the eye level position according to the following formula: δ h =(d i -D min ) Slope[(H,d)], where δ h It represents the height of the industrial camera relative to its eye level; Slope[(H,d)] represents the slope of the linear change of the array data H and d. Let the moving distance movVal = δ h The movement direction is movDir = f(above), where: when above = False, movDir = 'u'; when above = True, movDir = 'd'; above = Boolean[(H i -H i-1 ) / (d i -d i-1 )≥0], where the subscripts i and i-1 represent the current detection and the previous detection, respectively; above=True indicates that the camera is above the datum line; above=False indicates that the camera is below the datum line, and then return to the image acquisition step.
[0111] When find=2, the system checks whether the calculated eye-level position is reasonable and close to eye-level. The judgment formula is: d i ≤Min(d i-1 , d i-2 When the above formula holds true, it indicates that the view is close to eye level. The counter find is incremented by 1, and movVal = δ. s movDir = f(above); If the above formula is not true, it means that the calculated eye position is unreasonable. Decrement the counter find by 1, and let movVal = δ h -δ s movDir=reverse(movDir) means that the movement direction is opposite to the previous movement direction, and then return to the image acquisition step.
[0112] When find≥3, if d i <d i-1 This is considered an effective approximation of the eye level, so the camera should continue to move in the same direction, setting movVal=δ. s Return to the image acquisition step. Otherwise, compare the opening of the enclosure with the minimum value Min(d) of the previous detection results, and check if the counter has exceeded the maximum cumulative count F. max If the current detected enclosure opening size is not only greater than the previous value but also greater than or equal to Min(d), and the counter is less than or equal to F... max , that is, d i ≥Min(d) & find≤F max If it deviates from the eye-level position, and the eye-level judgment threshold (minimum opening value D of the enclosure) is met, then it is considered to be deviating from the eye-level position. min The value is too small, therefore the maximum cumulative number of times F is not reached. max Under these conditions, the camera should be moved in the opposite direction, and movVal=2δ s movDir=reverse(movDir), and at the same time, appropriately increase the eye-level judgment threshold, D min =D min +δ d The program increments the counter `find` by 1. If the counter reaches its maximum count, the program considers the camera's attempt to approach the eye-level position to have failed and exits.
[0113] In summary, this embodiment uses the distance between the vertices of the upper and lower contour lines to characterize the deviation of the industrial camera from the eye-level position, avoiding edge detection problems such as significant noise interference at the contour line edges. Furthermore, it utilizes row grayscale gradient change features to detect contour line vertices, offering advantages such as resistance to random noise and strong robustness. Taking advantage of the straight-line contour of the bottleneck section of the volumetric flask, the Hough transform method is used to detect the bottleneck in the image, thereby constructing the region of interest (ROI). Based on the ROI, the detection of the marker lines is more accurate and efficient, eliminating the need for frequent adjustments to the ROI.
[0114] like Figure 10 As shown, based on the above-described camera vision automatic alignment method for volumetric flask markings, this embodiment of the invention discloses a camera vision automatic alignment system for volumetric flask markings, comprising:
[0115] Acquisition module 600 is used to acquire grayscale images of volumetric flasks;
[0116] Bottleneck identification module 610 is used to detect bottlenecks and construct regions of interest on the grayscale image;
[0117] The enclosure opening detection module 620 is used to detect the upper enclosure vertex and the lower enclosure vertex in the region of interest based on the cumulative gray-scale gradient of the longitudinal row, and calculate the enclosure opening size based on the upper enclosure vertex and the lower enclosure vertex.
[0118] The eye-level position approximation module 630 is used to determine that the camera has reached the eye-level position when the size of the enclosure opening is less than or equal to a preset minimum value of the enclosure opening; otherwise, when the size of the enclosure opening is less than or equal to the maximum value of the enclosure opening, it determines that the current enclosure opening is a reasonable enclosure opening. Based on the cumulative number of reasonable enclosure openings, the size of the enclosure opening and the size of the enclosure opening when it was last determined to be a reasonable enclosure opening, the camera's movement direction and movement distance are determined. The camera is moved according to the movement direction and movement distance, and the process returns to the step of acquiring the grayscale image of the volumetric flask, until it is determined that the camera has reached the eye-level position or that the camera has failed to approach the eye-level position.
[0119] like Figure 11 As shown, an embodiment of the present invention discloses an electronic device, including a memory 401 storing executable program code and a processor 402 coupled to the memory 401;
[0120] The processor 402 calls the executable program code stored in the memory 401 to execute the camera vision automatic alignment method for volumetric bottle markings described in the above embodiments.
[0121] This invention also discloses a computer-readable storage medium storing a computer program that causes a computer to execute the camera vision automatic alignment method for volumetric flask markings described in the above embodiments.
[0122] The purpose of the above embodiments is to reproduce and derive the technical solution of the present invention by way of example, and to fully describe the technical solution, purpose and effect of the present invention. The purpose is to enable the public to have a more thorough and comprehensive understanding of the disclosure of the present invention, and not to limit the scope of protection of the present invention.
[0123] The above embodiments are not an exhaustive list based on the present invention, and there may be many other embodiments not listed. Any substitutions and improvements made without departing from the concept of the present invention are within the protection scope of the present invention.
Claims
1. A method for automatically aligning volumetric flask markings using camera vision, characterized in that, include: Acquire grayscale images of volumetric flasks; Bottlenecks are detected and regions of interest are constructed on the grayscale image; In the region of interest, the upper and lower boundary vertices are detected based on the cumulative gray-scale gradient of the vertical rows, and the boundary opening size is calculated based on the upper and lower boundary vertices. When the size of the enclosure opening is less than or equal to the preset minimum size of the enclosure opening, it is determined that the camera has reached the eye level position. Otherwise, when the size of the enclosure opening is less than or equal to the maximum size of the enclosure opening, it is determined that the current enclosure opening is a reasonable enclosure opening. Based on the cumulative number of reasonable enclosure openings, the size of the enclosure opening and the size of the enclosure opening when it was last determined to be a reasonable enclosure opening, the camera's moving direction and moving distance are determined. The camera is moved according to the moving direction and the moving distance, and the process returns to the step of acquiring the grayscale image of the volumetric flask, until it is determined that the camera has reached the eye level position or the camera has failed to approach the eye level position. The step of detecting the upper and lower boundary vertices in the region of interest based on the cumulative gray-level gradient of the vertical rows includes: The grayscale value of each row of pixels is accumulated within the region of interest to obtain the row grayscale value of each row, and the row grayscale values of all rows are arranged into a number column according to the vertical axis. The first-order discrete derivative and absolute value of the sequence are used to obtain the row grayscale gradient of each row. Search the sequence from front to back, and set the ordinate of the first row with a grayscale gradient greater than or equal to the gradient threshold as the vertex of the upper boundary. Search the sequence from back to front, and set the ordinate of the first row with a grayscale gradient greater than or equal to the gradient threshold as the vertex of the lower boundary.
2. The camera-based visual automatic alignment method for volumetric flask markings as described in claim 1, characterized in that, The step of determining the camera's movement direction and distance based on the cumulative number of reasonable enclosure openings, the size of the enclosure opening, and the size of the enclosure opening when it was previously determined to be a reasonable enclosure opening includes: If the cumulative number is 1, the camera moves upward based on a preset first moving distance; If the cumulative number is 2, calculate the distance and direction of the horizontal position relative to the current position based on the size and height of the enclosure opening at the current and previous times, and obtain the moving distance and the moving direction; If the cumulative count is 3, when it is determined that the current position is close to the eye level, the movement direction is determined according to the size and height of the enclosure opening of the current and previous times, and the movement distance is the preset second movement distance. Otherwise, the current enclosure opening is determined to be invalid, the cumulative count is decremented by 1, the movement direction is the opposite of the previous movement direction, and the movement distance is the difference between the previous movement distance and the preset second movement distance. If the cumulative number of times is greater than or equal to 4, and if the current enclosure opening size is smaller than the previous enclosure opening size, the movement direction is the same as the previous movement direction, and the movement distance is a preset third movement distance. Otherwise, if the current enclosure opening size is greater than the minimum of all previous enclosure opening sizes and does not exceed the preset maximum cumulative number of times, the movement direction is the opposite of the previous movement direction, and the movement distance is a preset fourth movement distance. Otherwise, the camera is deemed to have failed to approach the eye level position.
3. The camera-based visual automatic alignment method for volumetric flask markings as described in claim 2, characterized in that, The step of calculating the distance and direction of the horizontal position relative to the current position based on the current and previous enclosure opening size and position height includes: Calculate the linear change slope based on the current and previous enclosure opening size, position, and height; Calculate the difference between the size of the enclosure opening and the minimum size of the enclosure opening, and multiply the difference by the linear change slope to obtain the distance; Calculate the first difference between the current enclosure opening size and the previous enclosure opening size, and the second difference between the current position height and the previous position height. If both the first and second differences are positive or both are negative, set the direction to move downward; otherwise, set the direction to move upward.
4. The camera-based visual automatic alignment method for volumetric flask markings as described in claim 1, characterized in that, After obtaining the vertices of the upper and lower contours, the following is also included: Calculate the first difference between the ordinate of the lower boundary vertex and the upper edge of the region of interest, and calculate the second difference between the ordinate of the lower edge of the region of interest and the upper boundary vertex. When the first difference is less than the maximum value of the enclosure opening, it is determined that the enclosure is close to the upper edge, and the camera is moved upward based on a preset distance to return to the step of acquiring the grayscale image of the volumetric flask; When the second difference is less than the maximum value of the enclosure opening, it is determined that the enclosure is near the lower edge, and the camera is moved downward based on a preset distance to return to the step of acquiring the grayscale image of the volumetric flask.
5. The camera-based visual automatic alignment method for volumetric flask markings as described in claim 1, characterized in that, When the current enclosure opening is determined to be an unreasonable enclosure opening, the region of interest in the grayscale image is subjected to enhanced frequency domain processing, and the upper enclosure vertex and the lower enclosure vertex are re-detected. When the number of re-detections reaches the set maximum number, the camera is moved and the process returns to the step of acquiring the grayscale image of the volumetric flask.
6. The camera-based visual automatic alignment method for volumetric flask markings as described in claim 1, characterized in that, The step of detecting bottlenecks and constructing regions of interest on the grayscale image includes: The first edge point of each row is detected from left to right on the grayscale image. For the first edge points of all rows, the Hough transform method is used to detect whether there is a first vertical line. The first second edge point of each row is detected from right to left on the grayscale image. For the second edge points of all rows, the Hough transform method is used to detect whether there is a second vertical line. When both the first vertical line and the second vertical line exist and the distance between the first vertical line and the second vertical line is less than the maximum line distance, a bottleneck is detected, and the minimum bounding rectangle of all the first edge points used to construct the first vertical line and all the second edge points used to construct the second vertical line is set as the region of interest.
7. A camera-based vision-based automatic alignment system for volumetric bottle markings, characterized in that, include: The acquisition module is used to acquire grayscale images of volumetric flasks; A bottleneck identification module is used to detect bottlenecks and construct regions of interest on the grayscale image. The enclosure opening detection module is used to detect the upper enclosure vertex and the lower enclosure vertex in the region of interest based on the cumulative gray-scale gradient of the vertical row, and calculate the enclosure opening size based on the upper enclosure vertex and the lower enclosure vertex; The eye-level position approximation module is used to determine that the camera has reached the eye-level position when the size of the enclosure opening is less than or equal to the preset minimum size of the enclosure opening; otherwise, when the size of the enclosure opening is less than or equal to the maximum size of the enclosure opening, the current enclosure opening is determined to be a reasonable enclosure opening. Based on the cumulative number of reasonable enclosure openings, the size of the enclosure opening and the size of the enclosure opening when it was previously determined to be a reasonable enclosure opening, the camera's movement direction and movement distance are determined. The camera is moved according to the movement direction and movement distance, and the step of acquiring the grayscale image of the volumetric flask is returned until the camera is determined to have reached the eye-level position or the camera fails to approach the eye-level position. The step of detecting the upper and lower boundary vertices in the region of interest based on the cumulative gray-level gradient of the vertical rows includes: The grayscale value of each row of pixels is accumulated within the region of interest to obtain the row grayscale value of each row, and the row grayscale values of all rows are arranged into a number column according to the vertical axis. The first-order discrete derivative and absolute value of the sequence are used to obtain the row grayscale gradient of each row. Search the sequence from front to back, and set the ordinate of the first row with a grayscale gradient greater than or equal to the gradient threshold as the vertex of the upper boundary. Search the sequence from back to front, and set the ordinate of the first row with a grayscale gradient greater than or equal to the gradient threshold as the vertex of the lower boundary.
8. An electronic device, characterized in that, It includes a memory storing executable program code and a processor coupled to the memory; the processor calls the executable program code stored in the memory to execute the camera vision automatic alignment method for calibrating volumetric flask markings as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein the computer program causes a computer to perform the camera vision automatic alignment method for volumetric flask markings as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Automatic head-up method, device and system for glass measuring vessel marking and equipment
CN113375749A
Method, device and equipment for identifying graduation line of glass measuring vessel
CN116778183A