Blister capsule defect detection method and system

Through contour extraction and rectangular area cropping of the color image of the blister capsule, combined with Retinex image enhancement and color level cropping technology, the problem of poor detection of minor defects in the existing technology is solved, and efficient capsule defect detection is achieved, improving improve product quality and production efficiency.

CN118552476AActive Publication Date: 2024-08-27SIGMA SQUARES (BEIJING) TECH CO LTD

Patent Information

Application Number
CN202410425582.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-10
Publication Date
2024-08-27
Estimated Expiration
2044-04-10

AI Technical Summary

Technical Problem

Existing technology is ineffective at detecting minor defects in blister capsules, such as deformation and blistering.

Method used

By acquiring the color image of the medicine board, extracting the contours of the medicine board and capsule, cropping the rectangular area, applying Retinex image enhancement and color scale cropping contrast enhancement, performing smoothing and threshold segmentation, and judging the degree of deformation of the capsule to determine defects.

Benefits of technology

It improves the efficiency and accuracy of defect detection of blister capsules, reduces production costs, and ensures product quality after packaging.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118552476A
    Figure CN118552476A
Patent Text Reader

Abstract

The invention relates to a bubble cap capsule defect detection method and system, and the method comprises the steps: obtaining a color image of a medicine plate, then carrying out the positioning and contour extraction of the color image, and preliminarily judging whether a medicine has a large contour defect or is lack of particles or not. Cutting the area where the capsule is located to obtain a rectangular image, enhancing the rectangular image based on a Retinex enhancement algorithm, and performing contrast enhancement on the obtained first enhanced image so as to detect a non-defect area. And finally, judging whether the blister or the capsule at the corresponding position has defects or not through the non-defect area and the capsule contour. Defect detection is carried out on the capsules in the bubble caps instead of single capsules before packaging, so that the quality of packaged products is guaranteed. Compared with a manual detection mode, the detection efficiency is improved, and the production cost of an enterprise is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of machine vision technology, and in particular to a blister capsule defect detection method and system. Background Art

[0002] Common capsule packaging methods include medicine bottle packaging and medicine board packaging. Aluminum-plastic blister packaging is often used in medicine board packaging. Blister packaging is a packaging method that seals the product between a blister formed by a transparent plastic sheet and a base plate (made of cardboard, plastic film or sheet, aluminum foil or their composite materials). First, the plastic sheet is molded into a blister, and then the tablets are filled into the blister cavity. A covering material such as aluminum foil is used, and the pressure is used to heat-seal the blister substrate under certain temperature and time conditions. In the production process of aluminum-plastic blister packaging, some defects may occur on the blister plate and the medicine due to some reasons, so it is necessary to test the blister plate.

[0003] Some of the existing general testing methods mention the testing methods for blister plates and tablets and capsules inside the blisters, but the testing effect on minor defects of blister capsules such as deformation and bubble compression is not very good. Summary of the invention

[0004] In view of this, an object of the present invention is to provide a blister capsule defect detection method and system to solve the problem in the prior art that the detection effect of minor defects of the blister capsule, such as deformation, bubble compression, etc., is not very good.

[0005] In order to achieve the above object, the present invention adopts the following technical solutions:

[0006] A blister capsule defect detection method of the present invention comprises:

[0007] Obtain a color image of the medicine plate;

[0008] Extracting the outline of the medicine plate and the outline of the capsule inside the outline of the medicine plate in the color image; and performing capsule missing detection based on the number of the capsule outlines;

[0009] Cutting the rectangular area where the capsule outline is located to obtain a rectangular image;

[0010] Performing Retinex image enhancement on the rectangular image to obtain a first enhanced image; and performing contrast enhancement by color scale cropping on the first enhanced image to obtain a second enhanced image;

[0011] performing smoothing processing and threshold segmentation binarization on the second enhanced image in sequence to obtain a binarized image;

[0012] A non-defective area in the binary image is determined, a deformation degree is determined based on the non-defective area and the capsule contour, and whether a bubble shell or a capsule at a corresponding position has a defect is determined based on the deformation degree.

[0013] In one embodiment of the present application, extracting the outline of the medicine board in the color image and the outline of the capsule inside the outline of the medicine board includes:

[0014] Converting the color image into a grayscale image;

[0015] Performing threshold segmentation on the grayscale image to obtain a binary image;

[0016] Extracting all contours of the binary image, and selecting contours that meet target conditions from all contours as the medicine plate area, wherein the target conditions include contour area and width ratio meeting preset requirements;

[0017] Filling the medicine plate area to obtain a medicine plate mask, overlapping the medicine plate mask with the color image and performing an AND operation to obtain an input image for capsule positioning;

