Medicine bottle counting method for full-automatic medicine bottle counting equipment of intravenous administration center

Through camera vertical shooting and elliptical fitting technology, the problems of incomplete contour and weak anti-interference ability in bottle counting are solved, and accurate statistics of the number of bottles are achieved.

CN120411014AActive Publication Date: 2025-08-01THE FIRST HOSPITAL OF HUNAN UNIV OF CHINESE MEDICINE (CLINICAL RES INST OF TRADITIONAL CHINESE MEDICINE)
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202510492604.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-18
Publication Date
2025-08-01
Estimated Expiration
2045-04-18

AI Technical Summary

Technical Problem

The prior art has the problem that the complete bottle profile and weak anti-interference ability cannot be captured in the counting of static central medicine bottles, resulting in low counting accuracy, especially in complex environments that are prone to misjudgment and missed detection.

Method used

The camera is used to take the image of the medicine bottle vertically downward, and the bottle outline is obtained through edge detection. The bottle head and bottle shoulder position are separated by ellipse fitting technology, and classified according to the width of the ellipse major axis, and matched in the order of the ellipse center coordinates to ensure the complete extraction of the bottle outline and anti-interference ability.

Benefits of technology

It improves the accuracy and anti-interference ability of the bottle count, reduces the error detection rate and missed detection rate, and is suitable for detection scenarios with complex backgrounds and large interference from reflection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120411014A_ABST
    Figure CN120411014A_ABST
Patent Text Reader

Abstract

The invention discloses a medicine bottle counting method for full-automatic medicine bottle counting equipment of an intravenous dispensing center, and relates to the technical field of image vision, and the method comprises the steps: firstly, carrying out the edge detection of a medicine bottle image, then obtaining an ellipse shape at least including the outline of a medicine bottle head and a bottle shoulder through a shape fitting mode, dividing the ellipse into two types according to the size, then selecting a first type of ellipses in sequence, searching a second type of ellipses in a preset matching range for matching, marking two successfully matched contours as the same medicine bottle contour, and finally counting the number of the medicine bottle contours; according to the technical scheme, the key features of the local position of the medicine bottle can be accurately captured, interference of other noisy points or non-target ellipses can be filtered out in a mode of matching different contours, the false detection rate and the omission ratio are reduced, the method is suitable for detection scenes with complex backgrounds and large reflection interference, and the detection efficiency is improved. The number of the medicine bottles can be accurately counted.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of image vision. Specifically, it relates to a method for counting medicine bottles for a fully automatic medicine bottle counting device in a intravenous admixture center. Background Art

[0002] In the intravenous admixture center, it is often necessary to unpack medicine bottles. After unpacking, it is also necessary to count and statistics different types of medicine bottles. Currently, the main method for counting the number of medicine bottles in the intravenous admixture center is manual counting. This method will increase the workload in the case of a large number of medicine bottles and a complex environment. Especially during long-term work, people's attention will decline, resulting in an increase in the error rate, a slowdown in the statistical speed, and the problem of omission and duplicate statistics caused by human negligence in the manual counting method.

[0003] In the prior art, image vision technology is also used for machine counting. The statistical method of machine counting has high requirements for the clarity of the captured medicine image. When there are interfering objects or other objects that cause image distortion in the image, the accuracy of machine counting will decrease.

[0004] Currently, the general method for counting medicine bottles in image vision technology is contour extraction counting or counting according to a circular contour. When using image vision technology for machine counting, due to the centrality of camera imaging, for the medicine bottles at the edge position, the camera does not shoot directly above it, but has a certain small angle of inclination. There will be a little occlusion in the edge area. Therefore, the imaging of the medicine bottles in the edge area of the captured image has a discontinuous edge line, and the complete contour cannot be extracted, resulting in a low counting accuracy; in addition, when counting according to a circular contour, since the contour imaging of the medicine bottles in the edge area is not circular, it is often difficult to extract a perfect circular contour due to reasons such as reflection or shooting angle inclination, resulting in inaccurate detection quantity. Summary of the Invention

[0005] The purpose of this application is to provide a method for counting medicine bottles for a fully automatic medicine bottle counting device in a intravenous admixture center, to solve the problems of inability to capture the complete medicine bottle contour and weak anti-interference ability in the existing recognition methods, and to improve the accuracy of medicine bottle counting.

[0006] The technical solution of this application is: A method for counting medicine bottles for a fully automatic medicine bottle counting device in a intravenous admixture center is provided. The method includes:

[0007] Step 1, use a camera to vertically shoot down the target medicine bottle image, perform edge detection on the medicine bottle image, and obtain a medicine bottle contour map, where the medicine bottle contour at least includes the head and shoulder positions of the medicine bottle;

[0008] Step 2: Curve fit the edge pixel points in the contour diagram of the medicine bottle according to a circular or elliptical contour to detect the elliptical shapes at the head and shoulder positions of the medicine bottle;

[0009] Step 3: Classify the fitted ellipses into two categories according to the major axis width. The first category of ellipses corresponds to the shoulder of the medicine bottle, and the second category of ellipses corresponds to the head of the medicine bottle. The major axis width of the first category of ellipses is greater than that of the second category of ellipses;

