A method and system for detecting missing pills based on machine vision

Through machine vision-based detection methods, image processing and projection transformation technology are used to achieve rapid and accurate detection of tablet loss on the tablet plate, solving the problem of time-consuming, labor-intensive and error-prone problems in the prior art, and improving detection efficiency and accuracy.

CN114742824BActive Publication Date: 2025-03-18GUANGZHOU UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210563169.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-19
Publication Date
2025-03-18
Estimated Expiration
2042-05-19

AI Technical Summary

Technical Problem

In the prior art, the missing detection of tablets after packaging mainly relies on manual inspection, which consumes labor and is prone to errors, making it difficult to accurately detect missing tablets or regional packaging errors on the tablet plate.

Method used

Using a detection method based on machine vision, a standard image and image to be detected by obtaining the standard image of the tablet packaging, grayscale processing and threshold segmentation are performed, the packaging area and the tablet area are determined, the projection transformation matrix is ​​calculated, the tablet area in the standard image is projected on the image to be detected, the target image is obtained through the cutout process, and the contrast of the target image is calculated to determine whether the tablet is missing.

Benefits of technology

It realizes rapid and accurate detection of missing tablets on the tablet plate, improves detection efficiency and accuracy, and reduces labor costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114742824B_ABST
    Figure CN114742824B_ABST
Patent Text Reader

Abstract

The embodiment of this specification provides a method and system for detecting missing pills based on machine vision, wherein the method includes: obtaining a standard image of pill packaging and an image to be detected, and performing grayscale processing; performing threshold segmentation on the standard image according to a preset threshold range to determine the first packaging area and the first pill area; performing threshold segmentation on the image to be detected according to the preset threshold range to determine the second packaging area; calculating the coordinates of the corner points of the first packaging area and the second packaging area, and calculating the projection transformation matrix according to the coordinates of the corner points of the first packaging area and the second packaging area; according to the projection transformation matrix, projecting the first pill area onto the image to be detected to obtain the second pill area, and obtaining the target image by cutting out; according to the obtained target image, calculating the contrast of the target image to determine whether the pills are missing. This solves the problem that manual detection is prone to omissions and has a high error rate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This document relates to the field of visual inspection technology, and in particular to a method and system for detecting missing pills based on machine vision. Background Art

[0002] At present, placing tablets in a tablet plate of aluminum-plastic blister is a common packaging method. During packaging, the machine needs to package several tablets into the tablet plate, and then put them into the corresponding packaging box for sale on the market. Usually after the machine has packaged the pills, in order to ensure the integrity and accuracy of the packaged pills, an inspection is required. The current inspection is usually done manually, which is labor-intensive and error-prone. There is no way to accurately detect packaging errors. When the pill plate misses the pills and there are missing pills, or the number of pills packaged on the pill plate is correct but the type of pills packaged in a certain area does not correspond, manual inspection is prone to omissions and the error rate is high.

[0003] Therefore, it is necessary to develop a rapid and accurate method for detecting missing pills. Summary of the invention

[0004] One or more embodiments of this specification provide a method for detecting missing pills based on machine vision, including:

[0005] S1. Obtain a standard image and an image to be detected of a tablet package, and grayscale the standard image and the image to be detected to obtain a grayscale image;

[0006] S2. Based on the grayscale difference between different regions of the standard image, the standard image is segmented according to a preset threshold range to determine the first packaging area and the first tablet area;

[0007] S3. Based on the grayscale difference between different regions of the image to be detected, the image to be detected is threshold segmented according to a preset threshold range to determine the second packaging area;

[0008] S4. Calculate the coordinates of the corner points of the first packaging area and the second packaging area respectively, and calculate the projection transformation matrix according to the coordinates of the corner points of the first packaging area and the second packaging area;

[0009] S5. According to the obtained projection transformation matrix, the first pill area is projected onto the image to be detected to obtain a second pill area, and a target image is obtained by cutout processing;

[0010] S6. Based on the obtained target image, determine whether there are any missing pills by calculating the contrast of the target image.

[0011] One or more embodiments of this specification provide a pill missing detection system based on machine vision, including:

[0012] Image acquisition module: used to acquire a standard image and an image to be detected of the tablet package, and grayscale the standard image and the image to be detected to obtain a grayscale image;