[0018] Convert the input image from RGB channels to HSV channels, and separate the H channel image;

[0019] When there is text on the capsule surface, an opening operation or a closing operation is performed on the H channel image based on the capsule color to obtain an intermediate image, and the intermediate image is threshold segmented to obtain a capsule contour; when there is no text on the capsule surface, the H channel image is threshold segmented to obtain a capsule contour.

[0020] In one embodiment of the present application, the rectangular area where the capsule outline is located is cropped to obtain a rectangular image, including:

[0021] Fitting a rotated rectangle at each capsule contour position, wherein the rotated rectangle surrounds the corresponding capsule contour;

[0022] Determine multiple target vertex coordinates when the selection rectangle reaches the target position after rotation and displacement, and determine multiple initial vertex coordinates of the rotation rectangle;

[0023] constructing an affine matrix based on the plurality of target vertex coordinates and the plurality of initial vertex coordinates;

[0024] The grayscale value of each pixel of the rotated rectangle is copied to the target position based on the affine matrix to obtain a horizontal rectangular image.

[0025] In an embodiment of the present application, performing Retinex image enhancement on the rectangular image to obtain a first enhanced image includes:

[0026] The grayscale value of each pixel in the rectangular image S is added by one and the logarithm is calculated to obtain a first process image log_S, wherein the rectangular image S is an 8-bit grayscale image with a range of 0-255. The mathematical expression of the first process image log_S is:

[0027] log_S=log(S+1)

[0028] Gaussian smoothing is performed on the first process image log_S to obtain a second process image blurred, wherein the mathematical expression of the second process image blurred is:

[0029] blurred = Gauss(log_S)

[0030] The gray value difference is calculated for each pixel of the first process image log_S and the corresponding pixel of the second process image blurred to obtain a third process image R, wherein the mathematical expression of the third process image R is:

[0031] R = log_S-blurred

[0032] The grayscale value of each pixel of the third process image R is normalized to obtain a first enhanced image.

[0033] In one embodiment of the present application, contrast enhancement of the first enhanced image by color scale cropping is performed to obtain a second enhanced image, including:

[0034] Calculating a histogram of the first enhanced image, wherein the histogram includes pixel distribution conditions of multiple gray levels in the first enhanced image;

[0035] The histogram is clipped based on a preset clipping percentage to obtain a maximum grayscale level and a minimum grayscale level, wherein a ratio of the number of pixels of the maximum grayscale level or the minimum grayscale level to the total number of pixels of the first enhanced image is the preset clipping percentage;

[0036] The grayscale value offset Δ of the maximum grayscale level and the minimum grayscale level is calculated based on the preset contrast parameter Contrast, and the grayscale values ​​of the pixels of the maximum grayscale level and the minimum grayscale level are adjusted based on the grayscale value offset Δ. The mathematical expression of the adjustment result is:

[0037]

[0038]

[0039] Δ=(Max-Min)Contrast

[0040] Min is the grayscale value of the pixel with the minimum grayscale level before adjustment, Min' is the grayscale value of the pixel with the minimum grayscale level after adjustment, Max is the grayscale value of the pixel with the maximum grayscale level before adjustment, and Max' is the grayscale value of the pixel with the maximum grayscale level after adjustment;

[0041] A mapping table is constructed based on the adjustment result, wherein the mathematical expression of the mapping table is:

[0042]

[0043] Where NewValue is the gray value of the pixel after adjustment, round() indicates rounding, MaxB is the maximum gray level obtained by the shearing operation, MinB indicates the minimum gray level obtained by shearing, and I is the gray value of the pixel in the first enhanced image;

[0044] Grayscale value mapping is performed on the first enhanced image based on the mapping table to obtain a second enhanced image.

[0045] In one embodiment of the present application, the second enhanced image is smoothed and threshold segmented and binarized in sequence to obtain a binarized image, including:

[0046] Smoothing the second enhanced image based on a preset filter window to obtain a smoothed image;

[0047] Threshold segmentation and binarization are performed on the smoothed image to obtain a binarized image.

[0048] In one embodiment of the present application, determining a non-defective area in the binary image includes:

[0049] Non-zero pixels in the binary image are determined, and an area formed by the non-zero pixels is used as a non-defective area.

[0050] In one embodiment of the present application, determining the degree of deformation based on the non-defective area and the capsule contour includes:

[0051] The difference between the area of ​​the non-defective region and the area of ​​the capsule outline is calculated to obtain the degree of deformation.

[0052] In an embodiment of the present application, judging whether a bubble shell or a capsule at a corresponding position has a defect based on the deformation degree includes:

[0053] When the deformation degree is greater than a preset threshold, it is determined that the bubble shell or capsule at the corresponding position has a defect; otherwise, it is determined that the bubble shell or capsule at the corresponding position has no defect.

[0054] The present application also provides a blister capsule defect detection system, comprising:

[0055] An acquisition module, used for acquiring a color image of a medicine plate;

[0056] A contour extraction module, used to extract the outline of the medicine plate in the color image and the outline of the capsule inside the outline of the medicine plate; and to perform capsule missing detection based on the number of capsule outlines;

[0057] A cropping module, used for cropping the rectangular area where the capsule outline is located to obtain a rectangular image;

[0058] A first enhancement module is used to perform Retinex image enhancement on the rectangular image to obtain a first enhanced image; and perform contrast enhancement by color scale cropping on the first enhanced image to obtain a second enhanced image;

[0059] A second enhancement module is used to perform smoothing processing and threshold segmentation binarization on the second enhanced image in sequence to obtain a binarized image;

[0060] The judgment module is used to determine the non-defective area in the binary image, determine the deformation degree based on the area of ​​the non-defective area and the capsule contour, and judge whether the bubble shell or capsule at the corresponding position has defects based on the deformation degree.

[0061] The present application also provides an electronic device, the electronic device comprising:

[0062] one or more processors;

[0063] The storage device is used to store one or more programs. When the one or more programs are executed by the one or more processors, the electronic device implements the blister capsule defect detection method as described above.

[0064] The present application also provides a computer-readable storage medium, characterized in that a computer program is stored thereon, and when the computer program is executed by a processor of a computer, the computer is enabled to execute the above-mentioned method for detecting defects in blister capsules.

[0065] The beneficial effects of the present invention are as follows: a blister capsule defect detection method and system of the present invention obtains a color image of a medicine plate, and then locates and extracts the contour of the color image to preliminarily determine whether the medicine has a large contour defect or missing grains. Then the area where the capsule is located is cropped to obtain a rectangular image, and the rectangular image is enhanced based on the Retinex enhancement algorithm, and the obtained first enhanced image is contrast enhanced to facilitate the detection of non-defective areas. Finally, the non-defective area and the capsule contour are used to determine whether the blister or capsule at the corresponding position has defects. The present application performs defect detection on capsules in the blister, rather than single capsules before packaging, which ensures the quality of the packaged product. Compared with manual detection methods, the present invention improves detection efficiency and reduces the production cost of the enterprise. BRIEF DESCRIPTION OF THE DRAWINGS

[0066] The present invention will be further described below in conjunction with the accompanying drawings and embodiments:

[0067] Figure 1 is a schematic flow chart of a blister capsule defect detection method shown in an embodiment of the present application;

[0068] Figure 2 is a schematic diagram of an input image in an embodiment of the present application;

[0069] Figure 3 is a schematic diagram of a capsule outline in an embodiment of the present application;

[0070] Figure 4 is a schematic diagram of a rectangular image in an embodiment of the present application;

[0071] Figure 5 This is a schematic diagram of the effect of performing Retinex image enhancement on a rectangular image in an embodiment of the present application;

[0072] Figure 6 A schematic diagram of a contrast enhancement effect in an embodiment of the present application;

[0073] Figure 7 This is a schematic diagram of a non-defective area in an embodiment of the present application;

[0074] Figure 8 It is a structural diagram of a blister capsule defect detection system shown in one embodiment of the present application. DETAILED DESCRIPTION

[0075] The following describes the embodiments of the present invention by specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict.

[0076] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present invention, and thus the drawings only show the layers related to the present invention rather than being drawn according to the number, shape and size of the layers in actual implementation. In actual implementation, the type, quantity and proportion of each layer may be changed arbitrarily, and the layer layout may also be more complicated.

[0077] In the following description, numerous details are discussed to provide a more thorough explanation of embodiments of the present invention; however, it is apparent to one skilled in the art that embodiments of the present invention may be practiced without these specific details.

[0078] Figure 1 FIG. 1 is a flow chart of a blister capsule defect detection method shown in an embodiment of the present application. Figure 1 As shown, this application includes:

[0079] S110, obtaining a color image of the medicine plate; wherein, the present application obtains the color image from an industrial camera.

[0080] S120, extracting the outline of the medicine plate and the outline of the capsule inside the outline of the medicine plate in the color image; and performing capsule missing detection based on the number of capsule outlines;

[0081] This application first extracts the outline of the medicine plate, and then extracts the outline of the capsule inside the outline of the medicine plate, specifically including:

[0082] S121, converting the color image into a grayscale image;

[0083] S122, performing threshold segmentation on the grayscale image to obtain a binary image;