[0010] Step 4: Traverse each ellipse of the first category in sequence as the pairing reference. For the currently selected ellipse of the first category, search for ellipses of the second category within a preset matching range around it, and determine whether there is a unique ellipse of the second category within this preset matching range. If so, pair the two ellipses. If there is no ellipse of the second category, delete the selected ellipse of the first category. If there are multiple ellipses of the second category, search for a connection band between the currently selected ellipse of the first category and each ellipse of the second category. For a single pair of two ellipses, if there is a connection band between them, pair the current two ellipses. If there is no connection band between them, traverse the next ellipse of the second category until a paired ellipse of the second category is found;

[0011] Among them, after each single fitted ellipse is traversed, the two paired ellipses are removed from the ellipses to be paired;

[0012] Step 5: Mark the two paired ellipses as the contour of the same target medicine bottle, count the number of all target medicine bottle contours in the image, and finally obtain the number of target medicine bottles.

[0013] Further, Step 2 specifically includes:

[0014] Step 21: Select a single pixel point from the edge point set in sequence, and take this pixel point and multiple spaced points within its neighborhood range as sample points and substitute them into the ellipse equation to calculate the curve parameters corresponding to the current sample points. The neighborhood range is larger than the pixel area covered by a single medicine bottle in the image;

[0015] Step 22: Verify whether the curve parameters corresponding to the current sample points meet the constraint conditions of the ellipse. If they meet, take the ellipse corresponding to the current sample points as the initial ellipse and execute Step 23. If they do not meet, return to Step 21 and sequentially traverse the next point in the edge point set;

[0016] Step 23: Substitute the pixel points within the coverage range of the ellipse into the initial ellipse, perform iterative fitting and optimization to obtain the final fitted ellipse, mark the corresponding contour points as the boundary points of this fitted ellipse, and then sequentially traverse the next point in the edge point set P until all points are traversed.

[0017] Further, Step 21 specifically includes:

[0018] Select points from the edge point set P in order according to the priority of row coordinates. After each point is selected, n interval points within the neighborhood range of this point are used as sample points, where n ≥ 6. Substitute the coordinate values of these n sample points into the ellipse equation to construct an ellipse fitting linear equation system:

[0019]

[0020] In the formula, A, B, C, D, E, and F are respectively the parameters of the ellipse. Denote the ellipse fitting linear equation system as Mp = 0, where M is the coefficient matrix, p is the ellipse parameter matrix, T is the matrix transpose. When n = 6, directly calculate the matrix p by the elimination method. When n > 6, use the least squares method to fit the ellipse parameter matrix p.

[0021] Furthermore, in step 23, the expression for the center coordinates (x0, y0) of the ellipse is:

[0022]

[0023] In the formula, x0 is the column coordinate of the ellipse center, and y0 is the row coordinate of the ellipse center.

[0024] Furthermore, step 4 specifically includes:

[0025] Step 41, select a single first - type ellipse in the contour map in the order of row coordinate priority and coordinates from small to large. Search whether there is a second - type ellipse within the preset matching range of the current ellipse. If there is a unique second - type ellipse, pair the two ellipses. If no second - type ellipse is found, remove the currently selected first - type ellipse and sequentially traverse the next first - type ellipse;

[0026] Step 42, if there are multiple second - type ellipses within the preset matching range of the currently selected first - type ellipse, set bounding boxes for the regions where the currently selected first - type ellipse and each second - type ellipse are located in the contour map;

[0027] Step 43, construct a matching group with the currently selected first - type ellipse and each second - type ellipse. For each matching group, use the straight line where the centers of the two types of ellipses in the current matching group are located as the dividing line to divide the other pixel points in the current bounding box except the ellipse contour points, obtaining two straight - line fitting regions, and perform straight - line fitting on the pixel points in the straight - line fitting regions respectively;

[0028] Step 44: For each matching group, determine whether there is a fitted line connecting two ellipses in the current bounding box. If so, it is determined that there is a connection band between the current two ellipses, pair the two ellipses in the current matching group and remove them from the ellipses to be matched. If not, check the next matching group. If all the matching groups corresponding to the currently selected first type of ellipses cannot be paired, return to Step 41, re-find the next first type of ellipse and repeat the pairing process.

[0029] Further, in Step 42, set a bounding box for the area where the two ellipses of the current matching group are located in the contour map, specifically including:

[0030] Read the maximum column coordinate, minimum column coordinate, maximum row coordinate, and minimum row coordinate from the area where the currently selected first type of ellipse and any second type of ellipse within the preset matching range are located, and use the rectangle formed by the columns where the maximum column coordinate and minimum column coordinate are located and the rows where the maximum row coordinate and minimum row coordinate are located as the bounding box of the current two ellipses.

[0031] Further, Step 43 specifically includes:

[0032] For a single line fitting area, calculate the mean of the column coordinates of all pixel points The mean of the row coordinates Covariance Cov(x,y) and variance Var(x), expressed as:

[0033]