[0013] A standard image segmentation module: used to perform threshold segmentation on the standard image according to a preset threshold range based on the grayscale difference between different areas of the standard image, and determine the first packaging area and the first tablet area;

[0014] The image segmentation module to be detected is used to perform threshold segmentation on the image to be detected according to a preset threshold range based on the grayscale difference between different areas of the image to be detected, and determine the second packaging area;

[0015] Transformation matrix calculation module: used to calculate the coordinates of the corner points of the first packaging area and the second packaging area respectively, and calculate the projection transformation matrix according to the coordinates of the corner points of the first packaging area and the second packaging area;

[0016] Target image acquisition module: used to project the first pill area onto the image to be detected according to the obtained projection transformation matrix to obtain the second pill area, and obtain the target image by cutting out the image;

[0017] Missing judgment module: used to judge whether there are missing pills based on the obtained target image by calculating the contrast of the target image.

[0018] One or more embodiments of the present specification provide an electronic device, comprising: a processor; and a memory arranged to store computer executable instructions, wherein when the computer executable instructions are executed, the processor executes the steps of the above-mentioned method for visually inspecting burrs of injection molded parts.

[0019] One or more embodiments of the present specification provide a storage medium for storing computer executable instructions, wherein the computer executable instructions, when executed, implement the steps of the above-mentioned method for visually inspecting burrs of injection molded parts.

[0020] By adopting the embodiment of the present invention, when detecting missing tablets on a tablet plate, manual detection is not required, but visual detection is performed, that is, a reference area where the tablets are located is obtained by processing a standard image, and the detection result of the tablets on the tablet plate is determined based on the projection of the reference area where the tablets are located onto the image to be detected, thereby improving the detection accuracy and detection efficiency and effectively reducing the labor cost.

[0021] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate one or more embodiments of this specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0023] Figure 1 A flowchart of a method for detecting missing pills based on machine vision provided for one or more embodiments of this specification;

[0024] Figure 2 A schematic diagram of a missing pill detection system based on machine vision provided for one or more embodiments of this specification;

[0025] Figure 3 A schematic diagram of the structure of a device for detecting missing pills based on machine vision provided in accordance with one or more embodiments of this specification. DETAILED DESCRIPTION

[0026] In order to enable those skilled in the art to better understand the technical solutions in one or more embodiments of this specification, the following will be combined with the drawings in one or more embodiments of this specification to clearly and completely describe the technical solutions in one or more embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on one or more embodiments of this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this document.

[0027] Method Embodiment

[0028] According to an embodiment of the present invention, a method for detecting missing pills based on machine vision is provided. Figure 1 is a flowchart of a method for detecting missing pills based on machine vision provided by one or more embodiments of this specification, such as Figure 1 As shown, the method for detecting missing pills based on machine vision according to an embodiment of the present invention specifically includes:

[0029] S1. Obtain a standard image and an image to be detected of a tablet package, and grayscale the standard image and the image to be detected to obtain a grayscale image;

[0030] S2. Based on the grayscale difference between different regions of the standard image, the standard image is segmented according to a preset threshold range to determine the first packaging area and the first tablet area;

[0031] S3. Based on the grayscale difference between different regions of the image to be detected, the image to be detected is threshold segmented according to a preset threshold range to determine the second packaging area;

[0032] S4. Calculate the coordinates of the corner points of the first packaging area and the second packaging area respectively, and calculate the projection transformation matrix according to the coordinates of the corner points of the first packaging area and the second packaging area;

[0033] S5. According to the obtained projection transformation matrix, the first pill area is projected onto the image to be detected to obtain a second pill area, and a target image is obtained by cutout processing;

[0034] S6. Based on the obtained target image, determine whether there are any missing pills by calculating the contrast of the target image.

[0035] By adopting the embodiment of the present invention, when detecting missing tablets on a tablet plate, manual detection is not required, but visual detection is performed, that is, a reference area where the tablets are located is obtained by processing a standard image, and the detection result of the tablets on the tablet plate is determined based on the projection of the reference area where the tablets are located onto the image to be detected, thereby improving the detection accuracy and detection efficiency and effectively reducing the labor cost.

[0036] The following is a detailed description of the missing pill detection method based on machine vision:

[0037] Acquiring a standard image and an image to be detected of a tablet package, and graying the standard image and the image to be detected to obtain a grayscale image, specifically comprising:

[0038] S101. Obtain a standard image of a tablet package and an image to be detected.

[0039] S102. Calculate the average value of the three RGB channels in the standard image of the tablet package and the image to be detected, and use the average value as the grayscale value to grayscale the standard image of the tablet package and the image to be detected using the grayscale value to obtain a grayscale image.

[0040] The standard image is an image of a tablet plate with correctly packaged tablets, which is a multi-channel image.

[0041] Based on the grayscale difference between different regions of the standard image, threshold segmentation is performed on the standard image according to a preset threshold range to determine the first packaging region and the first tablet region, specifically including:

[0042] S201. Determine a preset grayscale threshold, wherein the grayscale threshold is determined based on the grayscale difference between the tablet region image and the package region image in the standard image;

[0043] S202. According to the grayscale threshold, the standard image is segmented by threshold, and the area with grayscale value within the first preset threshold range is extracted to obtain the packaging area;

[0044] S203. Extract the area whose gray value is within the second preset threshold range, and obtain the tablet area after feature selection and closing operation.

[0045] The area with gray value within the second preset threshold is extracted, and the tablet area is obtained after feature selection and closing operation, specifically including:

[0046] S2031. Perform threshold segmentation on the standard image, extract the area whose gray value is within the second preset threshold range, and obtain the first area;

[0047] S2032. Disconnect the connected domain of the first region, select a region with an area range of 1000 to 9999, and obtain a second region;

[0048] S2033. Perform a closing operation on the second region to obtain the tablet region.

[0049] The first preset threshold range for threshold segmentation is 90-255, and the second threshold range is 0-140.

[0050] Based on the grayscale difference between different areas of the image to be detected, the image to be detected is threshold segmented according to a preset threshold range to determine the second packaging area.

[0051] The preset threshold value range for threshold segmentation of the image to be detected is 90 to 255.

[0052] It should be noted that the area range and the grayscale threshold can be adjusted as needed, and the setting values ​​in this embodiment are not the only setting values.

[0053] Calculating the coordinates of the corner points of the first packaging area and the second packaging area respectively, and calculating the projection transformation matrix according to the coordinates of the corner points of the first packaging area and the second packaging area, specifically includes:

[0054] S401. Obtain the circumscribed contour of the first packaging area, and find the intersection of two adjacent sides according to the four sides of the circumscribed contour to obtain four corner points of the first packaging area as coordinate one;

[0055] S402. Obtain the circumscribed contour of the second packaging area, find the intersection of two adjacent sides according to the four sides of the circumscribed contour, obtain four corner points of the second packaging area, and obtain coordinate 2;

[0056] S403. According to the coordinate 1 and the coordinate 2, the projection transformation matrix of the corresponding point is calculated, as shown in Formula 1:

[0057]

[0058] Among them, (u,v,w) is the coordinate one, is coordinate two, is the transformation matrix.

[0059] According to the obtained projection transformation matrix, the first pill area is projected onto the image to be detected to obtain the second pill area, and the target image is obtained by cutting out the image.

[0060] According to the obtained target image, by calculating the contrast of the target image, determining whether the pills are missing specifically includes:

[0061] The contrast of the target image is calculated; when the contrast is less than a first set value, the detection result is determined to be missing pills; when the contrast is greater than a second set value, the detection result is determined to be normal.

[0062] Normally, if the pill is missing, the contrast of the acquired target image does not exceed 20 at most. If the pill is not missing, the contrast of the target image is greater than 40. Therefore, the embodiment of the present invention sets the first setting value of the contrast of the target image to 20 and the second setting value to 40.

[0063] System Example

[0064] According to an embodiment of the present invention, a pill missing detection system based on machine vision is provided. Figure 2 is a schematic diagram of a pill missing detection system based on machine vision provided by one or more embodiments of this specification, such as Figure 2 As shown, the machine vision-based pill missing detection system according to an embodiment of the present invention specifically includes:

[0065] Image acquisition module 20: used to acquire a standard image and an image to be detected of a tablet package, and grayscale the standard image and the image to be detected to obtain a grayscale image;

[0066] The standard image segmentation module 21 is used to perform threshold segmentation on the standard image according to a preset threshold range based on the grayscale difference between different regions of the standard image, and determine the first packaging region and the first tablet region;