[0084] S123, extracting all contours of the binary image, and selecting contours that meet target conditions from all contours as the medicine plate area, wherein the target conditions include contour area and width ratio meeting preset requirements;

[0085] S124, filling the medicine plate area to obtain a medicine plate mask, overlapping the medicine plate mask with the color image and performing an AND operation to obtain an input image for capsule positioning;

[0086] Figure 2 is a schematic diagram of an input image in an embodiment of the present application. The input image obtained by the above process is as follows: Figure 2 As shown, Figure 2 The edge line of the medicine plate has been marked.

[0087] S125, converting the input image from RGB channels to HSV channels, and separating an H channel image; the H channel represents color.

[0088] S126, when there are texts on the capsule surface, performing an opening operation or a closing operation on the H channel image based on the capsule color to obtain an intermediate image, performing threshold segmentation on the intermediate image to obtain a capsule outline; when there are no texts on the capsule surface, performing threshold segmentation on the H channel image to obtain a capsule outline.

[0089] Since the color of the capsule is quite different from the silver-white aluminum foil, threshold segmentation is performed based on the H image. If there is text on the capsule, an opening or closing operation is performed based on the capsule color to prevent text interference. The contour is then extracted, and finally the contour corresponding to the capsule is screened based on the area and aspect ratio. This step can detect serious defects such as powder leakage and truncation.

[0090] Figure 3 is a schematic diagram of a capsule contour in an embodiment of the present application. The capsule contour obtained by threshold segmentation is as follows: Figure 3 shown.

[0091] If it is a two-color capsule, two segmentations are performed, one for each color. The capsule is considered to be located only when both parts of the contour meet the conditions.

[0092] At this time, the outline of each capsule is obtained. If the blister and capsule are slightly deformed, the color change is small. If the deformation is serious, the outline area will change, which can be eliminated during positioning. Therefore, this step does not affect the deformation detection of the blister and capsule in the next step.

[0093] S130, cropping the rectangular area where the capsule outline is located to obtain a rectangular image;

[0094] The specific steps include:

[0095] S131, fitting a rotated rectangle at each capsule contour position, wherein the rotated rectangle surrounds the corresponding capsule contour;

[0096] S132, determining the coordinates of multiple target vertices when the selection rectangle reaches the target position after being rotated and displaced, and determining the coordinates of multiple initial vertices of the rotation rectangle;

[0097] S133, constructing an affine matrix based on the multiple target vertex coordinates and the multiple initial vertex coordinates;

[0098] S134, copying the grayscale value of each pixel of the rotated rectangle to the target position based on the affine matrix to obtain a horizontal rectangular image.

[0099] In this embodiment, a rotated rectangle is fitted to the outline of each capsule. The affine matrix is ​​calculated based on the position coordinates of the four vertices of the rotated rectangle and the coordinates of the four vertices of the horizontal rectangle after it is rotated and moved to the upper left corner of the image. Each coordinate of the horizontal rectangle is traversed, the position of the corresponding rotated rectangle is calculated, and the gray value of this position in the rotated rectangle is copied to the horizontal rectangle. Therefore, the rotated rectangles are cut out one by one, and the rotated horizontal rectangular images are obtained one by one.

[0100] Figure 4 is a schematic diagram of a rectangular image in an embodiment of the present application. The rectangular image obtained by cutting through the above process is as follows: Figure 4 shown.

[0101] S140, performing Retinex image enhancement on the rectangular image to obtain a first enhanced image; and performing contrast enhancement by color scale cropping on the first enhanced image to obtain a second enhanced image;

[0102] In this embodiment, each cropped capsule color BGR image is converted into a grayscale image, and then the Retinex image enhancement algorithm and the color scale-based contrast stretching algorithm are used to enhance the edge information. Finally, defects are detected by image smoothing and threshold segmentation. The difference between the threshold segmentation area and the capsule positioning contour area is used to indicate the degree of deformation.

[0103] If it is a two-color capsule, the position information of each color has been obtained in step S120, and the position information is mapped together with the affine sampling to obtain the position of each color in the regular rectangle. In order to prevent the color mutation area in the middle of the two-color capsule from affecting the detection result, an inspection-free area is set in the middle part of the entire capsule. Then, the Retinex image enhancement algorithm is performed on each part, and defects are detected based on the contrast stretching of the color scale, image smoothing and threshold segmentation. The overall deformation degree is comprehensively evaluated according to the deformation degree of the two areas.

[0104] (1) Retinex image enhancement

[0105] In the Retinex image enhancement algorithm, the image can be regarded as an incident image and a reflected image. The incident light shines on the reflective object, and the reflected light enters the human eye through the reflection of the reflective object. The formula is as follows:

[0106] S(x,y)=R(x,y)×L(x,y)

[0107] S(x,y) represents the image signal being observed or received by the camera; L(x,y) represents the illumination component of the ambient light; R(x,y) represents the reflection component of the target object that carries the image detail information. This formula can be used to restore R(x,y) to calculate R(x,y) = S(x,y) / L(x,y)

[0108] Based on the above principle, the process of performing Retinex image enhancement on the rectangular image to obtain the first enhanced image specifically includes:

[0109] S1401, adding one to the grayscale value of each pixel in the rectangular image S and calculating the logarithm to obtain a first process image log_S, wherein the rectangular image S is an 8-bit grayscale image with a range of 0-255, and the mathematical expression of the first process image log_S is:

[0110] log_S=log(S+1)

[0111] The purpose of S+1 is to make log(S+1) greater than 0.

[0112] S1402, performing Gaussian smoothing on the first process image log_S to obtain a second process image blurred, wherein the mathematical expression of the second process image blurred is:

[0113] blurred = Gauss(log_S)

[0114] In this application, Gaussian smoothing is used to simulate the illumination component.

[0115] S1403, performing grayscale value difference between each pixel of the first process image log_S and the corresponding pixel of the second process image blurred to obtain a third process image R, wherein the mathematical expression of the third process image R is:

[0116] R = log_S-blurred

[0117] S1404: Normalize the grayscale value of each pixel of the third process image R to obtain a first enhanced image.

[0118] Figure 5 FIG. 1 is a schematic diagram showing the effect of performing Retinex image enhancement on a rectangular image in an embodiment of the present application. Figure 5 As shown, the left side is a rectangular image, and the right side is an enhanced image (obtaining a first enhanced image).

[0119] (2) Contrast enhancement

[0120] The specific process of contrast enhancement in this application includes:

[0121] S1411, calculating a histogram of the first enhanced image, wherein the histogram includes pixel distribution conditions of multiple gray levels in the first enhanced image;

[0122] S1412, cropping the histogram based on a preset cropping percentage to obtain a maximum grayscale Max and a minimum grayscale Min, wherein a ratio of the number of pixels of the maximum grayscale or the minimum grayscale to the total number of pixels of the first enhanced image is a preset cropping percentage;

[0123] In this embodiment, the maximum grayscale and minimum grayscale after clipping are calculated by means of a cumulative histogram. The value of the cumulative histogram is the current grayscale histogram plus the value of the histogram of all grayscales that are less than or greater than the current grayscale. For example, if the clipping ratio is set to 10%, then when clipping a smaller value, the first grayscale in the cumulative histogram that is greater than or equal to the total number of image pixels multiplied by the clipping ratio is recorded as MinB. When clipping a larger value, the cumulative histogram is accumulated in order from a larger grayscale to a smaller grayscale, and the first grayscale in the cumulative histogram that is greater than or equal to the total number of image pixels multiplied by the clipping ratio is recorded as MaxB.

[0124] S1413, calculating the grayscale value offset Δ of the maximum grayscale level and the minimum grayscale level based on the preset contrast parameter Contrast, and adjusting the grayscale values ​​of the pixels of the maximum grayscale level and the minimum grayscale level based on the grayscale value offset Δ, and the mathematical expression of the adjustment result is:

[0125]

[0126]

[0127] Δ=(Max-Min)Contrast

[0128] Min is the grayscale value of the pixel with the minimum grayscale level before adjustment, Min' is the grayscale value of the pixel with the minimum grayscale level after adjustment, Max is the grayscale value of the pixel with the maximum grayscale level before adjustment, and Max' is the grayscale value of the pixel with the maximum grayscale level after adjustment;

[0129] Through contrast adjustment, new minimum value Min' and maximum value Max' are determined to re-stretch the pixel values ​​within the cropped range. The main purpose of contrast adjustment is to make the pixel values ​​within the cropped range more dispersed, avoid flat areas, and thus enhance the contrast of the image.

[0130] S1414: construct a mapping table based on the adjustment result, wherein the mathematical expression of the mapping table is:

[0131]

[0132] Where NewValue is the gray value of the pixel after adjustment, round() indicates rounding, MaxB is the maximum gray level obtained by the shearing operation, MinB indicates the minimum gray level obtained by shearing, and I is the gray value of the pixel in the first enhanced image;

[0133] This mapping table defines the new value that each gray level should be mapped to. If it is not clipped, the gray value is stretched to the new range, and NewValue represents the transformed gray level, which ranges from 0 to 255. The mapping table is segmented. If it is clipped, gray levels less than MinB are mapped to Min', and gray levels greater than MaxB are mapped to Max'.

