Text detection method, device, equipment and storage medium for drug packaging
By extracting the outline of the text area in the pharmaceutical packaging image and judging the QR code positioning standard, the automated testing of the drug packaging is achieved, the problem of low manual detection efficiency and accuracy is solved, and the quality of the drug is guaranteed.
Patent Information
- Application Number
- CN202311132580.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-04
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2043-09-04
AI Technical Summary
In the prior art, the packaging inspection of drug packaging in small bags requires manual inspection, which leads to limited detection efficiency and accuracy, and may cause secondary contamination of the drug.
By obtaining the target image of the pharmaceutical packaging, the outline tree matched by the text area is extracted, and the outline tree contains the QR code positioning mark.
The automated testing of drug packaging is achieved, the detection efficiency and accuracy are improved, and the secondary pollution risk of drugs caused by artificial operations is avoided.
Smart Images

Figure CN118261852B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology. More specifically, the embodiments of the present application relate to a method, device, equipment and storage medium for detecting text on a drug package. Background Art
[0002] At present, drugs can be divided into solid preparations and liquid preparations based on the preparation method. Solid preparations include tablets, capsules, powders, granules and other forms.
[0003] During the production and preparation process of traditional Chinese medicine packaging, traditional Chinese medicine preparations can be packaged in small bags.
[0004] In the related art, after the small bag packaging is completed, it is necessary to manually check whether the packaging bag has defects. However, human eyes are easily fatigued, so the efficiency and accuracy of manual inspection are limited by the state of personnel. In addition, the intervention of manual operation will cause secondary contamination of drugs, which will reduce the quality of drugs. Summary of the invention
[0005] In this context, the embodiments of the present application hope to provide a method, device, equipment and storage medium for text detection of drug packaging, so as to realize automated detection of drug packaging, improve the efficiency of text detection of drug packaging, enhance the accuracy of text detection of drug packaging, and ensure the quality of drugs.
[0006] In a first aspect of the embodiments of the present application, a method for detecting text on a drug package is provided, comprising:
[0007] Acquire a target image; wherein the target image includes image information of a target package; the target package is a medicine package; the image information includes a text area;
[0008] Extracting a contour tree matching the text region from the target image; the contour tree contains a topological structure of the text region;
[0009] Determine whether the contour tree contains a two-dimensional code locator; the two-dimensional code locator is a contour structure embedded with at least two layers of sub-contours;
[0010] If the contour tree contains the two-dimensional code positioning mark, it is determined that the drug packaging is qualified.
[0011] In a second aspect of the embodiments of the present application, a text detection device for a medicine package is provided, the device comprising:
[0012] An acquisition unit, used for acquiring a target image; wherein the target image includes image information of a target package; the target package is a medicine package; and the image information includes a text area;
[0013] An extraction unit, used for extracting a contour tree matching the text region from the target image; the contour tree includes a topological structure of the text region;
[0014] A judging unit, used to judge whether the contour tree contains a two-dimensional code positioning mark; the two-dimensional code positioning mark is a contour structure embedded with at least two layers of sub-contours;
[0015] A determination unit is used to determine that the drug packaging is qualified if the two-dimensional code positioning mark is included in the contour tree.
[0016] In a third aspect of the embodiments of the present application, a computing device is provided, the computing device comprising:
[0017] at least one processor, memory, and input-output unit;
[0018] The memory is used to store a computer program, and the processor is used to call the computer program stored in the memory to execute the text detection method for drug packaging of the first aspect.
[0019] In a fourth aspect of the embodiments of the present application, a computer-readable storage medium is provided, which includes instructions. When the instructions are executed on a computer, the computer executes the text detection method for drug packaging of the first aspect.
[0020] In the embodiment of the present application, a method, device, equipment and storage medium for text detection of drug packaging are provided. In the embodiment of the present application, a target image is obtained, and the target image contains image information of a target packaging, and the target packaging is a drug packaging. In order to detect the text information included in the image information of the target packaging, it is first necessary to extract the text area where the text information is located as the data basis for the text information detection process. Specifically, a contour tree matching the text area can be extracted from the target image, and the contour tree contains the topological structure of the text area. Since there is a specific relationship between the two-dimensional code and the text information in the target packaging involved in the embodiment of the present application, the two-dimensional code can be regarded as one of the references for detecting the text area. Therefore, after extracting the contour tree, it is further determined whether the contour tree contains a two-dimensional code positioning mark. The two-dimensional code positioning mark is a contour structure embedded with at least two layers of sub-contours. The two-dimensional code positioning mark is a special topological structure contained in the two-dimensional code, so the automatic detection of the two-dimensional code can be achieved through this special topological structure. If the contour tree contains a two-dimensional code positioning mark, it means that the drug packaging does not contain a two-dimensional code defect, that is, the drug packaging can be determined to be qualified.
[0021] In the implementation mode of the present application, the contour tree matching the text area is extracted from the image of the drug package, and the qualified drug package is screened by judging whether the contour tree contains a QR code positioning mark, thereby realizing the automatic detection of the drug package and greatly improving the efficiency of text detection of the drug package. At the same time, by automatically detecting the text area in the drug package image, the problem of decreased accuracy due to human eye fatigue and the risk of secondary drug contamination due to manual intervention are effectively avoided, which greatly improves the accuracy of text detection of drug packages and ensures the quality of drugs. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] By reading the detailed description below with reference to the accompanying drawings, the above and other purposes, features and advantages of the exemplary embodiments of the present application will become readily understood. In the accompanying drawings, several embodiments of the present application are shown in an exemplary and non-limiting manner, wherein:
[0023] Figure 1 A schematic diagram of a flow chart of a method for detecting text on a drug package provided in an embodiment of the present application;
[0024] Figure 2 A schematic diagram of a drug packaging image provided by an embodiment of the present application;
[0025] Figure 3 A schematic diagram of a target image acquisition method according to an embodiment of the present application;
[0026] Figure 4 A schematic diagram of a target image provided by an embodiment of the present application;
[0027] Figure 5 A schematic diagram of a preprocessing method according to an embodiment of the present application;
[0028] Figure 6 A schematic diagram of a flow chart of a contour tree extraction method provided in an embodiment of the present application;
[0029] Figure 7 A schematic diagram of a text area provided in an embodiment of the present application;
[0030] Figure 8 A schematic diagram of a QR code provided in one embodiment of the present application;
[0031] Fig. 9 A schematic diagram of a process for testing the quality of drug packaging provided in one embodiment of the present application;
[0032] Fig.10 A flowchart of a text line defect detection method provided in one embodiment of the present application;
[0033] Fig.11A flowchart of a correction method provided in one embodiment of the present application;
[0034] Fig.12 A schematic diagram of the structure of a text detection device for medicine packaging provided in one embodiment of the present application;
[0035] Fig.13 A schematic diagram of the structure of a medium in an embodiment of the present application is schematically shown;
[0036] Fig.14 A schematic diagram of the structure of a computing device according to an embodiment of the present application is shown schematically.
[0037] In the drawings, the same or corresponding reference numerals represent the same or corresponding parts. DETAILED DESCRIPTION
[0038] The principles and spirit of the present application will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are provided only to enable those skilled in the art to better understand and implement the present application, and are not intended to limit the scope of the present application in any way. On the contrary, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.
[0039] Those skilled in the art know that the embodiments of the present application can be implemented as a system, device, equipment, method or computer program product. Therefore, the present disclosure can be specifically implemented in the following forms, namely: complete hardware, complete software (including firmware, resident software, microcode, etc.), or a combination of hardware and software.
[0040] At present, drugs can be divided into solid preparations and liquid preparations based on the preparation method. Solid preparations include tablets, capsules, powders, granules and other forms.
[0041] In the production and preparation process of Chinese medicine packaging, Chinese medicine preparations can be packaged in small bags. At present, the production process of small bag packaging mainly includes: for a batch of Chinese medicine preparations, typesetting and editing the corresponding drug information, and then using a high-speed rewinder to print the drug information on the packaging materials of the small bag. Finally, using a small bag packaging machine to process the drug raw materials and packaging materials into Chinese medicine preparations packaged in small bags through multiple processes such as filling, heat sealing, and cutting.
[0042] In the related art, after the small bag packaging is completed, it is necessary to manually check the packaging bags for possible defects, such as printing errors. However, due to the limitations of human eye fatigue, the accuracy and efficiency of manual inspection methods are reduced. In addition, the intervention of manual operation will also cause secondary contamination of drugs, resulting in a decline in drug quality.
[0043] In summary, a new solution needs to be designed to solve the above technical problems.
[0044] In order to overcome the above technical problems, according to the implementation methods of the present application, a method, device, equipment and storage medium for text detection of pharmaceutical packaging are proposed. In the implementation methods of the present application, it is first necessary to obtain a target image, which contains image information of a target package. Among them, the target package is a pharmaceutical package, and the image information of the target package includes a text area. Then, a contour tree for representing the topological structure in the text area is extracted from the target image. Then, it is determined whether the contour tree contains a two-dimensional code locator, which is a contour structure embedded with at least two layers of sub-contours. Finally, if the contour tree contains a two-dimensional code locator, it is determined that the pharmaceutical packaging is qualified.
[0045] In the implementation mode of the present application, the contour tree matching the text area is extracted from the image of the drug package, and the qualified drug package is screened by judging whether the contour tree contains a QR code positioning mark, thereby realizing the automatic detection of the drug package and greatly improving the efficiency of text detection of the drug package. At the same time, by automatically detecting the text area in the drug package image, the problem of decreased accuracy due to human eye fatigue and the risk of secondary drug contamination due to manual intervention are effectively avoided, which greatly improves the accuracy of text detection of drug packages and ensures the quality of drugs.
[0046] The technical solution provided in the embodiments of the present application can be implemented by a server and / or a terminal device. The server and / or the terminal device can be deployed in the production equipment of the pharmaceutical packaging, or can be independent of the production equipment of the pharmaceutical packaging, and the transmission of data instructions can be achieved by establishing wireless communication and / or wired communication.
[0047] It should be noted that the server involved in the embodiments of the present application can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or 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, big data and artificial intelligence platforms.
[0048] The terminal device involved in the embodiments of the present application may be a device that provides voice and / or data connectivity to a user, a handheld device with a wireless connection function, or other processing devices connected to a wireless modem. For example, a mobile phone (or "cellular" phone) and a computer with a mobile terminal, for example, may be a portable, pocket-sized, handheld, computer-built-in or vehicle-mounted mobile device that exchanges voice and / or data with a wireless access network. For example, Personal Communication Service (PCS) phones, cordless phones, Session Initiation Protocol (SIP) phones, Wireless Local Loop (WLL) stations, Personal Digital Assistants (PDAs) and other devices.
[0049] It should be understood herein that any number of elements in the drawings is for illustration rather than limitation, and any naming is only for distinction rather than having any limiting meaning.
[0050] The principles and spirit of the present application are explained in detail below with reference to several representative implementations of the present application.
[0051] Reference below Figure 1 , Figure 1 A flowchart of a method for detecting text on a drug package provided in an embodiment of the present application. A method for detecting text on a drug package provided in an embodiment of the present application comprises:
[0052] Step S101, acquiring a target image.
[0053] In the embodiment of the present application, the target image includes a drug package. In practical applications, the target image may be a drug package for packaging solid preparations. For example, a drug packaging bag for packaging solid Chinese medicine preparations. In terms of packaging form, for example, the drug package may be a double-link drug package, where double-link refers to a packaging structure in which two independent packaging bags are connected together. Figure 2 The dual-drug package shown includes a complete image of package a and a partial image of package b. Figure 2In the embodiment, packaging bag a and packaging bag b are independent of each other and are used to package solid preparations respectively. A detachable connection structure is provided between packaging bag a and packaging bag b. It should be noted that in addition to two-piece pharmaceutical packaging, detachable independent pharmaceutical packaging can also constitute a triple, quadruple, or other number of packaging forms, which is not limited in the embodiments of the present application. For the sake of distinction, the present application refers to the pharmaceutical packaging to be detected as the target packaging. Accordingly, the target image contains the image information of the target packaging. The image information of the target packaging includes but is not limited to the text area, for example, it can be printed on Figure 2 The QR code and text information in the packaging bag a are shown.
[0054] In the embodiment of the present application, the target image can be acquired by an image acquisition device, and the image acquisition device can be a camera, a webcam or other device, which is not limited in the embodiment of the present application. For example, the image acquisition device can be a camera module installed in a packaging device or a packaging production line. It can also be a camera module in a mobile terminal or other device, which is connected to the packaging device by a clamping device or other connecting structure. In an optional implementation of step S101, the target image can be the original image acquired by the image acquisition device.
[0055] In another optional embodiment of the present application, in order to improve the detection efficiency, the target image may also be automatically binary processed. Figure 3 As shown, another optional implementation of step S101 can be implemented as the following steps:
[0056] Step S301, obtaining an original image containing a target package.
[0057] In the implementation manner of the present application, the original image is an image including the complete outline of the target package, which can be obtained by any image acquisition method. For example, the drug package (i.e., the target package) is placed on a solid color background to acquire the original image. For example, the drug package is fixed in the field of view of the image acquisition device by a clamp, so that the original image is acquired by the image acquisition device.
[0058] Step S302: binarize the original image to obtain a binarized image.
[0059] Step S303, identifying the largest contour of the package in the binary image.
[0060] Step S304: obtaining a bounding box containing the largest contour in the binary image as a target image.
[0061] For example, it is assumed that the original image obtained in step S301 is Figure 2 , assuming that the original image contains the package Figure 2 In this regard, please also refer to Figure 4 , Figure 4 is a schematic diagram of a binary image obtained by binarizing the original image in step S302. Figure 4 It can be seen that the foreground part that occupies the largest area of the image is the packaging bag a. Therefore, we can Figure 4 The maximum contour of the packaging bag a is identified and segmented in step S304, and then, the Figure 4 The bounding box containing the maximum contour is taken as the target image.
[0062] Through step S301 to step S304, the original image can be automatically binarized to provide a data basis for the contour extraction process of the package, thereby further improving robustness and ease of use.
[0063] In fact, the methods for binarizing the original image in step S302 include, but are not limited to: OTSU method, TRIANGLE method, window-based binarization method, and Huang's fuzzy thresholding method based on fuzzy set theory.
[0064] In order to obtain the outer contour of the package, in step S302, the original image needs to be binarized. For example, in order to improve robustness and ease of use, the implementation principle of Huang's fuzzy thresholding method is as follows:
[0065] First, define a fuzzy subset that maps from image X (i.e., the original image) to the value range [0, 1]:
[0066] X={x mn , μ x (x mn ))}
[0067] Among them, x mn Represents the pixel grayscale value at the midpoint (m, n) of image X, μ X (x mn ) indicates that the point has a certain attribute membership value. Among them, 0≤μ X (x mn )≤1, m=0, 1, ..., M-1, n=0, 1, ..., N-1. For binarization, each pixel has a close relationship to the category it belongs to, so this relationship can be used to represent μ X (x mn ) value.
[0068] For a given threshold t, the average values of the color scale values of background pixels and foreground pixels, μ0 and μ1, are expressed as follows:
[0069]
[0070]
[0071] Where h(g) represents the number of pixels with gray level g in the image.
[0072] The above background pixel color level average μ0 and foreground pixel color level average μ1 can be regarded as the target values of the foreground and background corresponding to the specified threshold t, and the relationship between a point in the image X and its region should intuitively be related to the difference between the gray value of the point and the target value of the region. Therefore, for the point (m, n), the following membership definition function is used:
[0073]
[0074] Where C is a constant that satisfies the above function: 0.5≤μ x (x mn )≤1.
[0075] Based on the Shannon entropy function, the entropy of a fuzzy set A is defined as:
[0076]
[0077] The Shannon function is:
[0078] S(μ A (x i ))=-μ A (x i )ln[μ A (x i )]-[1-μ A (x i )]ln[1-μ A (x i )]
[0079] Since the grayscale image has at most L color levels, the above formula can be further converted to:
[0080]
[0081] Finally, for all possible thresholds t, the t value with the minimum Shannon entropy value is taken as the final segmentation threshold. Thus, the image X is color segmented by the segmentation threshold, and the image X is automatically binarized to obtain a binary image.
[0082] In practical applications, the lighting conditions in different detection environments will affect the detection results. Therefore, it is necessary to perform threshold preprocessing on the original image to make the binarization result of the original image more stable, reduce the detection error caused by changes in lighting conditions in different detection environments, and improve the accuracy of the detection results.
[0083] In an alternative embodiment, see Figure 5 As shown, before acquiring the target image in step S101, the original image is pre-processed by thresholding through the following steps S501 to S505 to further improve the accuracy of the detection result.
[0084] Step S501, obtaining the maximum brightness and minimum brightness of each pixel in the original image containing the drug package;
[0085] Step S502, multiplying the sum of the highest brightness and the lowest brightness by a preset coefficient to obtain a first adaptive threshold;
[0086] Step S503, using a first adaptive threshold to perform binarization processing on the original image to obtain a first adaptive binarized image;
[0087] Step S504, constructing a convolution kernel based on the pixel size of the smallest element of the two-dimensional code in the original image, and using the convolution kernel to perform binarization processing on the original image to obtain a second adaptive binarized image;
[0088] Step S505 , performing median filtering on the second adaptive binary image, and fusing the median filtering result with the first adaptive binary image to obtain a target image.
[0089] Specifically, an original image containing a drug package is obtained by an image acquisition device. After obtaining an original image to be processed, in step S501, the pixel with the highest brightness and the pixel with the lowest brightness in the entire original image are searched, and the highest brightness value of the former is recorded as value max , the lowest brightness value of the latter is recorded as value min In step S502, assuming that the preset coefficient is α, the first adaptive threshold threshold is calculated using the following formula: auto :
[0090] threshold auto =α·(value min +value max )
[0091] In the above formula, according to experience, α can be set to 0.6. Then, in step S503, threshold autoPerform adaptive thresholding on the original image to obtain the first adaptive binary image dst auto .
[0092] Furthermore, assuming that the pixel size of the smallest element in the QR code is d QR Based on this, the size of the convolution kernel can be set to 3·d QR ×3·d QR In step S504, the convolution kernel is used to perform adaptive thresholding on the original image to obtain a second adaptive binary image dst adaptive ,Right now:
[0093]
[0094]
[0095] Wherein, I(x, y) is the gray value of the point (x, y). C is a constant, and according to experience, C can be set to any constant between 5 and 10.
[0096] In step S505, the second adaptive binary image dst adaptive Perform median filtering to remove dst adaptive Then, the median filter result dst adaptive With the first adaptive binary image dst auto Fusion is performed to obtain the target image dst:
[0097] dst=dst auto ∩dst adaptive
[0098] Through the adaptive binarized image and binarized image fusion scheme provided in this embodiment, the impact of lighting changes on the original image can be further reduced, the binarization result of the original image can be made more stable, the image quality can be further improved, and it is helpful to extract better quality text areas from the target image, thereby further improving the accuracy of automatic text area detection.
[0099] Here, it should be noted that, in addition to the execution order of the above examples, the process of obtaining the first adaptive binary image can be executed synchronously with the process of obtaining the second adaptive binary image. Alternatively, the latter can also be executed before the former, which is not limited.
[0100] After the target image is acquired, in step S102, a contour tree matching the text region is extracted from the target image. In the embodiment of the present application, the contour tree includes a topological structure of the text region.
[0101] Step S103, determining whether the contour tree contains a two-dimensional code locator. In the embodiment of the present application, the two-dimensional code locator is a contour structure embedded with at least two layers of sub-contours.
[0102] Step S104: If the outline tree contains a QR code location mark, it is determined that the drug packaging is qualified.
[0103] In the embodiment of the present application, the text area is an image area containing text information in the target package that the user intends to detect. In practical applications, the text area includes but is not limited to a QR code and text information. The text information includes pre-printed text information pre-printed on the drug packaging bag and printed text information produced on the drug packaging site.
[0104] In order to further improve the accuracy of packaging conformity inspection, image registration can be performed on the pharmaceutical packaging to avoid inspection errors caused by issues such as image shooting angle, packaging placement, and packaging clamping angle.
[0105] In an optional embodiment of the present application, if the physical size of the marker (such as the black mark in the drug package, etc.) meets the standard size, before detecting the text area of the drug package, the first registration positioning point related to the bounding box circumscribed by the maximum outline of the drug package is extracted from the target image, and the second registration positioning point related to the marker is extracted from the target image based on the marker detection result. Then, the first registration positioning point and the second registration positioning point are affine transformed to realize the image registration processing of the target image and reduce the detection error.
[0106] Take the left bag in the two-piece package as an example, take the circumscribed rectangular bounding box for the maximum outline of the left bag in the target image, and take the upper left corner coordinate point and the lower left corner coordinate point of the circumscribed rectangular bounding box as the upper left corner positioning point and the lower left corner positioning point of the left bag (i.e. the first registration positioning point). Take the horizontal midline of the right black mark in the left bag and the upper intersection of the rectangular bounding box as the upper right corner positioning point of the left bag (take the second registration positioning point). Then, perform affine transformation on the upper left corner positioning point, the lower left corner positioning point, and the upper right corner positioning point of the left bag, and perform image registration processing on the position of the left bag in the target image.
[0107] It is worth noting that in addition to the above-mentioned image registration method, the jitter in the vertical direction (i.e., the Z axis) can also be corrected to further improve the accuracy of image detection. Of course, in practical applications, image registration processing can be applied to the detection process of other parts besides the markers to improve the accuracy and reliability of the subsequent image detection process.
[0108] The embodiments of the present application mainly involve drug packaging. Taking the Chinese medicine pouches used to package Chinese medicine granules as an example, the text information of the Chinese medicine pouches is mainly divided into two parts: one part is the text information pre-printed on the drug packaging material. Usually, there are no defects that need to be detected in this part, and the position is very fixed and needs to be avoided; the other part is the text information printed at the production site before filling the Chinese medicine granules, also known as printed text information. This part includes but is not limited to text content such as drug ingredients, medication instructions, production date, manufacturer, etc. This part often produces defects, and the location where the defects occur is not fixed. Since the on-site printing position is very random, the text information printed on each Chinese medicine pouch needs to be relocated and searched.
[0109] In actual applications, the QR code on the drug packaging and text content such as drug instructions, production date, manufacturer, etc., are all text information printed on site (also referred to as printed text information in this application). In the embodiment of the present application, in order to facilitate the detection of defects in the text area, the part that needs to be detected in the text area is located, and the relative position relationship between the above-mentioned printed text information and the QR code is pre-entered. Optionally, the printed text information and the QR code are modeled so that the modeling information can be used as a reference for subsequent text area detection. Thus, by locating the position of the QR code, the position of the printed text information can be quickly found, thereby realizing automatic defect detection of the text area.
[0110] In the related art, the QR code positioning method used in commercial scenarios often requires multiple shots with a camera to obtain an accurate QR code recognition result. The recognition success rate is low and it is difficult to match the accuracy requirements in the pharmaceutical packaging defect detection scenario involved in this application.
[0111] The QR code recognition and positioning methods used in industrial scenarios, although their accuracy meets the requirements, the general recognition model often needs to perform a large amount of calculations to deal with the accuracy problems caused by factors such as occlusion, deflection, and blur, resulting in a slow QR code recognition speed. Usually, such algorithm models take 90ms or longer to output recognition results, which cannot meet the requirements of recognition speed and efficiency in the drug packaging defect detection scenario in this application.
[0112] In addition, in the embodiment of the present application, the drug package is usually fixed by a clamp to a fixed position within the field of view of the image acquisition device, so the posture and position of the QR code on the drug package are relatively fixed. Using the QR code recognition solution in the related art will generate redundancy and reduce the efficiency of QR code recognition.
[0113] To overcome the technical problems existing in the above QR code detection process, in an alternative embodiment of the present application, a QR code detection method is further provided for detecting the QR code in the drug packaging, improving the positioning success rate of the QR code, and further enhancing the detection efficiency of the QR code in the drug packaging.
[0114] As Figure 6 shown, extracting the contour tree matching the text area from the target image in step S102 can be implemented as the following steps:
[0115] Step S601, performing morphological operations on the target image to obtain a binary image containing the text area;
[0116] Step S602, extracting the QR code image containing the topological structure from the binary image containing the text area as the contour tree.
[0117] To further improve the robustness of the target image and reduce the possible noise, in step S601, morphological operations can be performed on the target image dst. Specifically, in an alternative implementation, a 3×3 convolution kernel is used to perform closing and opening operations on the target image dst, thereby obtaining a clearer and more stable binary image (i.e., the target image), as Figure 7 shown.
[0118] In the binary image containing the text area, in S602, contour extraction processing is further performed to obtain a contour tree containing the topological structure.
[0119] Furthermore, after obtaining the contour tree containing the topological structure, in step S103, it is determined whether the contour tree contains a QR code positioning mark. In the embodiment of the present application, the QR code has a special topological structure, that is, the QR code positioning mark. Through this special topological structure of the QR code positioning mark, the QR code can be quickly searched and recognized from the contour tree, and the position where the QR code is located can be obtained. In practical applications, the QR code positioning mark is a contour structure embedded with at least two layers of sub-contours. Specifically, the contour not surrounded by any contour is the outer contour, and one or more layers of contours inside the outer contour are called the sub-contours of the outer contour.
[0120] As Figure 8 shown, in the "hui" - shaped patterns at the upper - left, lower - right, and lower - left corners, the outer red "square" - shaped contour is the outer contour of the QR code positioning mark, the inner yellow "square" - shaped contour is the sub - contour of the outer contour, and the innermost green "square" - shaped contour is the sub - contour of the above - mentioned yellow sub - contour. According to the above characteristics, all candidate contours with sub - contours and the sub - contours having their own sub - contours can be screened out from the contour tree as the QR code positioning mark.
[0121] Specifically, it is possible to start searching inward from the outermost outer contour. Assume that in the contour tree, the outer contour is denoted as contour 0, and contours 1 and 2 are sub - contours at the same level as contour 0, and their parent contour is contour 0. Further, starting from contours 1 and 2, search further inward to obtain sub - contour 3 of contour 1 and sub - contour 4 of contour 2. Thus, it is possible to determine that contours 1 and 2 with two layers of sub - contours are QR code positioning marks.
[0122] Furthermore, in step S104, if the contour tree contains QR code positioning marks, in this case, the QR code in the target image can be positioned through the QR code positioning marks, so as to confirm that the QR code printed on the drug package is qualified, that is, to confirm that the drug package is qualified.
[0123] Further optionally, in order to avoid the influence of some noise shapes, the Chinese character "回" and similar structured text information, in an alternative embodiment, it is also necessary to further analyze the shape and size of the candidate contours, so as to screen out the actual contours of multiple QR code positioning marks.
[0124] In the embodiment of the present application, through the above steps S101 to S104, it is possible to extract the contour tree matching the text area from the image of the drug package, and screen qualified drug packages by judging whether the contour tree contains QR code positioning marks, realizing the automatic detection of drug packages and greatly improving the text detection efficiency of drug packages. At the same time, by automatically detecting the text area in the drug package image, it also effectively avoids the problem of decreased accuracy caused by human eye fatigue and the risk of secondary drug pollution caused by manual operation intervention, greatly improving the accuracy of text detection of drug packages and ensuring drug quality.
[0125] In practical applications, due to process reasons during the printing of drug packages, the printed text information may be slightly rotated. Usually, this slight rotation will not be recognized as a defect, but it will affect the stability of the defect detection result. Therefore, it is necessary to perform pose correction on the image of the drug package before the defect detection process.
[0126] For the above rotation correction problem, in the above or following embodiments, after positioning the QR code in the drug package and before detecting the text content printed on - site in the text area, an affine transformation process can also be performed on the text area according to the QR code positioning marks, so as to achieve automatic image registration of the text area, further improving the text detection accuracy and detection efficiency of drug packages.
[0127] Specifically, assume that three QR code positioning marks are found. Based on this, the QR code positioning marks are rearranged in the order of lower - left, upper - left, and upper - right as: (x0, y0), (x1, y1), (x2, y2). In practical applications, it can also be set to other orders, and this is only an example here.
[0128] Based on the above example sequence, the rotation angle θ of the text content is calculated using three QR code positioning markers, namely:
[0129]
[0130]
[0131]
[0132] Assume that the center coordinates of the text content in the text area are (x t ,y t ), calculate the transformation matrix M of the rotation θ around the center coordinate, that is:
[0133]
[0134] The matrix parameters are set as: α=cosθ, β=sinθ. The matrix M is used to perform an affine transformation on the text content in the text area so as to correct the rotation angle of the text content in the text area.
[0135] Through the above steps, automatic image registration of text areas can be achieved, which helps to further improve the accuracy and efficiency of text detection on drug packaging.
[0136] In one embodiment of the present application, a text content detection method is also provided to automatically detect the printed text information in the text area, so as to further improve the text detection accuracy and detection efficiency of the drug packaging.
[0137] Specifically, after finding the QR code, in an optional embodiment, it is possible to further detect whether there are defects in the printed text information in the text area, so as to further determine whether the drug packaging is qualified. Fig. 9 As shown, the printing text information detection method can be implemented as follows:
[0138] Step S901, obtaining the center coordinates of the QR code from the outline tree;
[0139] Step S902, determining the region of interest corresponding to the printed text information in the text area based on the center coordinates of the two-dimensional code;
[0140] Step S903, determining whether the visual features of the region of interest meet the standard text features of the text region;
[0141] Step S904: If the visual features of the region of interest meet the standard text features, it is determined that the drug packaging is qualified.
[0142] It is understandable that in step S901, the actual position of the two-dimensional code in the drug package, that is, the center coordinates of the two-dimensional code, can be determined by the two-dimensional code positioning mark. In an optional embodiment, the center coordinates of the two-dimensional code are directly calculated based on the three or more two-dimensional code positioning marks searched and the center coordinates of these two-dimensional codes.
[0143] In another optional implementation, if the number of QR code positioning markers is insufficient, for example, only two QR code positioning markers can be found, in another optional implementation, assuming that the center coordinates of the two positioning markers are (x1, y1) and (x2, y2), then the center coordinates of the QR code (x QR ,y QR ), can be calculated using the following formula:
[0144]
[0145] In this way, even if there are factors such as light disturbance and change in the posture of the small bag, the position of the QR code can be accurately located when only two QR code positioning marks are searched.
[0146] After the center coordinates of the two-dimensional code are obtained, in step S902, the region of interest corresponding to the printed text information in the text area is determined based on the center coordinates of the two-dimensional code.
[0147] Specifically, an optional implementation of step S902 is to use the center coordinates of the two-dimensional code as the position coordinates of the two-dimensional code; determine the region of interest containing each text line in the printed text information; perform contour extraction on the region of interest of each text line to obtain the contour to be detected corresponding to each text line. The region of interest of each text line is determined according to the position coordinates of the two-dimensional code, the relative position relationship between the two-dimensional code and the printed text information stored in advance, and the size information of each text line in the printed text information.
[0148] Further optionally, before step S902, the position of the preprinted text information is determined according to the position of the target image in the dual-drug package, the position of the marker, and the pre-stored relative positional relationship between the marker and the preprinted text information. Further, according to the position of the preprinted text information, the preprinted text information is masked in the binary image containing the text area to obtain a masked binary image.
[0149] Based on the above introduction, we know that the text area of the drug packaging is divided into two parts: the text information pre-printed on the drug packaging material, and the text information printed at the production site before filling the Chinese medicine granules. The former does not need to be detected, so this part of the text information can be further shielded.
[0150] Since the positional relationship between the two parts of text information is relatively fixed, and the positional relationship between the marker in the drug packaging (such as a black label, etc.) and the pre-printed text information can also be acquired in advance, the position of the marker in the drug packaging can be used to determine the position of this part of the pre-printed text information (also called pre-printed text information for ease of description).
[0151] Specifically, assuming that the coordinates of the black mark on the left side of the drug package are (x L ,y L ), the detected width is w L , the coordinates of the black mark on the right are (x R ,y R ), the detected width is w R The standard offset of the preprinted text information to the left black mark is (x1, y1), and the standard offset to the right black mark is (x2, y2). Then the position (x, y) of the preprinted text information on the drug package is:
[0152]
[0153]
[0154] Assuming that the standard size of the pre-printed text information is w×h, the text area corresponding to the pre-printed text information covered by the bounding box (x, y, w, h) is shielded, so that only the text information printed at the production site (also referred to as printed text information for ease of description) remains in the target image.
[0155] After obtaining the masked binary image, in an optional implementation of step S902, the position of each text line in the printed text information is determined based on the position coordinates of the two-dimensional code, the relative position relationship between the two-dimensional code and the printed text information, and the size information of each text line in the printed text information. Further, based on the position of each text line, the size information of each text line in the printed text information, and the preset dynamic offset, in the masked binary image, the absolute value bounding box corresponding to each text line is used as the region of interest containing each text line.
[0156] After obtaining the region of interest corresponding to the printed text information, in step S903, it is determined whether the visual features of the region of interest meet the standard text features of the text region, wherein the standard text features are set based on the pre-modeled printed text information.
[0157] Optionally, in step S903, it is determined whether the size information of the contour to be detected of each text line meets the pre-modeled standard text line contour size. For example, it can be set based on the size information of the pre-modeled printed text information, and the size information includes but is not limited to at least one of the width, height, and area of the text line.
[0158] For example, before mass production testing of drug packaging, the drug packaging will be modeled to obtain the relative position and size between each text line and the QR code. For example, assuming that the relative position and size of the first text line are recorded as (x0, y0, w0, h0), assuming that the relative position and size of the nth line of text are recorded as (x n ,y n , w n ,h n ). When a drug package to be tested is obtained, the absolute value bounding box of the nth text line is: (x QR -x n ,y QR -y n , w n ,h n ). Then, the absolute value bounding box can be used as the region of interest to extract the nth text line and detect whether the text line has defects. In practical applications, the detection process can refer to Fig.10 shown.
[0159] Furthermore, in step S904, if the visual features of the region of interest meet the standard text features, the drug packaging is determined to be qualified. Specifically, if the size information of the contour to be detected of each text line meets the standard text line contour size, it means that there is no printing error in the text line, in which case the drug packaging can be determined to be qualified.
[0160] In fact, the posture and position of the drug package may change, such as shaking, tilting, slight rotation, etc., which may cause the position of the text line in the drug package image to change. Or, there are certain differences between different batches of drug packages. In order to correct the above problems and avoid abnormalities in the bounding box stored in advance, a dynamic offset can be introduced to correct the visual deviation caused by the above phenomenon.
[0161] In the embodiment of the present application, the dynamic offset is used to correct errors caused by differences in drug types and / or production processes. Optionally, after step S904, the dynamic offset is dynamically updated with the detection results of each text line. Optionally, the initial value of the dynamic offset can be set to (0, 0).
[0162] One way to determine the dynamic offset is to assume that the dynamic offset (ofsx, ofsy) is initially set to (0, 0). Based on this, each time the region of interest containing the text line is extracted, the absolute value bounding box of the nth line of text is changed to:
[0163] (x QR -x n ,y QR -y n , w n , hx)
[0164] (x QR -x n +ofsx,y QR -y n +ofsy,w n ,h n )
[0165] For example, assuming that the detection result of the nth text line is qualified, then the offset of the text line relative to the current bounding box can be calculated. Assume that the offset is (x d ,y d ), then the dynamic offset can be updated as:
[0166] ofsx=(1-α)·ofsx+α·x d
[0167] ofsy=(1-α)·ofsy+α·y d
[0168] Wherein, α is a constant. For example, α can be set according to the position of the text line in the text area and its function. For a normal text paragraph, α can be set to 0.2. For a title line, α can be set to 0.5.
[0169] Therefore, on the basis of qualified text line detection, the dynamic offset is continuously updated so that a more appropriate region of interest can be extracted each time, thereby improving the accuracy of the text line detection result.
[0170] In an embodiment of the present application, the region of interest of each text line is determined based on the position coordinates of the QR code, the pre-stored relative position relationship between the QR code and the printed text information, and the size information of each text line in the printed text information.
[0171] pass Fig. 9The provided embodiments and related steps can realize text line detection in drug packaging, thereby further improving the efficiency of text detection in drug packaging, effectively avoiding the problem of decreased accuracy due to human eye fatigue and the risk of secondary contamination of drugs due to manual intervention, greatly improving the accuracy of text detection in drug packaging and ensuring the quality of drugs.
[0172] In an optional implementation, before extracting contours of the regions of interest of each text line in step S902 and obtaining contours to be detected corresponding to each text line, the images of the text lines may be preprocessed, thereby further improving the accuracy of the text detection results.
[0173] Specifically, see Fig.11 As shown, the specific steps for preprocessing the image of the text line can be implemented as follows:
[0174] Step S1101 , performing contour pre-extraction processing on the region of interest of each text line to obtain the pre-extracted contour of each text line.
[0175] In practical applications, when extracting the region of interest of each text line, if the distance between lines is close, then multiple text line contours may appear in one region of interest at the same time. In this case, it is necessary to remove the redundant text line contours.
[0176] Step S1102 , performing edge contour screening on the pre-extracted contour of each text line to obtain a first corrected contour of each text line.
[0177] As an optional implementation, in step S1002, the pre-extracted contours of each text line are screened to obtain the first corrected contours of each text line, which can be implemented as follows:
[0178] The highest point and / or the lowest point in the pre-extracted contour of each text line is obtained; if the distance from the highest point or the lowest point to the center coordinates of the corresponding text line is less than a preset line spacing threshold, the contour of the text line where the highest point or the lowest point is located is used as a candidate contour, and the physical height of the candidate contour is calculated; if the physical height of the candidate contour is less than the product of the height of the absolute value bounding box to which the candidate contour currently belongs and a preset coefficient, the candidate contour is removed from the absolute value bounding box to which the candidate contour currently belongs, and a first corrected contour of the text line corresponding to the current absolute value bounding box is obtained.
[0179] Specifically, in the above steps, the contours of each text line are traversed to find the highest point (x t ,y t ) and the lowest point (x b ,y b ), if y t-(y QR -y n +ofsy) < ε, or y QR -y n +ofsy + h n -y b < ε, then the current text line contour is a candidate contour to be removed, and then calculate the height h of the candidate contour to be removed c . If h c < h n × β, it is determined that the candidate contour to be removed does not belong to the text line, and the candidate contour is covered or truncated. Among them, β is set to 0.333.
[0180] Step S1103, perform a closing operation on the text information belonging to the up-and-down separated structure in the first corrected contour of each text line to obtain the second corrected contour of each text line.
[0181] For example, the text of the up-and-down separated structure can be special characters such as "number" and "ji". The two parts in the up-and-down separated structure may be misjudged as two characters. At this time, a closing operation can be performed on the middle position between the two characters to make them into a whole, so as to obtain the second corrected contour. This correction process can be executed in the preprocessing stage before text line detection, or in the modeling stage before printing, and there is no limitation here.
[0182] Through Fig.11 the provided embodiments and related steps, factors that may cause misjudgment in the text line detection process of drug packaging (such as multiple text lines appearing in the region of interest, incorrect recognition of up-and-down structured text, etc.) can be preprocessed, thereby further improving the accuracy and efficiency of text detection in drug packaging.
[0183] After introducing the devices and methods of the exemplary embodiments of the present application, next, refer to Fig.12 to describe a text detection device for a drug packaging of an exemplary embodiment of the present application. The text detection device for the drug packaging can be set in a text detection device for the drug packaging. The device includes:[[]]
[0184] An acquisition unit 1201, configured to acquire a target image; wherein, the target image includes image information of a target package; the target package is a drug packaging; the image information includes a text area;
[0185] An extraction unit 1202, configured to extract a contour tree matching the text area from the target image; the contour tree includes the topological structure of the text area;
[0186] The judging unit 1203 is used to judge whether the contour tree contains a two-dimensional code positioning mark; the two-dimensional code positioning mark is a contour structure embedded with at least two layers of sub-contours;
[0187] The determination unit 1204 is used to determine that the drug packaging is qualified if the two-dimensional code positioning mark is included in the contour tree.
[0188] As an optional implementation manner, the extraction unit 1202 is specifically configured to:
[0189] Performing morphological operations on the target image to obtain a binary image containing a text area;
[0190] A two-dimensional code image containing a topological structure is extracted from the binary image containing the text area as the contour tree.
[0191] As an optional implementation, if the contour tree includes the two-dimensional code positioning mark, when the determination unit 1204 determines that the drug package is qualified, it is used to:
[0192] Obtaining the center coordinates of the QR code from the contour tree;
[0193] Based on the center coordinates of the two-dimensional code, determine the region of interest corresponding to the printed text information in the text area;
[0194] Determining whether the visual features of the region of interest meet standard text features of the text region; the standard text features are set based on pre-modeled printed text information;
[0195] If the visual features of the region of interest meet the standard text features, it is determined that the drug packaging is qualified.
[0196] As an optional implementation, when the text line detection unit determines the region of interest corresponding to the printed text information in the text area based on the center coordinates of the two-dimensional code, it is specifically used to:
[0197] Taking the center coordinates of the QR code as the position coordinates of the QR code;
[0198] Determine an area of interest containing each text line in the printed text information; the area of interest of each text line is determined according to the position coordinates of the two-dimensional code, the pre-stored relative position relationship between the two-dimensional code and the printed text information, and the size information of each text line in the printed text information;
[0199] Perform contour extraction on the region of interest of each text line to obtain the contour to be detected corresponding to each text line;
[0200] When determining whether the visual features of the region of interest meet the standard text features of the text region, the text line detection unit is specifically used to:
[0201] Determine whether the size information of the contour to be detected of each text line meets the pre-modeled standard text line contour size; the size information includes at least one of the width, height, and area of the text line;
[0202] When the text line detection unit determines that the drug packaging is qualified if the visual features of the region of interest meet the standard text features, it is specifically used to:
[0203] If the size information of the to-be-detected contour of each text line meets the standard text line contour size, it is determined that the drug packaging is qualified.
[0204] As an optional implementation manner, the text line detection unit is further used for:
[0205] Before performing contour extraction on the region of interest of each text line to obtain the contour to be detected corresponding to each text line, a contour pre-extraction process is performed on the region of interest of each text line to obtain the pre-extracted contour of each text line;
[0206] Performing edge contour screening on the pre-extracted contour of each text line to obtain a first corrected contour of each text line;
[0207] A closing operation is performed on the text information belonging to the upper and lower separation structure in the first modified contour of each text line to obtain the second modified contour of each text line.
[0208] As an optional implementation manner, the text line detection unit performs border contour screening on the pre-extracted contours of each text line to obtain the first modified contour of each text line, which is specifically used to:
[0209] Obtaining the highest point and / or the lowest point in the pre-extracted contour of each text line;
[0210] If the distance from the highest point or the lowest point to the center coordinates of the corresponding text line is less than a preset line spacing threshold, the outline of the text line where the highest point or the lowest point is located is used as a candidate outline, and the physical height of the candidate outline is calculated;
[0211] If the physical height of the candidate contour is less than the product of the height of the absolute value bounding box to which the candidate contour currently belongs and a preset coefficient, the candidate contour is removed from the absolute value bounding box to which the candidate contour currently belongs to obtain a first corrected contour of the text line corresponding to the current absolute value bounding box.
[0212] As an optional implementation manner, the text line detection unit is further used for:
[0213] Before determining the region of interest corresponding to the printed text information in the text area based on the center coordinates of the two-dimensional code, the position of the pre-printed text information is determined according to the position of the target image in the two-drug package, the position of the marker, and the relative positional relationship between the marker and the pre-stored pre-printed text information;
[0214] According to the position of the pre-printed text information, the pre-printed text information is masked in the binary image containing the text area to obtain a masked binary image;
[0215] The determining of the region of interest containing each text line in the printed text information includes:
[0216] Determine the position of each text line in the printed text information according to the position coordinates of the two-dimensional code, the relative position relationship between the two-dimensional code and the printed text information, and the size information of each text line in the printed text information;
[0217] According to the position of each text line, the size information of each text line in the printed text information, and the preset dynamic offset, in the binary image after masking processing, the absolute value bounding box corresponding to each text line is used as the region of interest containing each text line;
[0218] The dynamic offset is used to correct errors caused by differences in drug types and / or production processes; the dynamic offset is dynamically updated with the detection results of each text line.
[0219] As an optional implementation manner, the acquiring unit 1201 is further configured to:
[0220] Before acquiring the target image, acquiring the highest brightness and the lowest brightness of each pixel in the original image containing the drug package;
[0221] The sum of the highest brightness and the lowest brightness is multiplied by a preset coefficient to obtain a first adaptive threshold;
[0222] Using the first adaptive threshold to perform binarization processing on the original image to obtain a first adaptive binarized image;
[0223] Constructing a convolution kernel based on the pixel size of the smallest element of the two-dimensional code in the original image, and using the convolution kernel to perform binarization processing on the original image to obtain a second adaptive binarized image;
[0224] The second adaptive binary image is subjected to median filtering, and a median filtering result is fused with the first adaptive binary image to obtain the target image.
[0225] In the embodiment of the present application, the text detection device for drug packaging extracts the contour tree matched by the text area from the image of the drug packaging, and screens qualified drug packaging by judging whether the contour tree contains a QR code positioning mark, thereby realizing the automatic detection of drug packaging and greatly improving the efficiency of text detection of drug packaging. At the same time, the device also effectively avoids the problem of decreased accuracy due to human eye fatigue and the risk of secondary drug contamination due to manual intervention by automatically detecting the text area in the drug packaging image, thereby greatly improving the accuracy of text detection of drug packaging and ensuring the quality of drugs.
[0226] After introducing the devices, methods and apparatus of the exemplary embodiments of the present application, next, reference is made to Fig.13 The computer-readable storage medium of the exemplary embodiment of the present application is described. The computer-readable storage medium can be set in a text detection device for a drug package. Please refer to Fig.13 , the computer-readable storage medium shown is a CD 130, on which a computer program (i.e., a program product) is stored. When the computer program is executed by the processor, the steps recorded in the above method implementation are implemented, for example, obtaining a target image; wherein the target image includes image information of a target package; the target package is a pharmaceutical package; the image information includes a text area; extracting a contour tree matching the text area from the target image; the contour tree includes a topological structure of the text area; determining whether the contour tree includes a two-dimensional code locator; the two-dimensional code locator is a contour structure embedded with at least two layers of sub-contours; if the contour tree includes the two-dimensional code locator, it is determined that the pharmaceutical package is qualified; the specific implementation method of each step is not repeated here.
[0227] It should be noted that examples of the computer-readable storage medium may also include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other optical or magnetic storage media, which are not listed here one by one.
[0228] After introducing the devices, methods, media and apparatus of the exemplary embodiments of the present application, reference is now made to Fig.14 For the computing device for text detection on medicine packaging according to the exemplary embodiment of the present application, the computing device may be arranged in a text detection device on medicine packaging.
[0229] Fig.14 A block diagram of an exemplary computing device 100 suitable for implementing the embodiments of the present application is shown. The computing device 100 may be a computer system or a server. Fig.14 The computing device 100 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0230] like Fig.14 As shown, the components of the computing device 100 may include, but are not limited to: one or more processors or processing units 1001, a system memory 1002, and a bus 1003 connecting different system components (including the system memory 1002 and the processing unit 1001).
[0231] The computing device 100 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the computing device 100, including volatile and nonvolatile media, removable and non-removable media.
[0232] The system memory 1002 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 10021 and / or cache memory 10022. The computing device 100 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the ROM 10023 may be used to read and write non-removable, non-volatile magnetic media ( Fig.14 is not shown in the Fig.10 As shown in FIG. 1 , a disk drive for reading and writing a removable non-volatile disk (e.g., a "floppy disk") and an optical disk drive for reading and writing a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) can be provided. In these cases, each drive can be connected to bus 1003 via one or more data medium interfaces. System memory 1002 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of each embodiment of the present application.
[0233] A program / utility 10025 having a set (at least one) of program modules 10024 may be stored, for example, in system memory 1002, and such program modules 10024 include, but are not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. Program modules 10024 generally perform the functions and / or methods of the embodiments described herein.
[0234] The computing device 100 may also communicate with one or more external devices 1004 (e.g., a keyboard, a pointing device, a display, etc.). Such communication may be performed via an input / output (I / O) interface 605. In addition, the computing device 100 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 1006. Fig.10 As shown, the network adapter 1006 communicates with other modules (such as the processing unit 1001, etc.) of the computing device 100 via the bus 1003. It should be understood that although Fig.10 Not shown, other hardware and / or software modules may be used in conjunction with computing device 100 .
[0235] The processing unit 1001 executes various functional applications and data processing by running the program stored in the system memory 1002, for example, obtaining a target image; wherein the target image contains image information of a target package; the target package is a pharmaceutical package; the image information includes a text area; extracting a contour tree matching the text area from the target image; the contour tree contains a topological structure of the text area; judging whether the contour tree contains a two-dimensional code locator; the two-dimensional code locator is a contour structure embedded with at least two layers of sub-contours; if the contour tree contains the two-dimensional code locator, it is determined that the pharmaceutical package is qualified. The specific implementation of each step is not repeated here. It should be noted that although several units / modules or sub-units / sub-modules of the text detection device for pharmaceutical packaging are mentioned in the above detailed description, this division is only exemplary and not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more units / modules described above can be concretized in one unit / module. Conversely, the features and functions of one unit / module described above can be further divided into multiple units / modules to be concretized.
[0236] In the description of the present application, it should be noted that the terms "first", "second" and "third" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance.
[0237] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0238] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, 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 communication interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0239] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0240] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0241] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform 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 program codes, 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.
[0242] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
[0243] In addition, although the operations of the method of the present application are described in a specific order in the drawings, this does not require or imply that the operations must be performed in this specific order, or that all the operations shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.
Claims
1. A method for detecting text on drug packaging, characterized in that: include: Acquire a target image; wherein the target image includes image information of a target package; the target package is a medicine package; the image information includes a text area; Extracting a contour tree matching the text region from the target image; the contour tree contains a topological structure of the text region; Determine whether the contour tree contains a two-dimensional code locator; the two-dimensional code locator is a contour structure embedded with at least two layers of sub-contours; If the two-dimensional code positioning mark is included in the outline tree, it is determined that the drug packaging is qualified; Wherein, if the two-dimensional code positioning mark is included in the outline tree, determining that the drug packaging is qualified includes: Obtaining the center coordinates of the QR code from the contour tree; Based on the center coordinates of the two-dimensional code, determine the region of interest corresponding to the printed text information in the text area; Determining whether the visual features of the region of interest meet standard text features of the text region; the standard text features are set based on pre-modeled printed text information; If the visual features of the region of interest meet the standard text features, then the drug packaging is determined to be qualified; Wherein, before determining the region of interest corresponding to the printed text information in the text area based on the center coordinates of the two-dimensional code, the method further includes: Determine the position of the preprinted text information according to the position of the target image in the dual-drug package, the position of the marker, and the relative position relationship between the marker and the pre-stored pre-printed text information; According to the position of the pre-printed text information, the pre-printed text information is masked in the binary image containing the text area to obtain a masked binary image; Determine the region of interest that contains each line of text in the printed text message, including: Determine the position of each text line in the printed text information according to the position coordinates of the two-dimensional code, the relative position relationship between the two-dimensional code and the printed text information, and the size information of each text line in the printed text information; According to the position of each text line, the size information of each text line in the printed text information, and the preset dynamic offset, in the binary image after masking processing, the absolute value bounding box corresponding to each text line is used as the region of interest containing each text line; The dynamic offset is used to correct errors caused by differences in drug types and / or production processes; the dynamic offset is dynamically updated with the detection results of each text line.
2. The method for detecting text on drug packaging according to claim 1, characterized in that: The step of extracting a contour tree matching the text area from the target image comprises: Performing morphological operations on the target image to obtain a binary image containing a text area; A two-dimensional code image containing a topological structure is extracted from the binary image containing the text area as the contour tree.
3. The method for detecting text on drug packaging according to claim 1, characterized in that: The determining of the region of interest corresponding to the printed text information in the text area based on the center coordinates of the two-dimensional code includes: Taking the center coordinates of the QR code as the position coordinates of the QR code; Determine an area of interest containing each text line in the printed text information; the area of interest of each text line is determined according to the position coordinates of the two-dimensional code, the pre-stored relative position relationship between the two-dimensional code and the printed text information, and the size information of each text line in the printed text information; Perform contour extraction on the region of interest of each text line to obtain the contour to be detected corresponding to each text line; The determining whether the visual features of the region of interest meet standard text features of a text region includes: Determine whether the size information of the contour to be detected of each text line meets the pre-modeled standard text line contour size; the size information includes at least one of the width, height, and area of the text line; If the visual feature of the region of interest meets the standard text feature, determining that the drug package is qualified includes: If the size information of the to-be-detected contour of each text line meets the standard text line contour size, it is determined that the drug packaging is qualified.
4. The method for detecting text on drug packaging according to claim 3, characterized in that: Before extracting the contour of the region of interest of each text line to obtain the contour to be detected corresponding to each text line, the method further includes: Performing contour pre-extraction processing on the region of interest of each text line to obtain the pre-extracted contour of each text line; Performing edge contour screening on the pre-extracted contour of each text line to obtain a first corrected contour of each text line; A closing operation is performed on the text information belonging to the upper and lower separation structure in the first modified contour of each text line to obtain the second modified contour of each text line.
5. The method for detecting text on drug packaging according to claim 4, characterized in that: The step of performing edge contour screening on the pre-extracted contour of each text line to obtain a first corrected contour of each text line includes: Obtaining the highest point and / or the lowest point in the pre-extracted contour of each text line; If the distance from the highest point or the lowest point to the center coordinates of the corresponding text line is less than a preset line spacing threshold, the outline of the text line where the highest point or the lowest point is located is used as a candidate outline, and the physical height of the candidate outline is calculated; If the physical height of the candidate contour is less than the product of the height of the absolute value bounding box to which the candidate contour currently belongs and a preset coefficient, the candidate contour is removed from the absolute value bounding box to which the candidate contour currently belongs to obtain a first corrected contour of the text line corresponding to the current absolute value bounding box.
6. The method for detecting text on drug packaging according to claim 1, characterized in that: Before acquiring the target image, the method includes: Obtaining the maximum brightness and minimum brightness of each pixel in the original image containing the drug package; The sum of the highest brightness and the lowest brightness is multiplied by a preset coefficient to obtain a first adaptive threshold; Using the first adaptive threshold to perform binarization processing on the original image to obtain a first adaptive binarized image; Constructing a convolution kernel based on the pixel size of the smallest element of the two-dimensional code in the original image, and using the convolution kernel to perform binarization processing on the original image to obtain a second adaptive binarized image; The second adaptive binary image is subjected to median filtering, and a median filtering result is fused with the first adaptive binary image to obtain the target image.
7. A text detection device for drug packaging, characterized in that: The device comprises: An acquisition unit, used for acquiring a target image; wherein the target image includes image information of a target package; the target package is a medicine package; and the image information includes a text area; An extraction unit, used for extracting a contour tree matching the text region from the target image; the contour tree includes a topological structure of the text region; A judging unit, used to judge whether the contour tree contains a two-dimensional code positioning mark; the two-dimensional code positioning mark is a contour structure embedded with at least two layers of sub-contours; A determination unit, configured to determine that the drug package is qualified if the two-dimensional code positioning mark is included in the outline tree; Wherein, the determination unit determines that the drug packaging is qualified if the contour tree contains the two-dimensional code positioning mark, which is specifically used for: Acquire the center coordinates of the two-dimensional code from the contour tree; determine the region of interest corresponding to the printed text information in the text area based on the center coordinates of the two-dimensional code; determine whether the visual features of the region of interest meet the standard text features of the text area; the standard text features are set based on the pre-modeled printed text information; if the visual features of the region of interest meet the standard text features, determine that the drug packaging is qualified; The text line detection unit is further used to: determine the position of the pre-printed text information according to the position of the target image in the two-component drug package, the position of the marker, and the relative position relationship between the pre-stored marker and the pre-printed text information before determining the region of interest corresponding to the printed text information in the text area based on the central coordinates of the two-dimensional code; and perform masking processing on the pre-printed text information in the binary image containing the text area according to the position of the pre-printed text information to obtain the binary image after masking processing; The text line detection unit determines the region of interest containing each text line in the printed text information, specifically for: According to the position coordinates of the two-dimensional code, the relative position relationship between the two-dimensional code and the printed text information, and the size information of each text line in the printed text information, the position of each text line in the printed text information is determined; according to the position of each text line, the size information of each text line in the printed text information, and a preset dynamic offset, in the binary image after masking processing, the absolute value bounding box corresponding to each text line is used as the region of interest containing each text line; wherein the dynamic offset is used to correct errors caused by differences in drug types and / or production processes; the dynamic offset is dynamically updated with the detection results of each text line.
8. A computing device, characterized in that The computing device comprises: at least one processor, memory, and input-output unit; The memory is used to store a computer program, and the processor is used to call the computer program stored in the memory to execute the text detection method for drug packaging as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Two-dimensional code image processing method and device, storage medium and electronic equipment
CN115358252A