[0067] The image segmentation module 22 is used to perform threshold segmentation on the image to be detected according to a preset threshold range based on the grayscale difference between different areas of the image to be detected, and determine the second packaging area;

[0068] Transformation matrix calculation module 23: used to calculate the coordinates of the corner points of the first packaging area and the second packaging area respectively, and calculate the projection transformation matrix according to the coordinates of the corner points of the first packaging area and the second packaging area;

[0069] Target image acquisition module 24: used to project the first pill area onto the image to be detected according to the obtained projection transformation matrix to obtain the second pill area, and obtain the target image by cutting out the image;

[0070] Missing judgment module 25: used to judge whether there are missing tablets by calculating the contrast of the target image according to the obtained target image.

[0071] The embodiment of the present invention is a system embodiment corresponding to the above-mentioned method embodiment. The specific operations of each module can be understood by referring to the description of the method embodiment, which will not be repeated here.

[0072] Device Example 1

[0073] The embodiment of the present invention provides a device for detecting missing pills based on machine vision, such as Figure 3 As shown, it includes: a memory 30, a processor 32, and a computer program stored in the memory 30 and executable on the processor 32. When the computer program is executed by the processor 32, the following method steps are implemented:

[0074] S1. Obtain a standard image and an image to be detected of a tablet package, and grayscale the standard image and the image to be detected to obtain a grayscale image;

[0075] S2. Based on the grayscale difference between different regions of the standard image, the standard image is segmented according to a preset threshold range to determine the first packaging area and the first tablet area;

[0076] S3. Based on the grayscale difference between different regions of the image to be detected, the image to be detected is threshold segmented according to a preset threshold range to determine the second packaging area;

[0077] S4. Calculate the coordinates of the corner points of the first packaging area and the second packaging area respectively, and calculate the projection transformation matrix according to the coordinates of the corner points of the first packaging area and the second packaging area;

[0078] S5. According to the obtained projection transformation matrix, the first pill area is projected onto the image to be detected to obtain a second pill area, and a target image is obtained by cutout processing;

[0079] S6. Based on the obtained target image, determine whether there are any missing pills by calculating the contrast of the target image.

[0080] Device Example 2

[0081] An embodiment of the present invention provides a computer-readable storage medium, on which a program for implementing information transmission is stored. When the program is executed by the processor 52, the following method steps are implemented:

[0082] S1. Obtain a standard image and an image to be detected of a tablet package, and grayscale the standard image and the image to be detected to obtain a grayscale image;

[0083] S2. Based on the grayscale difference between different regions of the standard image, the standard image is segmented according to a preset threshold range to determine the first packaging area and the first tablet area;

[0084] S3. Based on the grayscale difference between different regions of the image to be detected, the image to be detected is threshold segmented according to a preset threshold range to determine the second packaging area;

[0085] S4. Calculate the coordinates of the corner points of the first packaging area and the second packaging area respectively, and calculate the projection transformation matrix according to the coordinates of the corner points of the first packaging area and the second packaging area;

[0086] S5. According to the obtained projection transformation matrix, the first pill area is projected onto the image to be detected to obtain a second pill area, and a target image is obtained by cutout processing;

[0087] S6. Based on the obtained target image, determine whether there are any missing pills by calculating the contrast of the target image.

[0088] The computer-readable storage medium in this embodiment includes, but is not limited to, ROM, RAM, magnetic disk or optical disk, etc.

[0089] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for detecting missing pills based on machine vision, characterized in that: include: S1. Obtain a standard image and an image to be detected of a tablet package, and grayscale the standard image and the image to be detected to obtain a grayscale image; S2. Based on the grayscale difference between different regions of the standard image, the standard image is segmented according to a preset threshold range to determine the first packaging area and the first tablet area; The S2 specifically includes: S201. Determine a preset grayscale threshold, wherein the grayscale threshold is determined based on the grayscale difference between the tablet region image and the package region image in the standard image; S202. According to the grayscale threshold, the standard image is segmented by threshold, and the area with grayscale value within the first preset threshold range is extracted to obtain the first packaging area; S203. Extracting the area with gray value within the second preset threshold range, and obtaining the first pill area after feature selection and closing operation processing; S3. Based on the grayscale difference between different regions of the image to be detected, the image to be detected is threshold segmented according to a preset threshold range to determine the second packaging area; S4. Calculate the coordinates of the corner points of the first packaging area and the second packaging area respectively, and calculate the projection transformation matrix according to the coordinates of the corner points of the first packaging area and the second packaging area; S5. According to the obtained projection transformation matrix, the first pill area is projected onto the image to be detected to obtain a second pill area, and a target image is obtained by cutout processing; S6. Based on the obtained target image, determine whether there are any missing pills by calculating the contrast of the target image.