[0134] S1415: Perform grayscale value mapping on the first enhanced image based on the mapping table to obtain a second enhanced image.

[0135] Finally, the generated mapping table is applied to the entire image or a specific area. This step achieves the color level cropping of the image, so that the contrast and brightness of the image are adjusted. In this way, the algorithm improves the overall visual effect while retaining the image details.

[0136] In this application, Contrast is set to 0.5 and CutLimit is set to 0.1.

[0137] Figure 6 is a schematic diagram of the contrast enhancement effect in an embodiment of the present application. The effect of the second enhanced image is as follows: Figure 5 shown.

[0138] S150, performing smoothing processing and threshold segmentation binarization on the second enhanced image in sequence to obtain a binarized image;

[0139] Specifically include:

[0140] S151, smoothing the second enhanced image based on a preset filter window to obtain a smoothed image; the present application uses a filter window with a width and height of 7*7 to smooth the second enhanced image.

[0141] S152, performing threshold segmentation and binarization on the smoothed image to obtain a binarized image.

[0142] This application uses global threshold segmentation. If the capsule or bubble shell is deformed, its gray value will be significantly lower after the above image enhancement.

[0143] S160, determining a non-defective area in the binary image, determining a deformation degree based on the non-defective area and the capsule contour, and judging whether a bubble shell or a capsule at a corresponding position has a defect based on the deformation degree.

[0144] Specifically, the present application determines the non-zero pixels in the binary image and uses the area formed by the non-zero pixels as the non-defect area, and then calculates the difference between the area of ​​the non-defect area and the area of ​​the capsule contour to obtain the degree of deformation.

[0145] Figure 7 is a schematic diagram of a non-defective area in an embodiment of the present application. In the present application, the non-defective area of ​​the tube is determined as follows: Figure 7 As shown, the yellow part is the non-defective area, and the red part is the interpolation of the capsule contour area and the non-defective area, so the red area is the defective area.

[0146] When the deformation degree is greater than a preset threshold, it is determined that the bubble shell or capsule at the corresponding position has a defect; otherwise, it is determined that the bubble shell or capsule at the corresponding position has no defect.

[0147] A defect detection method for blister capsules of the present invention obtains a color image of a medicine plate, then locates and extracts the contour of the color image, and preliminarily determines whether the medicine has a large contour defect or missing grains. Then the area where the capsule is located is cropped to obtain a rectangular image, and the rectangular image is enhanced based on the Retinex enhancement algorithm, and the obtained first enhanced image is contrast enhanced to facilitate the detection of non-defective areas. Finally, the non-defective area and the capsule contour are used to determine whether the blister or capsule at the corresponding position has defects. The present application performs defect detection on capsules in blisters, rather than single-grain capsules before packaging, which ensures the quality of the packaged products. Compared with manual detection methods, the present invention improves detection efficiency and reduces the production cost of enterprises. In addition, the present invention is simple and effective, supports both monochrome capsules and dual-color capsules, is compatible with a variety of products and usage scenarios, does not require the construction of large-scale data sets, and does not require deep learning training.

[0148] like Figure 8 As shown, the present application also provides a blister capsule defect detection system, comprising:

[0149] An acquisition module, used for acquiring a color image of a medicine plate;

[0150] A contour extraction module, used to extract the outline of the medicine plate in the color image and the outline of the capsule inside the outline of the medicine plate; and to perform capsule missing detection based on the number of capsule outlines;

[0151] A cropping module, used for cropping the rectangular area where the capsule outline is located to obtain a rectangular image;

[0152] A first enhancement module is used to perform Retinex image enhancement on the rectangular image to obtain a first enhanced image; and perform contrast enhancement by color scale cropping on the first enhanced image to obtain a second enhanced image;

[0153] A second enhancement module is used to perform smoothing processing and threshold segmentation binarization on the second enhanced image in sequence to obtain a binarized image;

[0154] The judgment module is used to determine the non-defective area in the binary image, determine the deformation degree based on the area of ​​the non-defective area and the capsule contour, and judge whether the bubble shell or capsule at the corresponding position has defects based on the deformation degree.

[0155] A blister capsule defect detection system of the present invention obtains a color image of a medicine plate, then locates and extracts the contour of the color image, and preliminarily determines whether the medicine has a large contour defect or missing grains. Then the area where the capsule is located is cropped to obtain a rectangular image, and the rectangular image is enhanced based on the Retinex enhancement algorithm, and the obtained first enhanced image is contrast enhanced to facilitate the detection of non-defective areas. Finally, the non-defective area and the capsule contour are used to determine whether the blister or capsule at the corresponding position has defects. The present application performs defect detection on capsules in blisters, rather than single-grain capsules before packaging, which ensures the quality of the packaged products. Compared with manual detection methods, the present invention improves detection efficiency and reduces the production cost of enterprises. In addition, the present invention is simple and effective, supporting both monochrome and dual-color capsules, and is compatible with a variety of products and usage scenarios. There is no need to build a large-scale data set or deep learning training.