[0034] In the formula, (x j ,y j ) is the coordinate of the j-th pixel point in the line fitting area, and the fitted line is expressed as:

[0035] y = kx + b

[0036]

[0037] In the formula, k is the slope and b is the intercept.

[0038] Further, the connection band is the area where the fitted line that meets the pairing condition is located in the current bounding box, and the pairing condition is that the angle between the fitted line and the line where the centers of the current two ellipses are located is within the preset angle range.

[0039] Further, Step 44 also includes:

[0040] Find the line where the centers of the current two ellipses are located as the first line, use each fitted line as the second line, compare the second line with the first line in turn, and calculate the angle between the two sets of lines based on the slope. The angle between the first line and the second line is expressed as:

[0041]

[0042] In the formula, θ is the included angle between the first straight line and the second straight line, k1 is the slope of the first straight line, k2 is the slope of the second straight line. If k1 does not exist, then k = k2; if k2 does not exist, then k = k1.

[0043] The inventors of the present application found that during the process of taking pictures of medicine bottles, the bottle tops and bottle shoulders of medicine bottles often do not have a perfect circular contour, but have certain elliptical properties, and there are often connecting contours between the bottle tops and bottle shoulders. Therefore, the present invention proposes to use an elliptical model and cooperate with the connecting contours between the elliptical models for medicine bottle detection, and its effect is better than the existing solutions of counting by contour extraction or counting according to a circular contour; the inventors of the present application found that due to the existence of the camera optical axis, when it shoots vertically downward, the medicine bottles in the area directly below it can capture complete contours, while the medicine bottles at the edge of the shooting area will block each other and cannot capture complete contours. By counting through contour extraction, only some medicine bottles can be covered, and there will be omissions, and the accuracy of counting is relatively low; and the method of counting according to a circular contour also faces the same problem. Moreover, it will also be affected by the camera optical axis and cannot extract the circular contour of the medicine bottles at the edge, resulting in missed counting. In addition, the method of counting according to a circular contour is also easily interfered by reflection. Since the bottleneck part of the medicine bottle is relatively thin, it is easy to have the situation of liquid medicine hanging on the wall, and the reflectivity of the liquid medicine is relatively strong. When extracting the contour, the contour of the liquid medicine in the bottleneck will be extracted. The contour of the liquid medicine in the bottleneck is similar to the contour size of the head of the medicine bottle, which is prone to misjudgment and reduces the accuracy of counting. The solution proposed in the present invention to use an elliptical model and cooperate with the connecting contours between the elliptical models for medicine bottle detection can solve the problems in the existing solutions. The present invention classifies the fitted elliptical contours into two categories according to the width size, and then traverses each first-category ellipse in the order of the elliptical center coordinates, searches for the second-category ellipses within a preset matching range for matching, and finally determines the number of matching groups. In this way, it can avoid the problem of being unable to extract the complete medicine bottle contour and reduce the interference when counting according to a single circular contour, and more accurately detect the number of medicine bottles.

[0044] The beneficial effects of the present application are:

[0045] The technical solution in this application extracts the contours of local regions with distinct geometric features in the medicine bottle through shape fitting, and then matches the extracted different contours to accurately count the number of medicine bottles based on the number of matching contours. Compared with the existing technical methods, the technical solution in this application improves the accuracy and anti-interference ability of medicine bottle number counting. The object recognition and counting methods in the existing technology rely on the recognition of the overall contour of the object or the recognition of a single circular contour. In the complex background where medicine bottles are mutually blocked and under the interference of light reflection, it is difficult to effectively distinguish medicine bottles. Especially for transparent or semi-transparent medicine bottles, misrecognition or missed recognition is likely to occur. However, the method in this application can capture the key features of the local position of the medicine bottle more clearly, and can also filter out the interference of other noise points or non-target contours by matching different contours, greatly reducing the false detection rate and missed detection rate. In contrast, the technical solution in this application is more suitable for detection scenarios with complex backgrounds and large light reflection interference, and can accurately count the number of medicine bottles. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] The above and / or additional aspects of the present application will become obvious and easy to understand when combined with the description of the embodiments in conjunction with the following drawings, where:

[0047] Figure 1 is a schematic flowchart of a medicine bottle counting method for a fully automatic medicine bottle counting device in a static distribution center according to an embodiment of the present application;

[0048] Figure 2 is a schematic diagram of the angle between the straight line where the centers of two types of ellipses are located and the fitting straight line according to an embodiment of the present application;

[0049] Figure 3 is an image of a target medicine bottle taken vertically downward by a camera according to an embodiment of the present application;

[0050] Figure 4 is a contour diagram of a target medicine bottle according to an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0051] In order to more clearly understand the above objects, features, and advantages of the present application, the present application will be further described in detail below in conjunction with the drawings and specific embodiments. It should be noted that, without conflict, the embodiments of the present application and the features in the embodiments can be combined with each other.

[0052] In the following description, many specific details are set forth in order to fully understand the present application. However, the present application can also be implemented in other ways different from those described herein. Therefore, the protection scope of the present application is not limited by the specific embodiments disclosed below.

