A method for positioning a feature position of an ampoule neck
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- 美蓝(杭州)医药科技有限公司
- Filing Date
- 2026-05-07
- Publication Date
- 2026-08-04
AI Technical Summary
[0005]本发明解决了现有安瓿瓶割瓶定位技术无法自适应、高精度、抗干扰地定位瓶颈最窄处的问题,提出一种安瓿瓶瓶颈特征位置定位方法,主要采用基于完整掩码放大特征定位割瓶位置,达到了高精度、自适应、抗干扰地定位安瓿瓶割瓶位置的效果
1. 定位精度高,基于完整二值化瓶身掩码和像素平移特征放大,割瓶位置定位偏差≤0.2mm,显著降低割瓶碎裂、药液污染、泄漏风险;
Smart Images

Figure CN122510342A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of ampoule bottle feature location technology, and in particular to a method for locating the feature location of the bottle neck. Background Technology
[0002] In the fields of machine vision feature extraction and automated precision control, particularly in automated intravenous dispensing robot systems, the ampoule cutting process is crucial. As the healthcare industry's demands for automated and precise dispensing continue to increase, accurately determining the ampoule cutting position has a critical impact on ensuring the safety, success rate, and operational efficiency of medication dispensing. Precise cutting positions can effectively prevent medication contamination, ampoule breakage, and medication leakage, driving the development of centralized intravenous drug preparation and automated dispensing robot systems towards greater reliability and efficiency.
[0003] In the past, common methods for ampoule cutting and positioning included fixed-position manual teaching and manual parameter adjustment. Fixed-position manual teaching involved operators using experience to determine the approximate cutting location and then making multiple adjustments to find the optimal position. Manual parameter adjustment involved continuously adjusting parameters according to different ampoule sizes to achieve the correct cutting position. Other methods relied on fixed thresholds or template matching, setting a fixed threshold or using a specific template to match the ampoule image to determine the cutting position. Additionally, some methods were based on the original outline or incomplete mask, directly analyzing the captured image of the ampoule's original outline or incomplete mask to determine the cutting position.
[0004] However, these existing technologies have significant drawbacks. They lack automation adaptability, failing to automatically identify the cutting position based on the actual shape of the ampoule, still relying on manual operation. They also lack multi-specification compatibility; different ampoule sizes vary greatly, and even products of the same specification may experience bottleneck position shifts due to manufacturing process fluctuations. Traditional methods require parameter adjustments for each specification, making it difficult to meet the needs of automated dispensing of mixed specifications. Furthermore, they lack integration with front-end vision algorithms, failing to fully utilize image segmentation and gripper occlusion repair results, leading to incomplete bottleneck feature extraction, large positioning errors, and poor robustness. Moreover, they have weak anti-interference capabilities, easily affected by factors such as ampoule reflection, scratches, light source fluctuations, and gripper occlusion, frequently resulting in misjudgments and missed judgments, failing to meet the high reliability requirements of pharmaceutical scenarios. Summary of the Invention
[0005] This invention solves the problem that existing ampoule bottle cutting and positioning technologies cannot adaptively, accurately, and with anti-interference positioning of the narrowest part of the bottle bottleneck. It proposes a method for locating the feature position of the ampoule bottle bottleneck, which mainly adopts the method of locating the cutting position based on the magnified feature of the complete mask, achieving the effect of locating the cutting position of the ampoule bottle with high accuracy, adaptability, and anti-interference.
[0006] To achieve the above objectives, the following technical solution is proposed: A method for locating the characteristic position of the neck of an ampoule includes the following steps: S1, Obtain the complete binary mask of the ampoule, wherein the bottle body area and the background area have different pixel values in the mask; S2, for the complete binarized bottle mask, traverse row by row, and translate all bottle pixels in each row as a whole towards the zero point of the X-axis, so that the bottle pixels in each row are aligned with the zero point of the X-axis, thereby amplifying the radial width difference of the bottleneck in the X-axis direction and forming a magnified image of the width feature. S3, For the image after width feature magnification, count the number of pixels in the bottle body area row by row to construct a pixel width sequence that varies with the Y-axis height; S4, perform valley detection on the pixel width sequence to identify the width valley corresponding to the bottleneck region; S5. Within the Y-axis interval corresponding to the width trough, find the minimum pixel width point and determine the Y-axis coordinate corresponding to the minimum point as the bottle cutting reference position.
[0007] By adopting the above technical solution, high-precision positioning of the bottle cutting position can be achieved based on complete mask and feature magnification, with a positioning deviation of ≤0.2mm, which significantly reduces the risk of bottle breakage, liquid contamination and leakage. By constructing a pixel width sequence and performing valley detection, the bottleneck area can be accurately identified, thereby determining the reference position for bottle cutting.
[0008] Preferably, in step S2, shifting all bottle pixels in each row towards the zero point of the X-axis specifically involves: for each row, calculating the minimum or maximum X-coordinate of the bottle pixels in that row, shifting all bottle pixels in the row to the left or right, aligning the left or right boundary of the bottle pixels in that row to the zero point of the X-axis, while keeping the relative X-axis distance between pixels in that row unchanged.
[0009] By adopting the above technical solution, each row of bottle body pixels is shifted towards the zero point of the X-axis to align the left or right boundary, while keeping the distance between the pixels in the row and the X-axis unchanged. This can accurately magnify the radial width difference of the bottleneck in the X-axis direction, forming a magnified image of the width feature, which facilitates the subsequent accurate identification of the bottleneck area, thereby improving the positioning accuracy of the bottle cutting reference position and reducing the risk of bottle breakage, liquid contamination, and leakage.
[0010] Preferably, the trough detection in S4 further includes: using an adaptive threshold to divide the peaks and troughs, identifying the position where the height and width of the bottle body's peak first drops below the trough threshold and the drop is not less than 20% of the width of the main body's peak, as the lower edge of the bottleneck; and identifying the position where the width of the bottleneck trough ends rises and breaks through the peak threshold and the rise is not less than 30% of the minimum width of the bottleneck, as the upper edge of the bottleneck; the bottleneck region is the Y-axis interval between the lower edge of the bottleneck and the upper edge of the bottleneck.
[0011] By adopting the above technical solution, using adaptive thresholds to divide peaks and troughs, and combining specific descent and rise conditions to identify the lower and upper edges of the bottleneck, the bottleneck area can be accurately determined, improving the positioning accuracy of bottle cutting, reducing the risk of bottle breakage, liquid contamination, and leakage, enhancing anti-interference capabilities, and making peak and trough identification more stable and reliable.
[0012] Preferably, after constructing the pixel width sequence, step S3 further includes: using the 3σ criterion to remove outliers in the width sequence, and using a sliding window filter to smooth the width sequence.
[0013] By adopting the above technical solution, after constructing the pixel width sequence, outliers in the width sequence are removed using the 3σ criterion, and the width sequence is smoothed by combining sliding window filtering. This can avoid misjudgment caused by local abrupt changes, improve the smoothness of the width sequence, effectively enhance the anti-interference ability of the algorithm, and make the peak and valley recognition accuracy ≥99.8%, making the detection more stable and reliable.
[0014] Preferably, the method for obtaining the complete binary bottle mask in S1 includes: using an image segmentation model to perform semantic segmentation on the original image of the ampoule in the gripper holding state to obtain an initial mask; then using a gripper occlusion gap filling algorithm to repair the contour loss caused by the gripper occlusion to generate a complete binary mask with closed contour; and performing morphological closing operation on the mask to remove noise and burrs.
[0015] By adopting the above technical solution, an initial mask can be obtained by semantic segmentation using an image segmentation model. The clamp occlusion gap filling algorithm can repair the missing contour and generate a complete binary mask. Performing morphological closing operation on the mask can remove small noise and burrs, smooth the contour, and retain the key bottleneck features, thereby improving the stability of subsequent detection. It can also make full use of the image segmentation and clamp occlusion repair results, overcome the problems of incomplete bottleneck feature extraction, large positioning error, and poor robustness caused by traditional methods based on the original contour or incomplete mask, enhance the anti-interference ability of the algorithm, make the peak and valley recognition accuracy higher, and thus ensure the positioning accuracy.
[0016] Preferably, before trough detection, step S4 further includes setting minimum and maximum spacing constraints between the lower and upper edges of the bottle neck based on the physical range of the bottle neck height, in order to eliminate false troughs.
[0017] By adopting the above technical solution, the spacing constraint between the lower and upper edges of the bottle neck can be set according to the physical range of the bottle neck height before trough detection, effectively eliminating false troughs, improving the accuracy of peak and trough identification, and enhancing the algorithm's anti-interference ability and the stability and reliability of detection.
[0018] Preferably, the method further includes: S6. The pixel coordinates of the bottle-cutting reference position are combined with the pre-calibrated pixel equivalents and converted into physical coordinates that can be recognized by the robot bottle-cutting execution module, and then output to the robot control system.
[0019] By adopting the above technical solution, the pixel coordinates of the ampoule cutting reference position can be converted into physical coordinates that the robot can recognize, realizing seamless integration between the algorithm and the robot cutting execution module, forming a complete vision-control closed loop, and can be directly connected to the robot cutting execution module of the existing automated dispensing system.
[0020] Preferably, the method is compatible with ampoules of at least 2ml, 5ml, 10ml and 20ml sizes, and is applicable to ampoules made of transparent glass and brown glass, supporting multi-size mixed production lines and significantly reducing debugging costs.
[0021] Preferably, if no valid width valley is detected in S4, the process automatically returns to S1, re-acquires the complete binary bottle mask, and then adjusts the structuring element size or filtering parameters of the morphological closing operation before executing again.
[0022] By adopting the above technical solution, when no effective width valley is detected, the algorithm automatically returns to reacquire the complete binary bottle mask and adjusts the relevant parameters to execute again, which can improve the fault tolerance of the algorithm, ensure that the bottleneck features can be accurately detected, and improve the reliability and stability of positioning.
[0023] Preferably, in the complete binarized bottle mask, the pixel value of the bottle area is 255, and the pixel value of the background area is 0; the length of the pixel width sequence is equal to the number of pixel rows in the image height direction.
[0024] By adopting the above technical solution, the pixel values of the bottle body and background areas in the complete binary bottle mask are clearly defined, which facilitates the identification and processing of the bottle body area; the pixel width sequence length is specified to be equal to the number of pixel rows in the image height direction, so that the width sequence is established in correspondence with the image height, which helps to accurately count and analyze the change of bottle width with height, thereby improving the accuracy and reliability of ampoule bottle neck feature location.
[0025] The beneficial effects of this invention are: 1. High positioning accuracy: Based on complete binary bottle mask and pixel translation feature amplification, the positioning deviation of the bottle cutting position is ≤0.2mm, which significantly reduces the risk of bottle breakage, liquid contamination and leakage. 2. Full-size adaptive design, compatible with ampoules of all sizes including 2ml, 5ml, 10ml, and 20ml, suitable for transparent / brown glass materials, supports mixed production lines of multiple sizes, eliminates the need for manual parameter adjustment, and significantly reduces debugging costs; 3. Strong anti-interference ability. After morphological processing, outlier removal and multi-constraint verification, the peak and trough recognition accuracy is ≥99.8%, and it has strong robustness against reflection, scratches and clamping occlusion. Attached Figure Description
[0026] Figure 1 This is a flowchart of the method of the present invention.
[0027] Figure 2 This is a specific implementation process of the present invention for a certain type of ampoule. Detailed Implementation
[0028] The technical solutions in the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings. The described embodiments are only possible technical implementations of the present invention, but are not limited thereto. Other embodiments obtained by those skilled in the art in conjunction with the embodiments of the present invention without creative effort are also within the protection scope of the present invention. Example
[0029] A method for locating the characteristic position of the ampoule neck, referenced Figure 1 The steps include: S1, obtain the complete binary mask of the ampoule body, wherein the bottle body region and the background region have different pixel values in the mask; the method of obtaining the complete binary mask in S1 includes: using an image segmentation model to perform semantic segmentation on the original image of the ampoule in the gripper state to obtain an initial mask; then using a gripper occlusion gap filling algorithm to repair the contour loss caused by the gripper occlusion to generate a complete binary mask with closed contour; and performing morphological closing operation on the mask to remove noise and burrs. In this embodiment, semantic segmentation using an image segmentation model yields an initial mask. A gripper occlusion gap-filling algorithm repairs missing contours and generates a complete binary mask. Performing morphological closing operations on this mask removes minute noise and burrs, smooths the contour, and preserves key bottleneck features, improving subsequent detection stability. It also fully utilizes the results of image segmentation and gripper occlusion repair, overcoming the problems of incomplete bottleneck feature extraction, large positioning errors, and poor robustness caused by traditional methods based on original contours or incomplete masks. This enhances the algorithm's anti-interference ability, resulting in higher peak and trough recognition accuracy, thereby ensuring positioning precision.
[0030] S2, for the complete binary bottle mask, traverse row by row, and translate all bottle pixels in each row towards the zero point of the X-axis, aligning the bottle pixels in each row with respect to the zero point of the X-axis. This amplifies the radial width difference of the bottleneck in the X-axis direction, forming a magnified image of the width feature. Specifically, translating all bottle pixels in each row towards the zero point of the X-axis in S2 involves: for each row, calculating the minimum or maximum X-coordinate of the bottle pixels in that row, and translating all bottle pixels in the entire row to the left or right, aligning the left or right boundary of the bottle pixels in that row to the zero point of the X-axis, while maintaining the relative X-axis distance between pixels within that row. In this embodiment, translating each row of bottle pixels towards the zero point of the X-axis to align the left or right boundary while maintaining the relative X-axis distance between pixels within the row accurately amplifies the radial width difference of the bottleneck in the X-axis direction, forming a magnified image of the width feature. This facilitates subsequent accurate identification of the bottleneck area, thereby improving the positioning accuracy of the bottle cutting reference position and reducing the risks of bottle breakage, liquid contamination, and leakage.
[0031] S3 involves enlarging the image by width features, counting the number of pixels in the bottle area line by line, and constructing a pixel width sequence that varies with the Y-axis height. After constructing the pixel width sequence, S3 further includes: using the 3σ criterion to remove outliers from the width sequence, and using a sliding window filter to smooth the width sequence. In this embodiment, after constructing the pixel width sequence, using the 3σ criterion to remove outliers and combining it with sliding window filtering to smooth the width sequence avoids misjudgments caused by local abrupt changes, improves the smoothness of the width sequence, effectively enhances the algorithm's anti-interference ability, and achieves a peak and trough recognition accuracy of ≥99.8%, making the detection more stable and reliable.
[0032] S4, trough detection is performed on the pixel width sequence to identify the width troughs corresponding to the bottleneck region; before trough detection, S4 further includes: setting minimum and maximum spacing constraints between the lower and upper edges of the bottleneck based on the physical range of the ampoule bottleneck height, to eliminate false troughs. In this embodiment, the spacing constraints between the lower and upper edges of the bottleneck can be set according to the physical range of the ampoule bottleneck height before trough detection, effectively eliminating false troughs, improving the accuracy of peak and trough identification, and enhancing the algorithm's anti-interference ability and the stability and reliability of detection.
[0033] The trough detection in S4 further includes: using an adaptive threshold to divide peaks and troughs, identifying the position where the peak of the bottle body first drops below the trough threshold, and the drop is not less than 20% of the peak width, as the lower edge of the bottleneck; and identifying the position where the width of the bottleneck trough rises from the end of the trough and exceeds the peak threshold, and the rise is not less than 30% of the minimum bottleneck width, as the upper edge of the bottleneck; the bottleneck region is the Y-axis interval between the lower edge and the upper edge of the bottleneck. In this embodiment, by using an adaptive threshold to divide peaks and troughs, and combining specific drop and rise amplitude conditions to identify the lower and upper edges of the bottleneck, the bottleneck region can be accurately determined, improving the positioning accuracy of the bottle cutting location, reducing the risk of bottle breakage, liquid contamination, and leakage, enhancing anti-interference capabilities, and making peak and trough identification more stable and reliable.
[0034] If no valid width trough is detected in step S4, the algorithm automatically returns to step S1 to reacquire the complete binary bottle mask, adjusts the structuring element size or filtering parameters of the morphological closing operation, and executes again. In this embodiment, automatically returning to reacquire the complete binary bottle mask and adjusting relevant parameters when no valid width trough is detected improves the algorithm's fault tolerance, ensures accurate detection of bottleneck features, and enhances the reliability and stability of positioning.
[0035] S5. Within the Y-axis interval corresponding to the width trough, find the minimum pixel width point and determine the Y-axis coordinate corresponding to the minimum point as the bottle cutting reference position. In this embodiment, based on the complete mask and feature magnification, high-precision positioning of the bottle cutting position can be achieved with a positioning deviation of ≤0.2mm, significantly reducing the risk of bottle breakage, liquid contamination, and leakage. By constructing a pixel width sequence and performing trough detection, the bottleneck area can be accurately identified, thereby determining the bottle cutting reference position.
[0036] S6. The pixel coordinates of the bottle-cutting reference position are combined with the pre-calibrated pixel equivalents and converted into physical coordinates that can be recognized by the robot bottle-cutting execution module, and then output to the robot control system.
[0037] In this embodiment, the pixel coordinates of the ampoule cutting reference position can be converted into physical coordinates that the robot can recognize, realizing seamless integration between the algorithm and the robot cutting execution module, forming a complete vision-control closed loop, and can be directly connected to the robot cutting execution module of the existing automated dispensing system.
[0038] The method is compatible with ampoules of at least 2ml, 5ml, 10ml and 20ml sizes, and is applicable to ampoules made of transparent glass and brown glass. It supports mixed production of multiple sizes and significantly reduces debugging costs.
[0039] In the complete binary bottle mask, the pixel value of the bottle area is 255, and the pixel value of the background area is 0; the length of the pixel width sequence is equal to the number of pixel rows in the image height direction.
[0040] In this embodiment, the pixel values of the bottle body and background areas in the complete binary bottle mask are clearly defined, which facilitates the identification and processing of the bottle body area; the length of the pixel width sequence is specified to be equal to the number of pixel rows in the image height direction, so that the width sequence is correlated with the image height, which helps to accurately count and analyze the change of bottle width with height, thereby improving the accuracy and reliability of the positioning of the ampoule bottle neck feature.
[0041] The specific implementation process of this embodiment is as follows: S1, Complete Binarization Mask Acquisition: S101, Initial Segmentation: The SAM3 image segmentation model is used to perform semantic segmentation on the original image of the ampoule in the gripper state, and the initial mask of the bottle body is extracted. S102, Gap Filling: The gap filling algorithm of the gripper is used to repair the contour loss caused by the gripping, and a complete binary mask with closed contour, no redundancy and no loss is generated. The gray value of the bottle body area is 255 and the background is 0. S103, Mask preprocessing: Morphological closing operation is performed using 3×3 structuring elements to remove minor noise and burrs, smooth the contour, and retain key bottleneck features, thereby improving the stability of subsequent detection.
[0042] S2, Pixel translation and bottleneck feature magnification: S201, Row pixel alignment: Traverse the complete mask row by row, and shift the entire effective bottle body pixels of each row toward the zero point of the X-axis, while keeping the left and right relative positions of the pixels in that row unchanged; S202, Feature Magnification: By translating and aligning, the radial width difference of the ampoule bottle is significantly magnified in the X-axis direction, so that the image presents a clear "peak, trough, peak" shape: the main body of the bottle is a high-width peak, the bottleneck area is a low-width trough, and the difference between the peak and trough is magnified, which is convenient for accurate identification.
[0043] S3, Peak and trough detection and width sequence construction: S301, Width Statistics: The number of pixels in the bottle body area is counted row by row in the magnified mask to form a pixel width sequence that varies with the Y-axis height; S302, Adaptive Threshold and Anomaly Removal: Adaptive threshold is used to divide peaks and troughs, and the 3σ criterion is combined to remove outliers, pseudo-peaks and noise interference, while retaining the true bottle body and bottleneck transition features. S303, Sequence Smoothing: Sliding window filtering further improves the smoothness of wide sequences and avoids misjudgment caused by local abrupt changes.
[0044] S4, bottleneck lower edge positioning: S401, lower edge feature definition: the width of the first rapid drop from the wide peak at the bottom of the bottle body to below the trough threshold, and the drop is not less than 20% of the width of the main peak; S402, Lower edge coordinate extraction: Traverse the width sequence, identify the position that meets the mutation condition, and record the corresponding Y-axis coordinate as the lower edge of the bottleneck.
[0045] S5, bottleneck upper edge positioning: S501, upper edge feature definition: located at the end of the bottleneck trough, the width rises rapidly from narrow and breaks through the peak threshold, the rise is not less than 30% of the minimum width of the bottleneck, and the distance between the upper edge and the lower edge conforms to the physical range of the ampoule bottleneck height. S502, top edge coordinate extraction: Traverse upwards from the bottom edge of the bottleneck, identify effective abrupt change points by combining height interval constraints, and eliminate false top edges through spacing verification to obtain the Y-axis coordinate of the top edge of the bottleneck.
[0046] S6: Bottle cutting position determination and coordinate output: S601, Optimal bottle cutting point location: In the width sequence between the upper and lower edges of the bottle neck, find the point with the minimum pixel width. This point is the narrowest part of the bottle neck and is the mechanically optimal bottle cutting reference position. S602, Physical coordinate conversion: Combined with pixel equivalent calibration, pixel coordinates are converted into actual physical coordinates that the robot can execute; S603, Result Output and Fault Tolerance: Outputs the upper and lower edges of the bottleneck and the coordinates of the bottle cutting position to the robot bottle cutting control module; if no valid features are detected, the mask preprocessing and feature extraction process is automatically restarted.
[0047] This implementation uses a 10ml standard transparent glass ampoule as an example, and combines typical industrial camera imaging parameters (1920×1200 pixels resolution, 0.05mm / pixel pixel equivalent) in a gripper scenario, providing a detailed implementation process for each step. (Refer to...) Figure 2 The details are as follows: S1: Obtaining the complete binarized mask: S101, Initial Segmentation, Input original RGB image, 1920×1200. Using a pre-trained SAM3 model, after inputting the image, it automatically outputs the binarized initial mask M_init for the bottle body region, where the bottle body pixels are marked as 1 or 255, and the background is marked as 0.
[0048] Due to the grapple obstruction, the mask has gaps in the grapple contact area, resulting in a missing area with a pixel value of 0.
[0049] S102, Gap filling, using a gripper-based gap filling algorithm: Extract all connected components from M_init, and select the connected component with the largest area as the main body of the bottle. Calculate the convex hull of the main body mask, and generate the convex hull mask M_convex.
[0050] Calculate the difference region between M_convex and M_init; these difference regions are the gaps caused by the grippers.
[0051] For each gap region, morphological dilation is performed using known bottle body pixels on its boundary as seeds, and the gap is filled with circular structuring elements with a radius of 5 pixels until it is connected to the surrounding bottle body.
[0052] Output a complete binary mask M_complete, with a bottle body area pixel value of 255, background of 0, and closed outline with no missing pixels.
[0053] S103, Mask preprocessing: Perform a morphological closing operation on M_complete: Structural element: 3×3 square, all of which are 1.
[0054] Expansion followed by corrosion: Expansion fills tiny holes and burrs, while corrosion restores the original boundaries.
[0055] After output smoothing, the mask M_processed preserves key features of the bottleneck region, such as the narrowing transition region.
[0056] S2, Pixel translation and bottleneck feature magnification: S201, row pixel alignment, iterate through each row y of M_processed, where y = 0 to 1199.
[0057] Scan the column coordinate x of all pixels in the y-th row and collect the set X_set of all bottle body pixels with a value of 255.
[0058] Calculate the left boundary of the bottle body pixels in this row, x_min = min(X_set).
[0059] Transform the column coordinates x of all bottle body pixels in the row to x' = x - x_min.
[0060] The background pixel count remains at 0.
[0061] After the transformation, the left edge of the bottle body in each row is aligned to x'=0, and the relative spacing of the bottle body pixels within that row remains unchanged.
[0062] S202, Feature magnification, the previously insignificant radial narrowing effect in the bottleneck area is significantly amplified after alignment: Bottle body: The width of each row of the bottle body, max(X_set) - min(X_set) + 1, equals the number of pixels in that row after translation. For example, the main body of the bottle body is about 150 pixels.
[0063] At the narrowest point of the bottleneck: the number of pixels on the bottle body in this row may be reduced to 30 pixels.
[0064] The image clearly shows the width (bottle body), narrowness (bottleneck), and width (bottle mouth side) along the Y-axis.
[0065] S3, Peak and trough detection and width sequence construction: S301, Width Counting: For the translated image, count the number of pixels on the bottle body line by line. Width[y]=count(pixel(x',y)==255), where x'=0..1919.
[0066] The width sequence W=[w0,w1,...,w1199] with a length of 1200 is obtained, in pixels.
[0067] S302, Adaptive Thresholding and Anomaly Removal: Adaptive peak / trough threshold calculation: Calculate the mean μ = (1 / 1200) * Σw_y and the standard deviation σ of the sequence.
[0068] Peak threshold T_peak = μ * 1.2 (empirical coefficient).
[0069] Valley threshold T_valley=μ*0.6.
[0070] Outlier removal (3σ criterion): For each w_y, if |w_y-μ|>3σ, it is considered an outlier.
[0071] Outliers are replaced by linear interpolation of two adjacent valid values: w_y_new=(w_{y-1}+w_{y+1}) / 2.
[0072] False peak removal: For continuous peak regions, only the maximum value is retained as the true peak; tiny fluctuations with a width of less than 10 pixels are ignored.
[0073] S303, sequence smoothing, using sliding window filtering, window size L=11, an odd number: For each y, take all w values within the window [y-5, y+5], calculate the median, and replace w_y with the median.
[0074] Output the smoothed width sequence W_smooth.
[0075] S4, bottleneck lower edge positioning: S401, lower edge feature definition, traverses W_smooth from the bottom (y=1199) to the top (y=0) of the image.
[0076] The first position y_down that satisfies all of the following conditions: The current width w_y is less than T_valley.
[0077] The decrease in amplitude Δ_down = (width of the previous local peak - w_y) / width of the previous local peak ≥ 20%.
[0078] The previous local peak is defined as the peak point y_peak of the first continuous upward movement encountered from the bottom, followed by a downward movement, and its width w_peak is the main peak of the bottle body.
[0079] The descent speed is ≥10 pixels / line, and the descent speed is the width reduction within 5 consecutive lines.
[0080] S402, extract the lower edge coordinates, starting from y=1199, record the first local peak y_peak and its width w_peak.
[0081] Continue scanning upwards. When w_y <= T_valley and (w_peak - w_y) / w_peak >= 0.2, record the current y as a candidate lower edge.
[0082] Check 3 more rows from the bottom edge of the candidate. If the width continues to decrease or stabilizes at the bottom, then finally confirm that y_down = the current y.
[0083] In this embodiment, the y_down of the 10ml ampoule is 950 pixels.
[0084] S5, bottleneck upper edge positioning: S501, upper edge feature definition, continues traversing upwards from y_down. Find the position y_up that satisfies the following condition: The current width w_y is greater than T_peak.
[0085] The increase Δ_up = (w_y - w_min) / w_min ≥ 30%, where w_min is the minimum width within the interval [y_down, y_up], i.e. the narrowest point of the bottleneck.
[0086] Spacing constraint: Δy = y_down - y_up must be within the physical range of the ampoule neck height.
[0087] The physical neck height of a 10ml ampoule is approximately 8~12mm, corresponding to a pixel height of 160~240 pixels (0.05mm / pixel).
[0088] That is, 160≤(y_down-y_up)≤240.
[0089] S502, extract the coordinates along the top edge. Starting from y_down, search upwards for the first local minimum width point y_min, which is the narrowest point.
[0090] Continue upwards from y_min to find the first point y_candidate whose width exceeds T_peak.
[0091] Calculate Δy = y_down - y_candidate. If 160 ≤ Δy ≤ 240, then accept y_up = y_candidate.
[0092] If the spacing constraint is not met, skip the candidate and continue searching upwards for the next peak starting point until the condition is met.
[0093] In this embodiment, y_up = 710 pixels, Δy = 950 - 710 = 240, which meets the upper limit.
[0094] S6: Bottle cutting position determination and coordinate output: S601, Optimal bottle-cutting point location: Within the interval [y_up, y_down] (i.e., from 710 to 950 pixels), find the minimum value of W_smooth. y_cut=argmin_{yin[710,950]}w_y. The width w_min corresponding to this point is the narrowest point of the bottleneck.
[0095] In this embodiment, y_cut = 830 pixels and w_min = 28 pixels.
[0096] S602, physical coordinate conversion, known pixel equivalent k=0.05mm / pixel (obtained through pre-calibration using a calibration board).
[0097] Physical coordinates Y_physical = y_cut * k.
[0098] In this embodiment, 830×0.05=41.5mm is calculated from the top of the image or a fixed reference point. The actual robot coordinate system needs to be offset, and this step only outputs the relative coordinates.
[0099] S603, Output and Fault Tolerance, outputs three key values: The physical coordinates of the bottleneck edge are Y_up = y_up × k Bottleneck lower edge physical coordinate Y_down = y_down × k The physical coordinates of the bottle cutting position are Y_cut = y_cut × k The data is transmitted to the robot bottle-cutting control module to drive the grinding wheel or blade to press down.
[0100] Fault tolerance mechanism: If no valid lower or upper edge is found in S4 or S5, for example, y_down does not exist or Δy is out of range, the system automatically returns to S103, uses a larger struct, such as 5×5, to re-perform the morphological closing operation, and reduces the adaptive threshold coefficient, T_valley=μ*0.5, and retries a maximum of 3 times.
[0101] If the process still fails, an alarm for bottleneck feature recognition failure will be reported, the bottle cutting process will be suspended, and manual intervention will be requested.
[0102] The above are all preferred embodiments of this application, and are not intended to limit the scope of protection of this application. Therefore, all equivalent changes made in accordance with the structure, shape and principle of this application should be covered within the scope of protection of this application.
Claims
1. A method for locating the characteristic position of the neck of an ampoule, characterized in that, Includes the following steps S1, Obtain the complete binary mask of the ampoule, wherein the bottle body area and the background area have different pixel values in the mask; S2, for the complete binarized bottle mask, traverse row by row, and translate all bottle pixels in each row as a whole towards the zero point of the X-axis, so that the bottle pixels in each row are aligned with the zero point of the X-axis, thereby amplifying the radial width difference of the bottleneck in the X-axis direction and forming a magnified image of the width feature. S3, For the image after width feature magnification, count the number of pixels in the bottle body area row by row to construct a pixel width sequence that varies with the Y-axis height; S4, perform valley detection on the pixel width sequence to identify the width valley corresponding to the bottleneck region; S5. Within the Y-axis interval corresponding to the width trough, find the minimum pixel width point and determine the Y-axis coordinate corresponding to the minimum point as the bottle cutting reference position.
2. The method of claim 1, wherein, In step S2, shifting all bottle pixels in each row towards the zero point of the X-axis specifically involves: for each row, calculating the minimum or maximum X-coordinate of the bottle pixels in that row, shifting all bottle pixels in the row to the left or right, aligning the left or right boundary of the bottle pixels in that row to the zero point of the X-axis, while keeping the relative X-axis distance between pixels in that row unchanged.
3. The method of claim 1, wherein, The trough detection in S4 further includes: using an adaptive threshold to divide the peaks and troughs, identifying the position where the height and width of the bottle body's peak first drops below the trough threshold and the drop is not less than 20% of the width of the main peak, as the lower edge of the bottleneck; and identifying the position where the width of the bottleneck trough rises from the end of the bottleneck and breaks through the peak threshold and the rise is not less than 30% of the minimum width of the bottleneck, as the upper edge of the bottleneck; the bottleneck region is the Y-axis interval between the lower edge of the bottleneck and the upper edge of the bottleneck.
4. The method of claim 1, wherein, S3, after constructing the pixel width sequence, further includes: using the 3σ criterion to remove outliers in the width sequence, and using a sliding window filter to smooth the width sequence.
5. The method of claim 1, wherein, The method for obtaining the complete binary bottle mask in S1 includes: using an image segmentation model to perform semantic segmentation on the original image of the ampoule in the gripper holding state to obtain an initial mask; then using a gripper occlusion gap filling algorithm to repair the contour loss caused by gripper occlusion to generate a complete binary mask with closed contour; and performing morphological closing operation on the mask to remove noise and burrs.
6. The method of claim 1, wherein, Before trough detection, S4 further includes setting minimum and maximum spacing constraints between the lower and upper edges of the bottle neck based on the physical range of the bottle neck height, in order to eliminate false troughs.
7. The method of claim 1, wherein, The method further includes: S6. The pixel coordinates of the bottle-cutting reference position are combined with the pre-calibrated pixel equivalents and converted into physical coordinates that can be recognized by the robot bottle-cutting execution module, and then output to the robot control system.
8. The method of claim 1, wherein, The method is compatible with ampoules of at least 2ml, 5ml, 10ml, and 20ml sizes, and is applicable to ampoules made of both transparent and brown glass.
9. The method of claim 1, wherein, If no valid width valley is detected in S4, the process automatically returns to S1, re-acquires the complete binary bottle mask, and then adjusts the structuring element size or filtering parameters of the morphological closing operation before executing again.
10. The method of claim 1, wherein, In the complete binary bottle mask, the pixel value of the bottle area is 255, and the pixel value of the background area is 0; the length of the pixel width sequence is equal to the number of pixel rows in the image height direction.