[0156] This embodiment further provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, any one of the methods in this embodiment is implemented, wherein the method is the execution logic of this system.

[0157] This embodiment also provides an electronic terminal, including: a processor and a memory;

[0158] The memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the terminal executes any one of the methods in this embodiment.

[0159] The computer-readable storage medium in this embodiment can be understood by ordinary technicians in this field: all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to the computer program. The aforementioned computer program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other media that can store program codes.

[0160] The electronic terminal provided in this embodiment includes a processor, a memory, a transceiver and a communication interface. The memory and the communication interface are connected to the processor and the transceiver and complete communication with each other. The memory is used to store computer programs, the communication interface is used to communicate, and the processor and the transceiver are used to run computer programs so that the electronic terminal executes each step of the above method.

[0161] In this embodiment, the memory may include a random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.

[0162] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0163] In the above-mentioned embodiments, although the present invention has been described in conjunction with the specific embodiments of the present invention, many replacements, modifications and variations of these embodiments will be apparent to those skilled in the art according to the foregoing description. The embodiments of the present invention are intended to cover all such replacements, modifications and variations falling within the broad scope of the appended claims.

[0164] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Anyone familiar with the art may modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by a person of ordinary skill in the art without departing from the spirit and technical concept disclosed by the present invention shall still be covered by the claims of the present invention.

Claims

1. A method for detecting defects in blister capsules, It is characterized in that Includes steps: Obtain a color image of the medicine plate; Extracting the outline of the medicine plate and the outline of the capsule inside the outline of the medicine plate in the color image; and performing capsule missing detection based on the number of the capsule outlines; Cutting the rectangular area where the capsule outline is located to obtain a rectangular image; Performing Retinex image enhancement on the rectangular image to obtain a first enhanced image; and performing contrast enhancement by color scale cropping on the first enhanced image to obtain a second enhanced image; performing smoothing processing and threshold segmentation binarization on the second enhanced image in sequence to obtain a binarized image; A non-defective area in the binary image is determined, a deformation degree is determined based on the non-defective area and the capsule contour, and whether a bubble shell or a capsule at a corresponding position has a defect is determined based on the deformation degree.

2. A blister capsule defect detection method according to claim 1, It is characterized in that Extracting the outline of the medicine plate in the color image and the outline of the capsule inside the outline of the medicine plate, including: Converting the color image into a grayscale image; Performing threshold segmentation on the grayscale image to obtain a binary image; Extracting all contours of the binary image, and selecting contours that meet target conditions from all contours as the medicine plate area, wherein the target conditions include contour area and width ratio meeting preset requirements; Filling the medicine plate area to obtain a medicine plate mask, overlapping the medicine plate mask with the color image and performing an AND operation to obtain an input image for capsule positioning; Convert the input image from RGB channels to HSV channels, and separate the H channel image; When there is text on the capsule surface, an opening operation or a closing operation is performed on the H channel image based on the capsule color to obtain an intermediate image, and the intermediate image is threshold segmented to obtain a capsule contour; when there is no text on the capsule surface, the H channel image is threshold segmented to obtain a capsule contour.

3. A blister capsule defect detection method according to claim 1, It is characterized in that The rectangular area where the capsule outline is located is cropped to obtain a rectangular image, including: Fitting a rotated rectangle at each capsule contour position, wherein the rotated rectangle surrounds the corresponding capsule contour; Determine multiple target vertex coordinates when the selection rectangle reaches the target position after rotation and displacement, and determine multiple initial vertex coordinates of the rotation rectangle; constructing an affine matrix based on the plurality of target vertex coordinates and the plurality of initial vertex coordinates; The grayscale value of each pixel of the rotated rectangle is copied to the target position based on the affine matrix to obtain a horizontal rectangular image.

4. A blister capsule defect detection method according to claim 1, It is characterized in that Performing Retinex image enhancement on the rectangular image to obtain a first enhanced image includes: The grayscale value of each pixel in the rectangular image S is added by one and the logarithm is calculated to obtain a first process image log_S, wherein the rectangular image S is an 8-bit grayscale image with a range of 0-255. The mathematical expression of the first process image log_S is: log_S=log(S+1) Gaussian smoothing is performed on the first process image log_S to obtain a second process image blurred, wherein the mathematical expression of the second process image blurred is: blurred = Gauss(log_S) The gray value difference is calculated for each pixel of the first process image log_S and the corresponding pixel of the second process image blurred to obtain a third process image R, wherein the mathematical expression of the third process image R is: R = log_S-blurred The grayscale value of each pixel of the third process image R is normalized to obtain a first enhanced image.