[0053] The Canny edge detection used in this embodiment is an image edge detection algorithm. This algorithm aims to detect edges in an image and extract the contours, and is widely used in the fields of computer vision and image processing. The output of the Canny edge detection is a binary image, which can display the edges of objects and intuitively show the contours in the image.

[0054] As Figure 1 shown, this embodiment provides a method for counting medicine bottles for a fully automatic medicine bottle counting device in a static dispensing center, including:

[0055] Step 1, use a camera to vertically downward shoot the target medicine bottle to obtain a medicine bottle image, perform edge detection on the medicine bottle image to obtain a medicine bottle contour map, where the medicine bottle contour at least includes the medicine bottle head and the position of the medicine bottle shoulder.

[0056] Place the target medicine bottle in the shooting area, set the camera directly above the shooting area, adjust the camera so that the camera lens shoots vertically downward, and clearly capture the images of all target medicine bottles in the shooting area. Use the Canny edge detection algorithm to extract the contour shapes in the image (set the edge gradient threshold and retain the pixels with gradients greater than the threshold) to obtain the contour maps of each medicine bottle in the image. Among them, the contour map of the target medicine bottle is a binary image, where the white part represents the detected edge contour of the target medicine bottle, and the black part represents the non-edge background area.

[0057] Step 2, perform curve fitting on the edge pixel points in the medicine bottle contour map according to a circular or elliptical contour to detect the elliptical shapes at the positions of the medicine bottle head and the bottle shoulder.

[0058] Take all the edge pixel points in the medicine bottle contour map as the edge point set P(x i , y i ), where (x i , y i ) are the column coordinate and row coordinate of the i-th point in the edge point set P. Traverse the edge point set, and each time a single ellipse is fitted, mark the found elliptical contour points (the contour points are the points covered by the fitted elliptical contour in the edge point set P) as the boundary points of the fitted ellipse. Stop traversing until the number of remaining un-traversed points in the edge point set P is less than the number of samples required for fitting or all points in the edge point set P have been traversed; The specific steps for traversing a single pixel point are as follows:

[0059] Step 21: Select a single pixel point from the edge point set P in sequence, and take this pixel point and multiple spaced points within its neighborhood range as sample points and substitute them into the ellipse equation to calculate the curve parameters corresponding to the current sample points. The neighborhood range is set according to an empirical value, which is larger than the pixel area covered by a single medicine bottle in the image. Among them, the spaced points are multiple points extracted at a preset interval within the neighborhood range, and the preset interval can be set to 1 - 5 pixels; more preferably, before fitting, pixel points are merged in the way of 2*2, 3*3 or 4*4 to reduce the number of calculations.

[0060] In the order of row coordinate priority, select points from the edge point set P in sequence (that is, in the order of increasing coordinate values, and for an image, the pixel row and column coordinate values in the upper left corner are the smallest). After each point is selected, take n spaced points within the neighborhood range of this point as sample points, where n≥6. Substitute the coordinate values of these n sample points into the ellipse equation to construct an ellipse fitting linear equation system. The ellipse equation is expressed as:

[0061]

[0062] In the formula, A, B, C, D, E, and F are respectively the parameters of the ellipse; the ellipse fitting linear equation system is expressed as:

[0063]

[0064] Denote the ellipse fitting linear equation system as Mp = 0, where M is an n×6 coefficient matrix, p is an ellipse parameter matrix, and p = [A, B, C, D, E, F] T , T is the matrix transpose. When n = 6, directly calculate the matrix p by the elimination method. When n>6, use the least squares method to fit the ellipse parameter matrix p;

