Medicine bottle counting method, system, device and computer-readable storage medium
By performing clustering processing and intersection-union data analysis on medicine bottle images, the problem of inaccurate medicine bottle counting was solved and higher counting accuracy was achieved.
Patent Information
- Application Number
- CN202111320543.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-09
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2041-11-09
AI Technical Summary
The accuracy of counting medicine bottles in the existing technology is low and the error is large, resulting in counting errors.
By clustering the target medicine bottle images, obtaining cluster center data, calculating the intersection-over-union ratio data, and comparing it with the preset threshold, accurate counting of the medicine bottles can be achieved.
The accuracy of bottle counting is improved and counting errors are reduced.
Smart Images

Figure CN114186610B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a medicine bottle counting method, system, device and computer-readable storage medium. Background Art
[0002] Currently, when using products such as hospital medicine cabinets, it is necessary to count the medicine bottles containing medicines and determine the usage status based on the number of medicine bottles. In related technologies, the accuracy of identifying medicine bottles is relatively low, with large errors, which can lead to counting errors. Summary of the Invention
[0003] The present invention aims to address at least one of the technical problems existing in the prior art. To this end, the present invention provides a medicine bottle counting method, system, device, and computer-readable storage medium. These methods can count medicine bottles by clustering target bottle images, thereby improving the accuracy of the counting process.
[0004] The medicine bottle counting method according to the first embodiment of the present invention includes:
[0005] Acquire a preset target medicine bottle image;
[0006] Perform clustering on the target medicine bottle image to obtain cluster center data;
[0007] According to the cluster center data, the intersection-over-union data corresponding to the target medicine bottle image is calculated;
[0008] Compare the preset threshold value and the intersection-union ratio data to obtain a comparison result;
[0009] The medicine bottles corresponding to the medicine bottle scatter points in the target medicine bottle image are counted according to the comparison results.
[0010] The medicine bottle counting method according to the embodiment of the present invention has at least the following beneficial effects:
[0011] By acquiring a preset target medicine bottle image; clustering the target medicine bottle image to obtain cluster center data; calculating the intersection-over-union data corresponding to the target medicine bottle image based on the cluster center data; comparing the preset threshold and the intersection-over-union data to obtain a comparison result; and counting the medicine bottles corresponding to the medicine bottle scatter points in the target medicine bottle image based on the comparison result, the clustering of the target medicine bottle image can be used to count the medicine bottles and improve the accuracy of counting the medicine bottles.
[0012] According to some embodiments of the present application, including:
[0013] Obtain a preset initial medicine bottle image;
[0014] Performing identification processing on the initial medicine bottle image to obtain identification data corresponding to the medicine bottle;
[0015] Construct the target medicine bottle image based on the identification data.
[0016] According to some embodiments of the present application, including:
[0017] Perform segmentation processing on the target medicine bottle image to generate multiple medicine bottle images;
[0018] Clustering is performed on the scattered points of each medicine bottle image to obtain cluster center data.
[0019] According to some embodiments of the present application, including:
[0020] Counting the number of medicine bottle scatter points corresponding to the medicine bottle image to obtain medicine bottle scatter point data;
[0021] Get the preset mean clustering algorithm;
[0022] The mean clustering algorithm is used to calculate and process the scattered data of medicine bottles to obtain the cluster center data.
[0023] According to some embodiments of the present application, including:
[0024] Perform mean clustering on the scattered data of medicine bottles to obtain clustered data;
[0025] Perform computational processing on the clustered data to obtain the expected data corresponding to each medicine bottle image;
[0026] According to each mean data in the expected data, the cluster center data corresponding to the target medicine bottle image is calculated.
[0027] According to some embodiments of the present application, including:
[0028] The cluster data includes at least one of the following: first sub-data, second sub-data;
[0029] The expected data includes at least one of the following: first mean data, second mean data;
[0030] The medicine bottle image includes at least one of the following: a first sub-image and a second sub-image;
[0031] performing computational processing on first sub-data in the first sub-image to obtain first center data;
[0032] Performing calculation processing on the first central data and the first sub-data to obtain first target data;
[0033] generating first mean data corresponding to the first sub-image according to the first target data;
[0034] After obtaining the first mean data, performing calculation processing on the second sub-data in the second sub-image to obtain second center data;
[0035] Performing calculation processing on the second central data and the second sub-data to obtain second target data;
[0036] Second mean data corresponding to the second sub-image is generated according to the second target data.
[0037] According to some embodiments of the present application, including:
[0038] Use the preset neural network to train the cluster center data to obtain the image recognition model;
[0039] The target medicine bottle image is recognized and processed according to the image recognition model to obtain a numerical value for counting the medicine bottles corresponding to the medicine bottle scatter points in the target medicine bottle image.
[0040] According to the second aspect of the present application, the medicine bottle counting system includes:
[0041] An acquisition module, used to acquire a preset target medicine bottle image;
[0042] Clustering module, used to perform clustering processing on the target medicine bottle image to obtain cluster center data;
[0043] A calculation module is used to calculate the intersection-over-union data corresponding to the target medicine bottle image based on the cluster center data;
[0044] A comparison module is used to compare the preset threshold value with the intersection-and-union ratio data to obtain a comparison result;
[0045] The counting module is used to count the medicine bottles corresponding to the medicine bottle scatter points in the target medicine bottle image according to the comparison result.
[0046] A medicine bottle counting device according to a third aspect of the present application includes:
[0047] at least one memory;
[0048] at least one processor;
[0049] at least one program;
[0050] The program is stored in the memory, and the processor executes at least one program to implement:
[0051] A medicine bottle counting method as in the first aspect of the present invention.
[0052] According to the fourth aspect of the present application, the computer-readable storage medium stores executable instructions, which can be executed by a computer to enable the computer to execute the medicine bottle counting method as described in the first aspect of the present invention.
[0053] Additional aspects and advantages of the present invention will be set forth in part in the description which follows and, in part, will be obvious from the description which follows, or may be learned by practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] The present invention will be further described below with reference to the accompanying drawings and embodiments, in which:
[0055] Figure 1 A schematic diagram of a specific process of the medicine bottle counting method provided by the present invention;
[0056] Figure 2 A schematic diagram of a specific flow chart of step S100 in the medicine bottle counting method provided by the present invention;
[0057] Figure 3 A schematic diagram of a specific flow chart of step S200 in the medicine bottle counting method provided by the present invention;
[0058] Figure 4 This is a specific flow chart of step S220 in the medicine bottle counting method provided by the present invention;
[0059] Figure 5 This is a specific flow chart of step S223 in the medicine bottle counting method provided by the present invention;
[0060] Figure 6 A schematic diagram of a specific flow chart of step S202 in the medicine bottle counting method provided by the present invention;
[0061] Figure 7 A schematic diagram of a specific flow chart of step S500 in the medicine bottle counting method provided by the present invention;
[0062] Figure 8 A schematic diagram of a target medicine bottle image in an embodiment provided by the present invention;
[0063] Figure 9 A schematic diagram of cutting a target medicine bottle image in an embodiment of the present invention;
[0064] Figure 10 A schematic diagram of determining the K value in an embodiment provided by the present invention;
[0065] Figure 11 A schematic diagram of an average value of a maximum value in an embodiment provided by the present invention;
[0066] Figure 12 The corresponding embodiment of the present invention Figure 11 Schematic diagram of the average value of another maximum value. DETAILED DESCRIPTION
[0067] The following describes embodiments of the present invention in detail. Examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended only to explain the present invention and are not to be construed as limiting the present invention.
[0068] In the description of the present invention, "several" means more than one, "plurality" means more than two, "greater than," "less than," and "exceed" are understood to exclude the number itself, while "above," "below," and "within" are understood to include the number itself. The use of "first" and "second" in the description is solely for the purpose of distinguishing technical features and should not be construed as indicating or implying relative importance, implicitly specifying the number of the indicated technical features, or implicitly specifying the order of the indicated technical features.
[0069] In the description of the present invention, reference to terms such as "one embodiment," "some embodiments," "illustrative embodiments," "examples," "specific examples," or "some examples" means that the specific features, structures, materials, or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the exemplary expressions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
[0070] First, let’s analyze some of the terms used in this application:
[0071] Clustering: refers to the process of dividing a collection of physical or abstract objects into multiple clusters of similar objects.
[0072] Cluster analysis: The analytical process of grouping a collection of physical or abstract objects into clusters of similar objects.
[0073] Cluster center data: refers to a special sample data in cluster analysis, which is used to represent a certain class. Other sample data are determined by calculating the distance with it to determine whether they belong to the class.
[0074] Intersection-over-Union (IOU) is a concept used in target detection. It refers to the overlap rate between the generated candidate bound and the original labeled bound, that is, the ratio of their intersection to their union. This ratio is the IOU data. Usually, the ideal situation is complete overlap, that is, the ratio is 1. Generally, a ratio greater than 0.5 is considered a successful target detection.
[0075] Mean clustering algorithm: The mean clustering algorithm in this application refers to the k-means clustering algorithm (k-means clustering algorithm), which is an iterative cluster analysis algorithm. Its steps are: pre-divide the data into K groups, then randomly select K objects as the initial cluster centers, and then calculate the distance between each object and each seed cluster center, and assign each object to the cluster center closest to it. The cluster centers and the objects assigned to them represent a cluster. Every time a sample is assigned, the cluster center of the cluster will be recalculated based on the existing objects in the cluster. This process will be repeated until a certain termination condition is met. The termination condition can be that no (or a minimum number) objects are reassigned to different clusters, no (or a minimum number) cluster centers change again, and the sum of squared errors is locally minimized.
[0076] Distance criterion theorem: refers to the distance measurement criteria commonly used in mathematical science, including Euclidean distance, Manhattan distance, Chebyshev distance, standardized Euclidean distance, etc., which are used to calculate the distance between data.
[0077] Expected data: Expectation is also called mathematical expectation or mean. In probability theory and statistics, expectation is the probability of each possible result in the experiment multiplied by the sum of its results. It reflects the average value of the random variable, and the resulting data is the expected data.
[0078] Confidence data: Data that represents confidence is called confidence data.
[0079] Confidence: In statistics, the confidence interval of a probability sample is an interval estimate of a population parameter of this sample.
[0080] Confidence interval: It is the degree to which the true value of this parameter has a certain probability of falling around the measurement result. The confidence interval gives the credibility range of the measured value of the measured parameter, that is, the "certain probability" to be calculated, and this probability is called the confidence level.
[0081] Convolutional neural networks (CNNs) are a type of feedforward neural network with a deep structure that incorporates convolutional computations. They are a representative algorithm for deep learning. Convolutional neural networks possess the ability to learn representations and perform translation-invariant classification of input information based on their hierarchical structure, hence the term "translation-invariant artificial neural network."
[0082] The embodiments of the present disclosure provide a medicine bottle counting method, system, device, and computer-readable storage medium, which are specifically illustrated by the following embodiments. First, the medicine bottle counting method in the embodiments of the present disclosure is described.
[0083] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Artificial Intelligence (AI) is the theory, method, technology, and application system that uses digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use knowledge to achieve optimal results.
[0084] Fundamental AI technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interaction systems, and mechatronics. AI software technologies primarily encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.
[0085] The medicine bottle counting method provided in the embodiment of the present disclosure relates to the field of machine learning technology. The medicine bottle counting method provided in the embodiment of the present disclosure can be applied in a terminal, can be applied in a server side, or can be software running in a terminal or a server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, or a smart watch, etc.; the server side can be configured as an independent physical server, or as a server cluster or distributed system composed of multiple physical servers, or as a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the medicine bottle counting method, etc., but is not limited to the above forms.
[0086] like Figure 1 As shown, it is a schematic diagram of the implementation process of the medicine bottle counting method provided in an embodiment of the present application. The medicine bottle counting method may include but is not limited to steps S100 to S500.
[0087] S100, acquiring a preset target medicine bottle image;
[0088] S200, performing clustering processing on the target medicine bottle image to obtain cluster center data;
[0089] S300, calculating the intersection-over-union (IoU) data corresponding to the target medicine bottle image based on the cluster center data;
[0090] S400, comparing a preset threshold with the intersection-and-union ratio data to obtain a comparison result;
[0091] S500 , counting the medicine bottles corresponding to the medicine bottle scattered points in the target medicine bottle image according to the comparison result.
[0092] In step S100 of some embodiments, obtaining a preset target medicine bottle image specifically includes: first obtaining a preset initial medicine bottle image, then performing identification processing on the initial medicine bottle image to obtain identification data corresponding to the medicine bottle, and finally constructing a target medicine bottle image based on the identification data.
[0093] In some embodiments, reference Figure 2 , step S100 may include but is not limited to steps S110 to S130.
[0094] S110, obtaining a preset initial medicine bottle image;
[0095] S120, performing identification processing on the initial medicine bottle image to obtain identification data corresponding to the medicine bottle;
[0096] S130, constructing a target medicine bottle image according to the identification data.
[0097] In step S110 of some embodiments, obtaining the preset initial medicine bottle image is to photograph the medicine bottle with a preset professional camera device to obtain the initial medicine bottle image.
[0098] Furthermore, the height of the camera device is fixed so that medicine bottles of the same specifications have the same width and height in the medicine bottle image. For example, the medicine bottles include at least one of the following specifications: 1 ml, 2 ml and 5 ml.
[0099] In step S120 of some embodiments, the initial medicine bottle image is identified and processed to obtain identification data corresponding to the medicine bottle. When the medicine bottle is photographed using a camera device, an identification frame will appear to identify medicine bottles of different specifications. Since the camera height in step S110 is fixed but the placement of the medicine bottle is uncertain, the camera device will try to frame the medicine bottle with the most appropriate size when identifying the medicine bottle, resulting in changes in the width and height of each identification frame, but the hypotenuse will not change. Therefore, by identifying the medicine bottle, identification data corresponding to the medicine bottle is obtained, and the identification data is the width and height of the identification frame.
[0100] In step S130 of some embodiments, a target medicine bottle image is constructed based on the identification data, and the target medicine bottle image is constructed using the identification data obtained in step S120, that is, using the width and height of each identification frame as the x-axis and y-axis of the coordinate axes.
[0101] In some embodiments, reference Figure 8 , Figure 8 Shown is a schematic diagram of the target medicine bottle image.
[0102] In step S200 of some embodiments, clustering processing is performed on the target medicine bottle image to obtain cluster center data. Specifically, the target medicine bottle image is first cut to generate multiple sub-images, and then the sub-images are clustered to obtain cluster center data.
[0103] In some embodiments, reference Figure 3 , step S200 may include but is not limited to steps S210 to S220.
[0104] S210, performing segmentation processing on the target medicine bottle image to generate multiple medicine bottle images;
[0105] S220 , clustering the medicine bottle scattered points of each medicine bottle image to obtain cluster center data.
[0106] In step S210 of some embodiments, reference Figure 9 As shown, the target medicine bottle image is cut to generate multiple medicine bottle images. The target medicine bottle image in step S130 is segmented into multiple medicine bottle images through the same segmentation starting point. In this way, the distribution of scattered point data in each medicine bottle image is relatively concentrated compared to the image without segmentation, which can greatly reduce the error.
[0107] In step S220 of some embodiments, the medicine bottle scatter points of each medicine bottle image are clustered to obtain cluster center data. Specifically, the number of scatter points corresponding to the sub-image is first counted to obtain sub-scatter point data, and then a preset mean clustering algorithm is obtained. The sub-scatter point data is calculated and processed according to the mean clustering algorithm to obtain cluster center data.
[0108] Example 1
[0109] The specific implementation method for finally obtaining K cluster center data is as follows:
[0110] First, the initial K value is set to 1, and then multiple clustering is performed in sequence to obtain the curve of the average intersection-union ratio data changing with the K value, and the optimal number of K is found from the change of the slope of the curve.
[0111] Optionally, K=1, calculate the intersection-and-union (IU) data of each medicine bottle scatter point and one cluster center point, and then calculate the average of all IU data to obtain the average IU data.
[0112] Furthermore, in an embodiment of the present application, the corresponding cluster center points can be obtained by the K-means clustering algorithm, wherein the K-means clustering algorithm is a simple and commonly used unsupervised learning algorithm for dividing a data set into K clusters, so that the data similarity within the same cluster is high and the data similarity between different clusters is low.
[0113] Furthermore, the implementation steps of the K-means clustering algorithm are:
[0114] A. Initialize K cluster centers;
[0115] B. Use similarity measurement to assign each sample to the cluster center closest to it;
[0116] C. Calculate the mean of all samples in each cluster sample to update the cluster center;
[0117] D. Repeat steps B and C until the cluster center no longer changes or the maximum number of iterations is reached.
[0118] Optionally, K=2, calculate the intersection-and-union data of each medicine bottle scatter point and the two cluster center points respectively, and then determine the cluster center point with the largest intersection-and-union data after calculating the intersection-and-union data of each medicine bottle scatter point and each cluster center point, and then calculate the average value of the intersection-and-union data of each medicine bottle scatter point and the cluster center point with the largest intersection-and-union data value.
[0119] Optionally, K=3, calculate the intersection-and-union data of each medicine bottle scatter point and the three cluster center points respectively, then determine the cluster center point with the largest intersection-and-union data after calculating the intersection-and-union data of each medicine bottle scatter point and each cluster center point, and then calculate the average value of the intersection-and-union data of each medicine bottle scatter point and the cluster center point with the largest intersection-and-union data value.
[0120] It should be noted that K can take other values, and the calculation method is similar to the above-mentioned method of K=2 and K=3, and no further limitation is made here.
[0121] Furthermore, we can get the curve of average intersection-to-union ratio data changing with K value, as shown in Figure 10 As shown:
[0122] Depend on Figure 10 It can be seen that if a certain K value causes a significant change in the average IoU data, it can also be understood that the slope of the average IoU data corresponding to the K value obtained by calculation reaches a preset range, then the K value is determined as the result value.
[0123] In some embodiments, for example, K=15, the number of cluster center data is confirmed to be 15, which can also be understood as 15 cluster center data coordinates. In the subsequent embodiments of this application, K=15 is taken as an example to implement the medicine bottle counting method disclosed in the present invention.
[0124] In some embodiments, reference Figure 4 , step S220 may include but is not limited to steps S221 to S223.
[0125] S221, counting the number of medicine bottle scatter points corresponding to the medicine bottle image to obtain medicine bottle scatter point data;
[0126] S222, obtaining a preset mean clustering algorithm;
[0127] S223, using the mean clustering algorithm, calculate and process the scattered data of the medicine bottles to obtain cluster center data.
[0128] In step S221 of some embodiments, the number of medicine bottle scatter points corresponding to the medicine bottle image is counted to obtain medicine bottle scatter point data. Through the segmentation processing performed in step S210, multiple medicine bottle images are obtained, and the number of scatter points corresponding to each medicine bottle image is counted to obtain medicine bottle scatter point data.
[0129] In step S222 of some embodiments, a preset mean clustering algorithm is obtained. Furthermore, the mean clustering algorithm used in this application is a K-means clustering algorithm, and the corresponding cluster center data can be obtained through the K-means clustering algorithm.
[0130] Furthermore, the K-means clustering algorithm is a simple unsupervised learning algorithm used to divide a data set into K clusters so that the data similarity within the same cluster is high and the data similarity between different clusters is low.
[0131] In step S223 of some embodiments, the mean clustering algorithm is used to perform computational processing on the scattered data of the medicine bottles to obtain cluster center data. Specifically, mean clustering is performed on the scattered data of the medicine bottles to obtain cluster data, and then computational processing is performed on the cluster data to obtain expected data. Finally, computational processing is performed on the expected data to obtain cluster center data.
[0132] In some embodiments, reference Figure 5 , step S223 may include but is not limited to steps S201 to S203.
[0133] S201, performing mean clustering processing on the scattered data of the medicine bottles to obtain clustered data;
[0134] S202, performing computational processing on the clustered data to obtain expected data corresponding to each medicine bottle image;
[0135] S203: Calculate cluster center data corresponding to the target medicine bottle image based on each mean value data in the expected data.
[0136] Before executing step S201, optionally, in an embodiment of the present application, a preset distance criterion theorem is first obtained, specifically using the formula: 1-IOU(box, anchor), where IOU is the intersection-over-union data, box is the box, and anchor is the anchor, to implement the medicine bottle counting method of the present application.
[0137] In step S201 of some embodiments, mean clustering processing is performed on the medicine bottle scatter data to obtain cluster data, that is, the medicine bottle scatter data in each medicine bottle image is assigned to the initial cluster center closest to it, and then the mean of all medicine bottle scatter data in each cluster is calculated, and the initial cluster center is updated. This iterative cycle is performed until the cluster center no longer changes or the maximum number of iterations is reached, thereby obtaining cluster data.
[0138] Furthermore, the cluster data includes at least one of the following: first sub-data and second sub-data.
[0139] In step S202 of some embodiments, the clustering data is computationally processed to obtain expected data corresponding to each medicine bottle image, specifically: the first sub-data in the first sub-image is computationally processed to obtain first center data, the first center data and the first sub-data are computationally processed to obtain first target data, first mean data corresponding to the first sub-image is generated based on the first target data, after obtaining the first mean data, the second sub-data in the second sub-image is computationally processed to obtain second center data, the second center data and the second sub-data are computationally processed to obtain second target data, and second mean data corresponding to the second sub-image is generated based on the second target data.
[0140] Furthermore, the expected data includes at least one of the following: first mean data and second mean data.
[0141] Furthermore, the medicine bottle image includes at least one of the following: a first sub-image and a second sub-image.
[0142] Furthermore, in an embodiment of the present application, taking the example of dividing the target medicine bottle image into two sub-images, namely the first sub-image and the second sub-image, the clustering data corresponding to the first sub-image is the first sub-data, and the clustering data corresponding to the second sub-image is the second sub-data.
[0143] It should be noted that the embodiment of the present application takes the example of dividing the target medicine bottle image into two sub-images. Similarly, it can also be divided into three sub-images, four sub-images, etc., and the corresponding methods are the same as dividing the target medicine bottle image into two sub-images.
[0144] Furthermore, in an embodiment of the present application, the target medicine bottle image is set to include a total of M scattered point data, the first sub-image has M1 scattered point data, the second sub-image has M2 scattered point data, and K is the total number of cluster center data of the target medicine bottle image.
[0145] In step S203 of some embodiments, cluster center data corresponding to the target medicine bottle image is calculated based on each mean data in the expected data, and the first mean data and the second mean data obtained in step S203 are further averaged to calculate the cluster center data corresponding to the target medicine bottle image.
[0146] In some embodiments, reference Figure 6 , step S202 may include but is not limited to steps S231 to S236.
[0147] S231, performing calculation processing on first sub-data in the first sub-image to obtain first center data;
[0148] S232, performing calculation processing on the first central data and the first sub-data to obtain first target data;
[0149] S233, generating first mean data corresponding to the first sub-image according to the first target data;
[0150] S234, after obtaining the first mean data, performing calculation processing on the second sub-data in the second sub-image to obtain second center data;
[0151] S235, performing calculation processing on the second central data and the second sub-data to obtain second target data;
[0152] S236: Generate second mean data corresponding to the second sub-image according to the second target data.
[0153] In step S231 of some embodiments, the first sub-data in the first sub-image is computationally processed to obtain first center data, that is, the cluster data obtained according to step S202 is obtained, which includes scattered point data corresponding to multiple sub-images. First, the first sub-data in the first sub-image is computationally processed to obtain first center data, that is, the cluster center data corresponding to the first sub-image.
[0154] Furthermore, in an embodiment of the present application, the first center data corresponding to the first sub-image is calculated in the first sub-image according to the formula P1=M1 / M*K, wherein P1 is the first center data, M1 is the number of scattered point data of the first sub-image, K is the total number of cluster center data of the target medicine bottle image, and M is the total number of scattered point data included in the target medicine bottle image.
[0155] Furthermore, if P1 obtained by calculation is not an integer, when the last decimal place is greater than or equal to 5, it is rounded up; when the last decimal place is less than 5, it is rounded down.
[0156] Furthermore, in some embodiments, the target medicine bottle image includes a total of M=1000 scattered point data, the scattered point data of the first sub-image is M1=389, the scattered point data of the second sub-image is M2=611, K=15 is the total number of cluster center data of the target medicine bottle image, and the number of first center data P1=6.
[0157] In step S232 of some embodiments, the first center data and the first sub-data are calculated and processed to obtain the first target data, that is, the intersection and union ratio of the first center data and the first sub-data is calculated to obtain multiple intersection and union ratio data, wherein the first sub-data is the scattered point data of the first sub-image, and the first target data is the multiple intersection and union ratio data.
[0158] In step S233 of some embodiments, first mean data corresponding to the first sub-image is generated based on the first target data, that is, the multiple intersection-over-union data obtained in step S232 are averaged to obtain the first mean data corresponding to the first sub-image.
[0159] In step S234 of some embodiments, after obtaining the first mean data, the second sub-data in the second sub-image are calculated and processed to obtain second center data, that is, the clustering data obtained according to step S202 is obtained, which includes scattered point data corresponding to multiple sub-images. First, the second sub-data in the second sub-image are calculated and processed to obtain second center data, that is, the cluster center data corresponding to the second sub-image.
[0160] Furthermore, in an embodiment of the present application, the second center data corresponding to the second sub-image is calculated in the second sub-image according to the formula P2=K-M1 / M*K, wherein P2 is the second center data, M1 is the number of scattered point data of the first sub-image, K is the total number of cluster center data of the target medicine bottle image, and M is the total number of scattered point data included in the target medicine bottle image.
[0161] Further, according to the embodiment of step S231, the number of second central data P2=K-P1=9.
[0162] In step S235 of some embodiments, the second center data and the second sub-data are calculated and processed to obtain second target data, that is, the intersection and union ratio of the second center data and the second sub-data is calculated to obtain multiple intersection and union ratio data, wherein the second sub-data is the scattered point data of the second sub-image, and the second target data is the multiple intersection and union ratio data.
[0163] In step S236 of some embodiments, second mean data corresponding to the second sub-image is generated based on the second target data, that is, the multiple intersection-over-union data obtained in step S235 are further averaged to obtain second mean data corresponding to the second sub-image, which is used to perform average processing with the first mean data in step S233 to obtain cluster center data.
[0164] Example 2
[0165] refer to Figure 11 , Figure 11 This is a schematic diagram of the average value of the maximum values calculated for this embodiment, thereby determining that the value with the smallest slope is the cut image value.
[0166] refer to Figure 12 , Figure 12 To correspond Figure 11 Schematic diagram of the average value of another maximum value.
[0167] In the steps of the above embodiment, the medicine bottle image is cut into two sub-images, namely the first sub-image and the second sub-image, to implement the step of clustering and cutting the medicine bottle image of the present application, cutting the medicine bottle image into multiple sub-images, and then performing clustering processing on the sub-images to obtain cluster center data.
[0168] Optionally, the medicine bottle image is cut into three sub-images, namely a first sub-image, a second sub-image, and a third sub-image.
[0169] Furthermore, in the first sub-image, the intersection and union ratios of M1 / M*K cluster centers and M1 medicine bottle scattered data are calculated respectively, and the maximum value Wmax1, Wmax2, ..., Wmax(M1 / M*K) of the intersection and union ratios of each cluster center and M1 medicine bottle scattered data is taken, and then the average value max1 of these maximum values is calculated.
[0170] Furthermore, in the second sub-image, the intersection and union ratios of M2 / M*K cluster centers and M2 medicine bottle scattered data are calculated respectively, and the maximum value Wmax1, Wmax2, ..., Wmax(M2 / M*K) of the intersection and union ratios of each cluster center and M2 medicine bottle scattered data is taken, and then the average value max2 of these maximum values is calculated.
[0171] Furthermore, in the third sub-image, the intersection and union ratios of M3 / M*K cluster centers and M3 medicine bottle scattered data are calculated respectively, and the maximum value Wmax1, Wmax2, ..., Wmax(M3 / M*K) of the intersection and union ratios of each cluster center and M3 medicine bottle scattered data is taken, and then the average value max3 of these maximum values is calculated.
[0172] Furthermore, we calculate the average value of max1, max2, and max3.
[0173] Optionally, the medicine bottle image is cut into four sub-images, namely a first sub-image, a second sub-image, a third sub-image, and a fourth sub-image.
[0174] According to the calculation method in the steps of the above embodiment, it can be calculated that
[0175] It should be noted that if a small probability situation occurs, for example, the results of the first three sub-images obtained based on the proportion are 4.5; 4.5; 4.5; according to the principle of rounding up, 5, 5, 5 are obtained, and the fourth sub-image is: 15-5-5-5=0, then this calculation result is skipped directly, and the case of cutting the medicine bottle image into 4 parts is ignored.
[0176] In step S300 of some embodiments, the intersection-over-union (IoU) data corresponding to the target medicine bottle image may be calculated based on the cluster center data by performing computational processing on the anchor boxes and true labels corresponding to the 15 cluster center data to obtain the IoU data.
[0177] In step S400 of some embodiments, a preset threshold value and the IoU data are compared to obtain a comparison result.
[0178] Furthermore, if the intersection-over-union data is greater than a preset threshold, step S510 is executed to train the cluster center data using a preset neural network to obtain an image recognition model.
[0179] Furthermore, if the intersection-over-union data is less than or equal to a preset threshold, step S100 is executed to obtain a preset target medicine bottle image.
[0180] In step S500 of some embodiments, counting the medicine bottles corresponding to the medicine bottle scatter points in the target medicine bottle image according to the comparison result is specifically as follows: first, a preset neural network is used to train the cluster center data to obtain an image recognition model, and then the target medicine bottle image is recognized and processed according to the image recognition model to obtain a numerical value for counting the medicine bottles corresponding to the medicine bottle scatter points in the target medicine bottle image.
[0181] In some embodiments, reference Figure 7 , step S500 may include but is not limited to steps S510 to S520.
[0182] S510, using a preset neural network to train cluster center data to obtain an image recognition model;
[0183] S520 , performing recognition processing on the target medicine bottle image according to the image recognition model, and obtaining a numerical value of counting the medicine bottles corresponding to the medicine bottle scatter points in the target medicine bottle image.
[0184] In step S510 of some embodiments, the cluster center data is trained using a preset neural network to obtain an image recognition model, that is, the cluster center data obtained in step S200 is input into the preset neural network for training to obtain the image recognition model.
[0185] Optionally, the neural network may be a YOLO network.
[0186] In step S520 of some embodiments, the target medicine bottle image is identified and processed according to the image recognition model to obtain a numerical value for counting the medicine bottles corresponding to the medicine bottle scatter points in the target medicine bottle image. The target medicine bottle image obtained in step S100 is input into the image recognition model obtained in step S510 for detection, and after preprocessing, a numerical value for counting the medicine bottles corresponding to the medicine bottle scatter points in the target medicine bottle image is finally obtained.
[0187] Optionally, the preprocessing means includes at least one of the following: a non-maximum suppression algorithm.
[0188] In some embodiments, a medicine bottle counting system includes: an acquisition module for acquiring a preset target medicine bottle image; a clustering module for clustering the target medicine bottle image to obtain cluster center data; a calculation module for calculating intersection-over-union data corresponding to the target medicine bottle image based on the cluster center data; a comparison module for comparing a preset threshold with the intersection-over-union data to obtain a comparison result; and a counting module for counting medicine bottles corresponding to the bottle scatter points in the target medicine bottle image based on the comparison result.
[0189] In some embodiments, a medicine bottle counting device includes: at least one memory; at least one processor; and at least one program, wherein the memory is used to store an executable program that, when executed, executes the medicine bottle counting method described above.
[0190] In some embodiments, the computer-readable storage medium stores executable instructions, and the executable instructions can be executed by a computer.
[0191] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely arranged relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0192] The embodiments described in the embodiments of the present disclosure are intended to more clearly illustrate the technical solutions of the embodiments of the present disclosure and do not constitute a limitation on the technical solutions provided by the embodiments of the present disclosure. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of the present disclosure are also applicable to similar technical problems.
[0193] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0194] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0195] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0196] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store programs, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0197] The preferred embodiments of the present disclosure are described above with reference to the accompanying drawings, but are not intended to limit the scope of the present disclosure. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and essence of the present disclosure should be within the scope of the present disclosure.
Claims
1. A method for counting medicine bottles, characterized in that: include: Acquire a preset target medicine bottle image; wherein, acquiring the preset target medicine bottle image includes: acquiring a preset initial medicine bottle image; performing identification processing on the initial medicine bottle image to obtain identification data corresponding to the medicine bottle; and constructing the target medicine bottle image based on the identification data; Clustering the target medicine bottle image to obtain cluster center data; wherein the clustering of the target medicine bottle image to obtain cluster center data includes: segmenting the target medicine bottle image to generate multiple medicine bottle images; counting the number of medicine bottle scatter points corresponding to the medicine bottle images to obtain medicine bottle scatter point data; obtaining a preset mean clustering algorithm; and using the mean clustering algorithm to perform calculation processing on the medicine bottle scatter point data to obtain the cluster center data; Calculating intersection-over-union (IoU) data corresponding to the target medicine bottle image based on the cluster center data; Comparing a preset threshold with the IoU data to obtain a comparison result, wherein if the average IoU data is greater than the threshold, the cluster center is used as an anchor frame to train the YOLO image recognition model; Use the trained YOLO model to count the bottles in the target bottle image; The step of obtaining a preset target medicine bottle image specifically includes: Using a camera at a fixed height to collect initial images of various standardized medicine bottles; Performing labeling processing on the initial medicine bottle image to obtain labeling frame width and height data corresponding to medicine bottles of various standardized specifications; Using the width and height of the identification frame as coordinate axes, construct a scatter distribution map of the medicine bottles as the target medicine bottle image; The clustering process of the target medicine bottle image to obtain cluster center data specifically includes the steps of dynamically allocating subgraph cluster centers: Performing a segmentation process on the target medicine bottle image based on the medicine bottle scatter distribution map to generate a plurality of medicine bottle images; Counting the number of medicine bottle scatter points corresponding to the medicine bottle image to obtain medicine bottle scatter point data; The number of cluster centers of each sub-image is dynamically allocated according to the formula P_i = (M_i / M) × K, where P_i is the number of cluster centers of the i-th sub-image, M_i is the number of its scattered points, M is the total number of scattered points, and K is the total number of cluster centers; Use the K-means clustering algorithm to calculate the scattered data of each sub-image and output the cluster center coordinates; Before the target medicine bottle image is cut, the total cluster center number K optimization step is also included: Iteratively calculate the average IoU ratio for different K values, where K is first initialized to 1. Then, for each candidate K value, perform K-means clustering and calculate the average IoU ratio of all the scattered points of the medicine bottles to the nearest cluster center; A curve is drawn showing how the average value of the intersection-over-union ratio changes with the K value. When the slope of the curve reaches a preset range, the current K value is determined to be the optimal number of cluster centers to generate the cluster center data.
2. The medicine bottle counting method according to claim 1, characterized in that: The method of using the mean value clustering algorithm to calculate and process the scattered data of the medicine bottles to obtain the cluster center data includes: Performing mean clustering processing on the scattered data of the medicine bottles to obtain clustered data; Performing computational processing on the clustered data to obtain expected data corresponding to each of the medicine bottle images; The cluster center data corresponding to the target medicine bottle image is calculated based on each mean data in the expected data.
3. The medicine bottle counting method according to claim 2, characterized in that: The cluster data includes at least one of the following: first sub-data, second sub-data; The expected data includes at least one of the following: first mean data, second mean data; The medicine bottle image includes at least one of the following: a first sub-image and a second sub-image; The computing and processing of the clustered data to obtain expected data corresponding to each of the medicine bottle images comprises at least one of the following steps: performing computational processing on the first sub-data in the first sub-image to obtain first center data; performing computational processing on the first central data and the first sub-data to obtain first target data; generating the first mean value data corresponding to the first sub-image according to the first target data; After obtaining the first mean data, performing calculation processing on the second sub-data in the second sub-image to obtain second center data; performing computational processing on the second central data and the second sub-data to obtain second target data; The second mean data corresponding to the second sub-image is generated according to the second target data.
4. The medicine bottle counting method according to any one of claims 1 to 3, characterized in that: Counting the medicine bottles corresponding to the medicine bottle scattered points in the target medicine bottle image according to the comparison result includes: Using a preset neural network to train the cluster center data to obtain an image recognition model; The target medicine bottle image is recognized and processed according to the image recognition model to obtain a numerical value for counting the medicine bottles corresponding to the medicine bottle scatter points in the target medicine bottle image.
5. Medicine bottle counting system, characterized in that, include: an acquisition module, configured to acquire a preset target medicine bottle image; wherein acquiring the preset target medicine bottle image comprises: acquiring a preset initial medicine bottle image; performing identification processing on the initial medicine bottle image to obtain identification data corresponding to the medicine bottle; and constructing the target medicine bottle image based on the identification data; The acquisition module is used to acquire a preset target medicine bottle image, specifically comprising: collecting initial medicine bottle images of various standardized medicine bottles through a camera at a fixed height; performing identification processing on the initial medicine bottle images to obtain width and height data of identification frames corresponding to the various standardized medicine bottles; and constructing a medicine bottle scatter distribution map as the target medicine bottle image using the width and height of the identification frames as coordinate axes; A clustering module is configured to perform clustering processing on the target medicine bottle image to obtain cluster center data; wherein the clustering processing on the target medicine bottle image to obtain cluster center data includes: performing segmentation processing on the target medicine bottle image to generate multiple medicine bottle images; counting the number of medicine bottle scatter points corresponding to the medicine bottle images to obtain medicine bottle scatter point data; obtaining a preset mean clustering algorithm; and using the mean clustering algorithm to perform calculation processing on the medicine bottle scatter point data to obtain the cluster center data; The clustering module is used to perform clustering processing on the target medicine bottle image to obtain cluster center data, specifically including the steps of dynamically allocating sub-graph cluster centers: cutting the target medicine bottle image based on the medicine bottle scatter point distribution map to generate multiple medicine bottle images; counting the number of medicine bottle scatter points corresponding to the medicine bottle image to obtain medicine bottle scatter point data; dynamically allocating the number of cluster centers of each sub-image according to the formula P_i=(M_i / M)×K, where P_i is the number of cluster centers of the i-th sub-image, M_i is the number of its scatter points, M is the total number of scatter points, and K is the total number of cluster centers; using the K-means clustering algorithm to calculate the scatter point data of each sub-image and output the cluster center coordinates; The clustering module is further configured to, before performing segmentation processing on the target medicine bottle image, further include the step of optimizing the total number of cluster centers K: iteratively calculating the average intersection-over-union ratios for different K values, wherein K=1 is first initialized, and then for each candidate K value, K-means clustering is performed to calculate the average intersection-over-union ratios of all medicine bottle scatter points and the nearest cluster center; a curve is drawn showing how the average intersection-over-union ratio data changes with the K value, and when the slope of the curve reaches a preset range, determining that the current K value is the optimal number of cluster centers to generate the cluster center data; A calculation module, configured to calculate, based on the cluster center data, an intersection-over-union (IoU) data corresponding to the target medicine bottle image; A comparison module is used to compare a preset threshold with the IoU data to obtain a comparison result, wherein if the average IoU data is greater than the threshold, the cluster center is used as an anchor frame to train the YOLO image recognition model; The counting module is used to count the medicine bottles in the target medicine bottle image using the trained YOLO model.
6. Medicine bottle counting device, characterized in that, include: at least one memory; at least one processor; at least one program; The program is stored in the memory, and the processor executes at least one of the programs to implement: The medicine bottle counting method according to any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that The computer-readable storage medium stores executable instructions, which can be executed by a computer to cause the computer to execute: The medicine bottle counting method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Dense stacking target detection method based on automatic labeling and transfer learning
CN110866476A