5. A blister capsule defect detection method according to claim 1, It is characterized in that Performing contrast enhancement by color scale cropping on the first enhanced image to obtain a second enhanced image includes: Calculating a histogram of the first enhanced image, wherein the histogram includes pixel distribution conditions of multiple gray levels in the first enhanced image; The histogram is clipped based on a preset clipping percentage to obtain a maximum grayscale level and a minimum grayscale level, wherein a ratio of the number of pixels of the maximum grayscale level or the minimum grayscale level to the total number of pixels of the first enhanced image is the preset clipping percentage; The grayscale value offset Δ of the maximum grayscale level and the minimum grayscale level is calculated based on the preset contrast parameter Contrast, and the grayscale values ​​of the pixels of the maximum grayscale level and the minimum grayscale level are adjusted based on the grayscale value offset Δ. The mathematical expression of the adjustment result is: Δ=(Max-Min)Contrast Min is the grayscale value of the pixel with the minimum grayscale level before adjustment, Min' is the grayscale value of the pixel with the minimum grayscale level after adjustment, Max is the grayscale value of the pixel with the maximum grayscale level before adjustment, and Max' is the grayscale value of the pixel with the maximum grayscale level after adjustment; A mapping table is constructed based on the adjustment result, wherein the mathematical expression of the mapping table is: Where NewValue is the gray value of the pixel after adjustment, round() indicates rounding, MaxB is the maximum gray level obtained by the shearing operation, MinB indicates the minimum gray level obtained by shearing, and I is the gray value of the pixel in the first enhanced image; Grayscale value mapping is performed on the first enhanced image based on the mapping table to obtain a second enhanced image.

6. A blister capsule defect detection method according to claim 1, It is characterized in that The second enhanced image is subjected to smoothing processing and threshold segmentation binarization in sequence to obtain a binarized image, including: Smoothing the second enhanced image based on a preset filter window to obtain a smoothed image; Threshold segmentation and binarization are performed on the smoothed image to obtain a binarized image.

7. A blister capsule defect detection method according to claim 1, It is characterized in that Determining a non-defective area in the binary image includes: Non-zero pixels in the binary image are determined, and an area formed by the non-zero pixels is used as a non-defective area.

8. A blister capsule defect detection method according to claim 1, It is characterized in that Determining the degree of deformation based on the non-defective area and the capsule contour includes: The difference between the area of ​​the non-defective region and the area of ​​the capsule outline is calculated to obtain the degree of deformation.

9. A blister capsule defect detection method according to claim 1, It is characterized in that Judging whether the bubble shell or capsule at the corresponding position has a defect based on the deformation degree includes: When the deformation degree is greater than a preset threshold, it is determined that the bubble shell or capsule at the corresponding position has a defect; otherwise, it is determined that the bubble shell or capsule at the corresponding position has no defect.

10. A blister capsule defect detection system, It is characterized in that include: An acquisition module, used for acquiring a color image of a medicine plate; A contour extraction module, used to extract the outline of the medicine plate in the color image and the outline of the capsule inside the outline of the medicine plate; and to perform capsule missing detection based on the number of capsule outlines; A cropping module, used for cropping the rectangular area where the capsule outline is located to obtain a rectangular image; A first enhancement module, configured to perform Retinex image enhancement on the rectangular image to obtain a first enhanced image; and performing contrast enhancement by color scale cropping on the first enhanced image to obtain a second enhanced image; A second enhancement module is used to perform smoothing processing and threshold segmentation binarization on the second enhanced image in sequence to obtain a binarized image; The judgment module is used to determine the non-defective area in the binary image, determine the deformation degree based on the area of ​​the non-defective area and the capsule contour, and judge whether the bubble shell or capsule at the corresponding position has defects based on the deformation degree.

Citation Information

Patent Citations

  • Capsule defect visual detection method based on matrix analysis

    CN110570422A

  • Infrared image denoising enhancement method, device and system based on local adaptive CLAHE, and computer readable storage medium

    CN112365424A

  • Blister defect general detection method based on machine vision

    CN115578380A

  • Capsule endoscope gastrointestinal low-light image adaptive enhancement method

    CN115661111A

  • Mine infrared image enhancement method and device

    CN115861117A

Cited By

  • Vacuum machine package sealing performance detection system based on convolutional neural network

    CN118761014A