2. The method according to claim 1, characterized in that: The S1 specifically includes: S101. Obtaining a standard image of the tablet packaging and an image to be detected; S102. Calculate the average value of the three RGB channels in the standard image of the tablet package and the image to be detected, and use the average value as the grayscale value to grayscale the standard image of the tablet package and the image to be detected to obtain a grayscale image.

3. The method according to claim 1, characterized in that The S203 specifically includes: S2031. Perform threshold segmentation on the standard image, extract the area whose gray value is within the second preset threshold range, and obtain the first area; S2032. Disconnect the connected domain of the first region, select a region with an area range of 1000 to 9999, and obtain a second region; S2033. Perform a closing operation on the second region to obtain the tablet region.

4. The method according to claim 1, characterized in that The first preset threshold range is 90 to 255, and the second preset threshold range is 0 to 140; In step S3, in performing threshold segmentation on the image to be detected according to a preset threshold range, the preset threshold range is 90-255.

5. The method according to claim 1, characterized in that The S4 specifically includes: S401. Obtain the circumscribed contour of the first packaging area, and find the intersection of two adjacent sides according to the four sides of the circumscribed contour to obtain four corner points of the first packaging area as coordinate one; S402. Obtain the circumscribed contour of the second packaging area, find the intersection of two adjacent sides according to the four sides of the circumscribed contour, obtain four corner points of the second packaging area, and obtain coordinate 2; S403. Calculate the projection transformation matrix of the corresponding points according to the coordinate one and the coordinate two.

6. The method according to claim 1, characterized in that The S6 specifically includes: Calculating the contrast of the target image; When the contrast is less than a set value, the detection result is determined to be missing tablets; When the contrast is greater than the set value, the detection result is determined to be normal.

7. A pill missing detection system based on machine vision, characterized in that: include: Image acquisition module: used to acquire a standard image and an image to be detected of the tablet package, and grayscale the standard image and the image to be detected to obtain a grayscale image; A standard image segmentation module: used to perform threshold segmentation on the standard image according to a preset threshold range based on the grayscale difference between different areas of the standard image, and determine the first packaging area and the first tablet area; The standard image segmentation module is specifically used for: Determining a preset grayscale threshold, wherein the grayscale threshold is determined based on a grayscale difference between the tablet region image and the package region image in the standard image; According to the grayscale threshold, the standard image is segmented by a threshold value, and a region where the grayscale value is within a first preset threshold range is extracted to obtain a first packaging region; Extracting an area whose grayscale value is within a second preset threshold range, and obtaining a first pill area after feature selection and closing operation processing; The image segmentation module to be detected is used to perform threshold segmentation on the image to be detected according to a preset threshold range based on the grayscale difference between different areas of the image to be detected, and determine the second packaging area; Transformation matrix calculation module: used to calculate the coordinates of the corner points of the first packaging area and the second packaging area respectively, and calculate the projection transformation matrix according to the coordinates of the corner points of the first packaging area and the second packaging area; Target image acquisition module: used to project the first pill area onto the image to be detected according to the obtained projection transformation matrix to obtain the second pill area, and obtain the target image by cutting out the image; Missing judgment module: used to judge whether there are missing pills based on the obtained target image by calculating the contrast of the target image.

8. An electronic device, characterized in that: include: processor; as well as, A memory arranged to store computer executable instructions, which, when executed, cause the processor to implement the steps of the method for missing tablets based on machine vision as claimed in any one of claims 1 to 6.

9. A storage medium, characterized in that: Used to store computer executable instructions, which, when executed, implement the steps of the method for detecting missing tablets based on machine vision according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Tablet inspection device, tablet inspection method, and tablet inspection program

    CN106104260A

  • Method for classification and online defect visual detection of blister drugs on production line

    CN107525808A