[0065] Since there is no unique solution for p when n is greater than 6, it is necessary to find the optimal solution of the ellipse parameter matrix; use the least squares method to fit the ellipse parameter matrix p to make ||Mp|| 2 minimize, that is, find the optimal solution of p when Mp≈0. Let M T MP = 0, perform eigenvalue decomposition on M T M. The eigenvalue λ and eigenvector s satisfy the equation (M T M)s = λs. Rewrite this equation as (M T M - λI)s = 0. In the formula, I is the identity matrix, which is used to ensure that the matrices are still of the same dimension after subtraction. Since λ is the eigenvalue of M T M, the matrix (M T M - λI) is not a full-rank matrix, and the determinant of the matrix (M T M - λI) is equal to zero, obtaining det(M T(M - λI) = 0. All eigenvalues λ (multiple eigenvalues can be obtained) are found using this determinant equation, and the smallest eigenvalue λ is taken. min , and then solve the equation (M T M - λ min I)s = 0 to obtain the eigenvector s corresponding to the smallest eigenvalue λ min , and use it as the ellipse parameter matrix p.

[0066] Step 22: Verify whether the curve parameters corresponding to the current sample point satisfy the constraint conditions of the ellipse. If they are satisfied, take the ellipse corresponding to the current sample point as the initial ellipse and execute Step 23. If not, return to Step 21 and sequentially traverse the next point in the edge point set P.

[0067] After obtaining the ellipse parameter matrix p, verify whether the ellipse parameters corresponding to the current sample point satisfy the ellipse constraint condition B 2 -4AC < 0. If they are satisfied, take the ellipse corresponding to the current sample point as the initial ellipse, execute Step 23 for the initial ellipse, calculate the contour points of the ellipse corresponding to the current sample point. If not, return to Step 21, select the next pixel point from the edge point set P in sequence, and calculate the corresponding curve parameters again until a sample point that satisfies the ellipse constraint condition or the condition for stopping traversal is reached (that is, the number of remaining un-traversed points in the edge point set P is less than the number of samples required for fitting or all points in the edge point set P have been traversed).

[0068] Step 23: Substitute the pixel points within the coverage range of the ellipse into the initial ellipse, perform iterative fitting and optimization to obtain the final fitted ellipse, and mark the contour points corresponding to the fitted ellipse as the boundary points of the fitted ellipse. Among them, the boundary points are not traversed sequentially, but still participate in the process of finding contour points (that is, a point may be marked as the boundary point of multiple ellipses). Then, sequentially traverse the next point in the edge point set P until the condition for stopping traversal is reached, and finally obtain multiple ellipses and their corresponding center coordinates.

[0069] Calculate the center coordinates of the ellipse according to the parameters A, B, C, D, E, F of the final fitted ellipse. The expression for the center coordinates (x0, y0) of the ellipse is:

[0070]

[0071] In the formula, x0 is the column coordinate of the ellipse center, and y0 is the row coordinate of the ellipse center.

[0072] In this embodiment, after obtaining the parameters A, B, C, D, E, F of the ellipse, calculate the set center (x0, y0) and the major axis a of the ellipse according to these parameters.

[0073] In this embodiment, the fitted ellipse includes a circle. When parameter B is 0 and parameter A is equal to C, the ellipse degenerates into a circle.

[0074] In this embodiment, there are multiple medicine bottles in the shooting area. The medicine bottles in the edge area cannot be photographed completely to show the contour, and it is easy to miss detection through contour counting. If only the head of the bottle body is identified, it is easily affected by the contour of the liquid medicine hanging on the bottleneck, resulting in inaccurate detection quantity. If the head and shoulder are jointly detected, more bottle body information can be obtained and the detection can be more accurate.

[0075] Step 3: Divide the fitted ellipses into two categories according to the major axis width. The first type of ellipse corresponds to the shoulder of the medicine bottle, and the second type of ellipse corresponds to the head of the medicine bottle. The major axis width of the first type of ellipse is greater than that of the second type of ellipse.

[0076] Calculate the major axis width of each fitted ellipse based on the parameters of the ellipse. The fitted ellipse with the major axis width within the first width threshold range (set according to the size of the bottle shoulder) is used as the first type of ellipse corresponding to the shoulder of the medicine bottle, and the fitted ellipse with the major axis width within the second width threshold range (set according to the size of the bottle head) is used as the second type of ellipse corresponding to the head of the medicine bottle. Among them, the major axis direction width 2a is expressed as:

[0077]

[0078] Step 4: Traverse each first type of ellipse in sequence as the pairing reference. For the currently selected first type of ellipse, search for the second type of ellipse within the preset matching range around it, and determine whether there is a unique second type of ellipse within this preset matching range. If so, pair the two ellipses. If the second type of ellipse is not included, delete the selected first type of ellipse. If there are multiple second type of ellipses, search for a connecting band between the currently selected first type of ellipse and each second type of ellipse. For a single group of two ellipses, if there is a connecting band between them, pair the current two ellipses. If there is no connecting band between them, traverse the next second type of ellipse until a paired second type of ellipse is found. Among them, after each single fitted ellipse is traversed, the two paired ellipses are removed from the ellipses to be paired. Preferably, when fitting the ellipse, increase the error tolerance, regard semi-ellipses and approximate ellipses as ellipses, and then perform secondary confirmation through the connecting band between the ellipses to reduce the possibility of missed detection.

[0079] Step 41, in the order of row coordinate first and coordinate values from small to large (i.e., the order of coordinate values from small to large, which is from top to bottom and from left to right in the figure), select a single first - type ellipse in the contour map (it is possible to select a first - type ellipse or a second - type ellipse, preferably select the ellipse corresponding to the bottle shoulder, that is, the first - type ellipse). Check whether there is a second - type ellipse within the preset matching range of the current ellipse. If there is a unique second - type ellipse, pair the two ellipses. If no second - type ellipse is found, remove the currently selected first - type ellipse from the ellipses to be paired, and sequentially traverse the next first - type ellipse;

[0080] In this embodiment, before counting the medicine bottles, first collect a medicine bottle image for ellipse fitting, and then manually label the two paired ellipses, calculate the center distance of each pair of ellipses, and take the maximum distance from the center of the medicine bottle head to the center of the medicine bottle shoulder in the image as the radius of the preset matching range.

[0081] The preset matching range is a circular area with the center of a single first - type ellipse as the center, and the radius of the preset matching range is greater than the maximum distance from the center of the medicine bottle head to the center of the medicine bottle shoulder in the image; for a single first - type ellipse, calculate the center distance between it and each second - type fitting ellipse within the preset matching range, and select the second - type ellipse with the center distance less than the radius of the preset matching range as the object to be matched; among them, the center distance d between the first - type ellipse and the second - type ellipse is expressed as:

[0082]

[0083] In the formula, x 0,c1 is the column coordinate of the current first - type ellipse, x 0,c2 is the column coordinate of the current second - type ellipse, y 0,c1 is the row coordinate of the current first - type ellipse, y 0,c2 is the row coordinate of the current second - type ellipse.

[0084] Step 42, if there are multiple second - type ellipses within the preset matching range of the currently selected first - type ellipse, set bounding boxes for the regions where the currently selected first - type ellipse and each second - type ellipse are located in the contour map;

[0085] Read the maximum column coordinate, minimum column coordinate, maximum row coordinate, and minimum row coordinate from the region where the currently selected first - type ellipse and any second - type ellipse within the preset matching range are located, and use the rectangle formed by connecting the column where the maximum column coordinate and minimum column coordinate are located and the row where the maximum row coordinate and minimum row coordinate are located as the bounding box of the current two ellipses.

[0086] Step 43: Construct matching groups with the currently selected first - type ellipses and each second - type ellipse. For each matching group, use the line passing through the centers of the two types of ellipses in the current matching group as the dividing line to divide the other pixel points in the current bounding box except for the ellipse contour points into two line - fitting regions, and perform line fitting on the pixel points in the line - fitting regions respectively.

[0087] Perform line fitting on all points in a single line - fitting region. Specifically, calculate the mean of the column coordinates of all pixel points in the line - fitting region and the mean of the row coordinates the covariance Cov(x,y) of all pixel points (used to describe the joint change trend of x and y) and the variance Var(x) (used to describe the degree of dispersion of x), expressed as:

[0088]

[0089]

[0090] where (x j ,y j ) is the coordinate of the j - th pixel point in the line - fitting region, and the fitted line is expressed as:

[0091] y = kx + b

[0092]

[0093] where k is the slope and b is the intercept.

[0094] Step 44: For each matching group, determine whether there is a fitted line that satisfies the pairing condition and connects the two ellipses in the current bounding box. If so, determine that the two ellipses in the current matching group are matched, pair the two ellipses in the current matching group and remove them from the ellipses to be matched, and regard them as a successfully paired matching group. If not, check the next matching group. If none of the matching groups corresponding to the currently selected first - type ellipses can be paired, return to Step 41, re - search for the next first - type ellipse and repeat the pairing process.

[0095] The fitted line that satisfies the pairing condition and connects the two ellipses is judged as follows:

[0096] Find the line passing through the centers of the current two ellipses as the first line, regard each fitted line as the second line, compare the second line with the first line in turn, and calculate the included angle between the two groups of lines based on the slope. The included angle between the first line and the second line is expressed as:

[0097]

[0098] In the formula, θ is the angle between the first straight line and the second straight line, k1 is the slope of the first straight line, and k2 is the slope of the second straight line. In the second formula above, if k1 does not exist, then k=k2, and if k2 does not exist, then k=k1.

[0099] A determination is made as to whether a fitted line that meets the matching criteria exists within the current bounding box. If so, a determination is made that a connecting band exists between the two ellipses, and the two ellipses in the current matching group are paired and removed from the set of fitted ellipses to be matched. If no fitted line exists, the second type of ellipse in the current group is excluded, and the next matching group is determined. In this embodiment, the preset angle range can be set to 0° to 20°.

[0100] For a single first-class ellipse, if there are multiple second-class ellipses within the preset matching range that can be paired with it, the two ellipses in the matching group whose angle is closest to the bottle's own angle are considered the two successfully paired ellipses, and the remaining matching groups are discarded. In this embodiment, the bottle's own angle can be set to 8°.

[0101] like Figure 2 As shown, the image on the left shows the original image of a single target medicine bottle. After contour extraction, the image on the right is obtained. Ellipse fitting is performed on the right image to obtain two fitted ellipses. The green lines in the figure represent the two fitted ellipses. The ellipse with the shorter major axis corresponds to the location of the medicine bottle head, and the ellipse with the longer major axis corresponds to the location of the medicine bottle shoulder. The blue line in the figure is the straight line tracing the centers of the two ellipses, and the red line is a fitted straight line. The angle between the two is θ. In this embodiment, a higher gradient threshold is set to better highlight the contours of the top and shoulder.

[0102] Step 5: Mark the two successfully paired ellipses as the same target bottle outline, count the number of all target bottle outlines in the image, and finally obtain the number of target bottles.

[0103] Examples:

[0104] Use the camera to shoot vertically downwards. Figure 3 As shown in the image of the medicine bottle, it can be seen from the figure that the head and shoulder of the medicine bottle can be clearly seen, while other parts are blocked; edge detection is performed on the medicine bottle image, and the following is obtained: Figure 4 As shown in the medicine bottle outline diagram, it can be seen that the outlines of the bottle head, bottle shoulder and bottle neck are relatively clear, while the outlines of other positions are blurred and the complete bottle outline cannot be extracted; the medicine bottle outline diagram is curve fitted according to the circle or ellipse outline to obtain the elliptical shape of the bottle head and bottle shoulder, and the fitted ellipse is divided into the first type of ellipse and the second type of ellipse, among which the green ellipse is the first type of ellipse and the red ellipse is the second type of ellipse.

[0105] To illustrate the matching situation, take the outlines of two medicine bottles in the figure as examples. For example, Figure 4 As shown, there is a nested situation for the two types of ellipses in the middle of the image, that is, the center of the second type of ellipse is located within the area of the first type of ellipse. In this case, there is a unique second type of ellipse within the preset matching range of the first type of ellipse. Therefore, these two ellipses belong to the same target medicine bottle outline; there is no nested situation for the two types of ellipses above the image, that is, the center of the second type of ellipse is not within the area of the first type of ellipse. As can be seen from Figure 4 , there is a connection band between the second type of ellipse and the first type of ellipses numbered 1, 2, and 3, and between the red second type of ellipse and the first type of ellipse numbered 1. The pixel points in the yellow square in the figure can fit a straight line, and the fitted straight line meets the pairing conditions, so the two ellipses can be paired. However, there is no connection band between the red second type of ellipse and the second type of ellipses numbered 2 and 3, so the two ellipses cannot be paired. Therefore, this second type of ellipse and the first type of ellipse numbered 1 belong to the same target medicine bottle outline.

[0106] The technical solution of the present invention is applicable to transparent glass medicine bottles or plastic medicine bottles, semi-transparent glass medicine bottles or plastic medicine bottles, such as common ampoule bottles, and is particularly applicable to glass medicine bottles. The glass medicine bottles are filled with liquid medicine, and violent collisions need to be avoided as much as possible during transportation. Therefore, the existing counting method using a stepped structure (setting steps of different heights to let objects roll down for counting) cannot count glass bottles. Also, because glass bottles are transparent and have strong reflectivity, the complete outline cannot be recognized when using machine recognition. At the same time, it is also affected by the liquid medicine hanging on the wall in the bottleneck. When the recognition fails with the outline of a single shape, it is easy to make mistakes, resulting in inaccurate statistics.

[0107] The steps in this application can be adjusted, combined, and deleted according to actual needs.

[0108] The units in the device of this application can be combined, divided, and deleted according to actual needs.

[0109] Although this application is disclosed in detail with reference to the accompanying drawings, it should be understood that these descriptions are merely exemplary and are not used to limit the application of this application. The protection scope of this application is defined by the appended claims and may include various modifications, improvements, and equivalent solutions made to the invention without departing from the protection scope and spirit of this application.

Claims

1. A method for counting medicine bottles of a fully automatic medicine bottle counting device for a static dispensing center, characterized in that, The method includes: Step 1: Use a camera to vertically downward shoot an image of the target medicine bottle, perform edge detection on the medicine bottle image to obtain a medicine bottle contour map, where the medicine bottle contour at least includes the head and the shoulder position of the medicine bottle; Step 2: Curve fit the edge pixel points in the medicine bottle contour map according to a circular or elliptical contour to detect the elliptical shapes at the head and the shoulder position of the medicine bottle; Step 3: Divide the fitted ellipses into two categories according to the major axis width. The first type of ellipse corresponds to the shoulder of the medicine bottle, and the second type of ellipse corresponds to the head of the medicine bottle. The major axis width of the first type of ellipse is greater than that of the second type of ellipse; Step 4: Traverse each first type of ellipse in sequence as a pairing reference. For the currently selected first type of ellipse, search for the second type of ellipse within a preset matching range around it, and determine whether the preset matching range contains a unique second type of ellipse. If so, pair the two ellipses. If the second type of ellipse is not included, delete the selected first type of ellipse. If there are multiple second type of ellipses, search for a connection band between the currently selected first type of ellipse and each second type of ellipse. For a single group of two ellipses, if there is a connection band between them, pair the current two ellipses. If there is no connection band between them, traverse the next second type of ellipse until a paired second type of ellipse is found; Among them, after each single fitted ellipse is traversed, the two paired ellipses are removed from the ellipses to be paired; Step 5: Mark the two paired ellipses as the same target medicine bottle contour, count the number of all target medicine bottle contours in the image, and finally obtain the number of target medicine bottles.

2. The vial counting method for the fully automatic vial counting device in the intravenous admixture center according to claim 1, characterized in that, The specific content of the said Step 2 includes: Step 21: Sequentially select a single pixel point from the edge point set, and use this pixel point and multiple spaced points within its neighborhood range as sample points to substitute into the ellipse equation to calculate the curve parameters corresponding to the current sample points. The neighborhood range is larger than the pixel area covered by a single medicine bottle in the image; Step 22: Verify whether the curve parameters corresponding to the current sample points satisfy the constraint conditions of the ellipse. If they are satisfied, take the ellipse corresponding to the current sample points as the initial ellipse and execute Step 23. If they are not satisfied, return to Step 21 and sequentially traverse the next point in the edge point set; Step 23: Substitute the pixel points within the coverage range of the ellipse into the initial ellipse, perform iterative fitting optimization to obtain the final fitted ellipse, mark the corresponding contour points as the boundary points of this fitted ellipse, and then sequentially traverse the next point in the edge point set P until all points are traversed.

3. The vial counting method for the fully automatic vial counting device in the intravenous admixture center according to claim 2, wherein The specific content of the said Step 21 includes: Select points in sequence from the edge point set P in the order of row coordinate priority. After each point is selected, use n spaced points within the neighborhood range of this point as sample points, where n≧6. Substitute the coordinate values of these n sample points into the ellipse equation to construct an ellipse fitting linear equation system: In the formula, A, B, C, D, E, and F are respectively the parameters of the ellipse. Denote the ellipse fitting linear equation system as Mp=0, where M is the coefficient matrix, p is the ellipse parameter matrix, T is the matrix transpose. When n = 6, directly calculate the matrix p by the elimination method. When n>6, use the least squares method to fit the ellipse parameter matrix p.

4. The method for counting medicine bottles of the fully automatic medicine bottle counting device for intravenous admixture center according to claim 3, characterized in that, In the said step 23, the expression of the central coordinates (x0, y0) of the ellipse is: In the formula, x0 is the column coordinate of the ellipse center, and y0 is the row coordinate of the ellipse center.

5. The vial counting method for the fully automatic vial counting device in the intravenous admixture center according to claim 4, characterized in that, The said step 4 specifically includes: Step 41: Select a single first-class ellipse in the contour map in the order of row coordinate priority and coordinates from small to large, and check whether there is a second-class ellipse within the preset matching range of the current ellipse. If there is a unique second-class ellipse, pair the two ellipses. If no second-class ellipse is found, remove the currently selected first-class ellipse and sequentially traverse the next first-class ellipse; Step 42: If there are multiple second-class ellipses within the preset matching range of the currently selected first-class ellipse, set bounding boxes for the regions where the currently selected first-class ellipse and each second-class ellipse are located in the contour map; Step 43: Construct matching groups with the currently selected first-class ellipse and each second-class ellipse respectively. For each matching group, take the straight line where the centers of the two types of ellipses in the current matching group are located as the dividing line, divide the other pixel points in the current bounding box except the ellipse contour points to obtain two straight line fitting regions, and perform straight line fitting on the pixel points in the straight line fitting regions respectively; Step 44: For each matching group, check whether there is a fitting straight line connecting the two ellipses in the current bounding box. If so, determine that there is a connection band between the current two ellipses, pair the two ellipses in the current matching group and remove them from the ellipses to be matched for fitting. If not, check the next matching group. If all the matching groups corresponding to the currently selected first-class ellipse cannot be paired, return to step 41, re-search for the next first-class ellipse and repeat the pairing process.

6. The vial counting method for the fully automatic vial counting device in the intravenous admixture center according to claim 5, characterized in that, In the said step 42, setting the bounding box for the regions where the two ellipses in the current matching group are located in the contour map specifically includes: Read the maximum column coordinate, minimum column coordinate, maximum row coordinate, and minimum row coordinate from the regions where the currently selected first-class ellipse and any one second-class ellipse within the preset matching range are located, and use the rectangle formed by connecting the columns where the maximum column coordinate and minimum column coordinate are located and the rows where the maximum row coordinate and minimum row coordinate are located as the bounding box for the current two ellipses.

7. The method for counting medicine bottles of the fully automatic medicine bottle counting device for intravenous admixture center according to claim 5, characterized in that, The said step 43 specifically includes: For a single said straight line fitting region, calculate the column coordinate mean x, row coordinate mean y, covariance Cov(x, y), and variance Var(x) of all pixel points, expressed as: where (x j , y j ) is the coordinate of the j-th pixel point in the straight line fitting region, and the fitting straight line is expressed as: y = kx + b In the formula, k is the slope and b is the intercept.

8. The vial counting method for the fully automatic vial counting device in the intravenous admixture center according to claim 5, characterized in that, The said connection band is the region where the fitting straight line that meets the pairing conditions in the current bounding box is located, and the pairing condition is that the included angle between the fitting straight line and the straight line where the centers of the current two ellipses are located is within the preset angle range.

9. The vial counting method for the fully automatic vial counting device in the intravenous admixture center according to claim 8, characterized in that, The said step 44 also includes: Obtain the straight line where the centers of the current two ellipses are located as the first straight line, take each fitting straight line as the second straight line, compare the second straight line with the first straight line in turn, and calculate the included angle between the two groups of straight lines based on the slope. The included angle between the first straight line and the second straight line is expressed as: In the formula, θ is the included angle between the first straight line and the second straight line, k1 is the slope of the first straight line, k2 is the slope of the second straight line. If k1 does not exist, then k = k2; if k2 does not exist, then k = k1.

Citation Information

Patent Citations

  • PE bottle detecting and sorting method based on machine vision

    CN106824816A

  • On-line PE bottle identification and positioning method based on machine vision

    CN106875441A

  • Method for detecting the appearance quality of head of medical ampoule bottle

    CN112577967A

  • Neuron cell body identification method and device

    CN114550168A

  • Circular medicine quantity detection method based on circular power theorem

    CN115631128A