Vial defect detection method and device based on image recognition
Through the vial defect detection method based on image recognition, through image processing and pharmaceutical powder imaging feature analysis, the problems of low detection efficiency and low accuracy of vials in the existing technology are solved, fast and accurate defect identification is achieved, and the quality of medicines is improved. control.
Patent Information
- Application Number
- CN202311603820.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-28
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2043-11-28
AI Technical Summary
The existing technology has low efficiency, low accuracy, and low robustness in detecting defects in vials during the pharmaceutical production process. It is especially difficult to identify small-area and small-scale powder defects, resulting in insufficient drug efficacy or health problems.
The vial defect detection method based on image recognition is used to preprocess and extract the contour by identifying the area of interest in the collected image. De-adhesion processing and correction are performed based on the morphological characteristics of the vial. Defects are determined based on the imaging characteristics of the pharmaceutical powder to improve detection accuracy. .
It improves the speed and accuracy of vial defect detection, reduces misjudgments, can effectively identify small and medium-sized defects in drugs, and improves the efficiency and productivity of drug quality control.
Smart Images

Figure CN117611799B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image recognition, and in particular to a method and device for detecting defects in vials based on image recognition. Background Art
[0002] With the growth of global population and the increasing demand for medicines, the demand for vials, as containers for powdered medicines, is also increasing year by year. In the process of filling powdered medicines into vials by filling machines, empty bottles, slight powder hanging, severe powder hanging and other problems are prone to occur, which will lead to insufficient efficacy of the medicines and in severe cases, health problems for the users of the medicines. Therefore, defect detection of medical vials is a very important requirement.
[0003] At present, manual visual inspection is mainly used in the production process of pharmaceuticals. Under the conditions of sufficient light and good product consistency, the effect of manual visual inspection is relatively good. However, for powder defects with small area and small degree, it is difficult to distinguish directly with the naked eye and high-resolution detection instruments are needed for observation. Manual inspection has the problems of low efficiency, low precision and low robustness.
[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0005] In order to solve or partially solve the problems existing in the related art, the solution provided in the present application can improve the speed and accuracy of defect detection of vials during the vial transmission process.
[0006] The first aspect of the present application provides a method for detecting defects in medical vials, comprising:
[0007] Identify the region of interest of the acquired image and extract the image to be detected;
[0008] Preprocessing the image to be detected, extracting the contour of the preprocessed image to be detected, and obtaining a first image;
[0009] Extracting a contour of the first image based on the morphological features of the vial to obtain a second image that meets the morphological features of the vial and a third image that does not meet the morphological features of the vial;
[0010] Performing de-adhesion processing on the third image based on a preset size kernel filter, extracting a contour of the de-adhesion processed third image based on the morphological features of the vial, and obtaining a fourth image that conforms to the morphological features of the vial;
[0011] According to the imaging characteristics of the vial, the second image and the fourth image are corrected to obtain a candidate vial image;
[0012] The candidate vial images are extracted according to the powder imaging features to obtain the powder image corresponding to each vial. When the powder image is smaller than the preset minimum powder image, it is determined that the vial corresponding to the powder image is defective.
[0013] The second aspect of the present application provides a medical vial defect detection device, comprising:
[0014] A detection module is used to identify the region of interest of the collected image and extract the image to be detected;
[0015] A first extraction module is used to preprocess the image to be detected, extract the contour of the preprocessed image to be detected, and obtain a first image;
[0016] A second extraction module is used to extract the contour of the first image based on the morphological features of the vial, so as to obtain a second image that meets the morphological features of the vial and a third image that does not meet the morphological features of the vial;
[0017] A correction module, used for performing de-adhesion processing on the third image based on a preset size kernel filter, extracting a contour of the de-adhesion processed third image based on the morphological features of the vial, and obtaining a fourth image that conforms to the morphological features of the vial;
[0018] A third extraction module is used to correct the second image and the fourth image according to the imaging characteristics of the vial to obtain a candidate vial image;
[0019] The defect inspection module is used to extract candidate vial images according to the powder imaging features, obtain the powder image corresponding to each vial, and when the powder image is smaller than the preset minimum powder image, determine that the vial corresponding to the powder image has a defect.
[0020] A third aspect of the present application provides an electronic device, including:
[0021] Processor; and
[0022] The memory stores executable codes, and when the executable codes are executed by the processor, the processor executes the above method.
[0023] A fourth aspect of the present application provides a computer-readable storage medium having executable code stored thereon. When the executable code is executed by a processor of an electronic device, the processor executes the above method.
[0024] The technical solution provided by this application may have the following beneficial effects:
[0025] In the first aspect, the present application extracts an image to be detected by identifying a region of interest of a captured image; preprocesses the image to be detected, extracts a contour of the preprocessed image to be detected, and obtains a first image; extracts a contour of the first image based on the morphological features of the vial, and obtains a second image that meets the morphological features of the vial and a third image that does not meet the morphological features of the vial; de-adhesions the third image based on a preset size kernel filter, and extracts a contour of the de-adhesioned third image based on the morphological features of the vial, and obtains a fourth image that meets the morphological features of the vial; corrects the second image and the fourth image according to the imaging characteristics of the vial, and obtains a candidate vial image; the present application reduces misjudgment of the vial image and improves the accuracy of identifying the vial through multiple image processing processes of the vial image.
[0026] In the second aspect, the method of the present application includes: extracting candidate vial images based on drug powder imaging features, obtaining a drug powder image corresponding to each vial, and determining that the vial corresponding to the drug powder image is defective when the drug powder image is smaller than a preset minimum drug powder image. The present application further separates the drug powder from the vial background based on the drug powder imaging features, and determines whether the vial is qualified by identifying the drug powder image.
[0027] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] The above and other objects, features and advantages of the present application will become more apparent by describing in more detail exemplary embodiments of the present application in conjunction with the accompanying drawings, wherein the same reference numerals generally represent the same components in the exemplary embodiments of the present application.
[0029] Figure 1 It is a flow chart of a method for detecting defects in vials based on image recognition according to an embodiment of the present application;
[0030] Figure 2 is another flow chart of a method for detecting defects in vials based on image recognition according to an embodiment of the present application;
[0031] Figure 3 It is a schematic diagram of the structure of an electronic device shown in an embodiment of the present application. DETAILED DESCRIPTION
[0032] The embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to make the present application more thorough and complete, and to fully convey the scope of the present application to those skilled in the art.
[0033] The terms used in this application are for the purpose of describing specific embodiments only and are not intended to limit this application. The singular forms of "a", "said" and "the" used in this application and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0034] It should be understood that although the terms "first", "second", "third", etc. may be used in this application to describe various information, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of this application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of this application, the meaning of "multiple" is two or more, unless otherwise clearly and specifically defined.
[0035] With the growth of global population and the increasing demand for medicines, the demand for vials, which are containers for powdered medicines, is also increasing year by year. In the process of filling powdered medicines into vials by filling machines, problems such as empty bottles, slight powder hanging, and severe powder hanging are prone to occur, which will lead to insufficient efficacy of the medicines and, in severe cases, health problems for the users of the medicines. Therefore, defect detection of medical vials is a very important requirement.
[0036] At present, manual visual inspection is mainly used in the production process of pharmaceuticals. Under the conditions of sufficient light and good product consistency, the effect of manual visual inspection is relatively good. However, for powder defects with a small area and a small degree, it is difficult to distinguish directly with the naked eye and high-resolution detection instruments are needed for observation. Manual inspection has the problems of low efficiency, low precision and low robustness.
[0037] To address the above-mentioned problems, no effective solution has been proposed yet.
[0038] This application provides a method for detecting defects in vials based on image recognition, which can effectively improve the rapid inspection of vials during the transmission of bearing parts. This method is combined with chain plate transmission equipment, and the mechanical movement is combined with the camera and lighting to identify all rollers within a certain range of the chain plate, and then start to automatically count the number of rollers.
[0039] The application scenarios of this method include: the industrial computer is started, after the system is powered on, the device software is started and logged in, the software starts the machine vision module and waits for the PLC signal to trigger the detection signal, the PLC motion control module is started, and the loader begins to transport the vials to the conveyor belt. The industrial camera and light source that have been started shoot and process the image of the material in real time, and the vial defect detection method based on image recognition provided by this application is automatically counted, and then the data is stored in the database. This application uses a conveyor belt to replace the manual picking method. The camera cooperates with the light source. The conveyor belt moves the product from the material frame to the front of the camera for inspection, which reduces the requirements for loading, improves the accuracy and speed of detection, and improves productivity. The kicking mechanism kicks the defective product out to the NG material frame next to the conveyor belt, realizing rapid inspection of defective products.
[0040] It should be noted that the vials in the present application are mainly used in the pharmaceutical field, and the method of the present application is mainly used to identify a series of defects of the pharmaceutical vials when they are converted into powdered medicine bottles.
[0041] Figure 1 : is a flow chart of a method for detecting defects in vials based on image recognition according to an embodiment of the present application. The method comprises:
[0042] Step S101, identifying the region of interest of the acquired image and extracting the image to be detected.
[0043] The captured image in this embodiment can be a continuous video image, and the conveyor belt image is processed by frame extraction according to the interval time of the video. In this embodiment, the conveyor belt is a chain plate conveyor belt. Different from the traditional double-speed conveyor belt, the chain plate conveyor belt transports materials more stably, making the image taken by the camera clearer and more stable, which helps to reduce the pre-processing steps of subsequent image recognition.
[0044] In one embodiment, in step S101, the height H and length W of a vial in the image are used as a reference, and W and H of the detection frame for capturing the region of interest are set to 1.2*W and 1.4H respectively.
[0045] Step S102 , preprocessing the image to be detected, extracting contours from the preprocessed image to be detected, and obtaining a first image.
[0046] The preprocessing of the image to be detected is mainly to perform image enhancement processing on the image to be detected. Image enhancement processing generally adopts image filtering. Image filtering is an operation to suppress the noise in the image to be processed under the condition of retaining the detailed features of the image to be processed. Image filtering can be performed in the real domain or in the frequency domain. After image filtering, the image quality can be changed or enhanced. Through filtering, some features in the image can be emphasized or some unnecessary parts in the image can be removed. The filter used for image filtering can be a linear filter, such as a box filter, a mean filter (blur), a Gaussian filter (Gaussian Blur), etc., or it can be a nonlinear filter, such as a median filter (medianBlur), a bilateral filter (Bilateral Filter), etc.
[0047] In one embodiment, the image to be detected is preprocessed, including: performing image enhancement operation on the image to be detected to obtain a first candidate image; performing binarization processing on the first candidate image to obtain a second candidate image; performing noise reduction processing on the second candidate image according to a median filtering operation and a size feature of a vial to obtain a preprocessed image to be detected.
[0048] Specifically, this embodiment obtains the first image by performing image enhancement operation on the image to be detected, with the purpose of increasing the contrast between the image and the background and better extracting the material features. Image enhancement mainly processes the image through equalization and linear enhancement of the image. Let f(x, y) represent the input image, g(x, y) represent the above first candidate image, and g(x, y)=T(f(x, y)) is used, where T represents the image enhancement operation, as shown in formula (1):
[0049] Formula (1);
[0050] Formula (1) uses piecewise linear transformation for image enhancement.
[0051] After obtaining the first candidate image, it is necessary to perform binarization on the first candidate image so that the gray value of the material edge is low, thereby distinguishing the background and the material connected domain. Set the segmentation threshold h, use g2 (x, y) to represent the second candidate image, and use formula (2) to perform binarization on the first candidate image. Formula (2) includes:
[0052]
[0053] The binarization of an image is to set the grayscale of the points on the image to 0 or 255, that is, to make the entire image present an obvious black and white effect. That is, the grayscale image with 256 brightness levels is selected through appropriate thresholds to obtain a binary image that can still reflect the overall and local features of the image. The collective properties of the image are only related to the position of the points with pixel values of 0 or 255, and no longer involve the multi-level values of the pixels, making the processing simpler, and the amount of data processing and compression is small. In order to obtain an ideal binary image, closed and connected boundaries are generally used to define non-overlapping areas. All pixels with grayscale greater than or equal to the threshold are judged to belong to a specific object, and their grayscale value is 255, otherwise these pixels are excluded from the object area, and the grayscale value is 0, indicating the background or exceptional object area. If a specific object has a uniform grayscale value inside, and it is under a uniform background with other levels of grayscale values, the threshold method can be used to obtain a comparative segmentation effect. If the difference between the object and the background is not expressed in the grayscale value (such as different textures), this difference feature can be converted into a grayscale difference, and then the threshold selection technology can be used to segment the image. Dynamically adjusting the threshold to achieve image binarization allows dynamic observation of the specific results of image segmentation.
[0054] Since there are many noise points in the binarized image, similar to salt and pepper noise, after obtaining the second candidate image, it is necessary to use median filtering on the second candidate image to remove smaller noise points and obtain the image after median filtering. Use g3 (x, y) to represent the image after median filtering. The use of median filtering includes g3 (x, y) = M (g2 (x, y)), where M is the median filtering operation. Median filtering is a nonlinear smoothing technique that sets the gray value of each pixel point to the median value of all pixel points in a neighborhood window of the point. Median filtering is a nonlinear signal processing technique based on sorting statistics theory that can effectively suppress noise. The basic principle of median filtering is to replace the value of a point in a digital image or digital sequence with the median value of each point in a neighborhood of the point, so that the surrounding pixel values are close to the true value, thereby eliminating isolated noise points.
[0055] According to the median filter, the smaller noise points in the second candidate image are removed. According to the size characteristics of a single Xiling bottle, the noise with a connected domain area C_Aera less than 1000 is removed to reduce the misjudgment of the image. g4 is used to represent the preprocessed image to be detected. R is a denoising operation. The processed image to be detected g4 (x, y) is subjected to contour extraction to obtain a first image. At this time, the first image needs to be judged to see whether the extracted contour conforms to the morphological characteristics of the vial.
[0056] Step S103, extracting the contour of the first image based on the morphological features of the vial, to obtain a second image that meets the morphological features of the vial and a third image that does not meet the morphological features of the vial.
[0057] In one embodiment, a contour is extracted from a first image based on morphological features of a vial to obtain a second image that meets the morphological features of the vial and a third image that does not meet the morphological features of the vial, including: determining a minimum circumscribed rectangle of a connected domain of the vial image based on the morphological features of the vial; and judging the first image based on the minimum circumscribed rectangle of the connected domain of the vial image to obtain a second image and a third image.
[0058] In this embodiment, the minimum circumscribed rectangle Min_Rotate of the connected domain is obtained according to the morphological characteristics of the vial. By setting the minimum and maximum length and width (min_L, min_W, max_L, max_W), area (min_Aera, max_Aera), and other characteristics of the circumscribed rectangle, the second image is obtained. The second image is an image of the target material preliminarily screened out, and the second image includes all pixel sets of the image of the target material after the preliminarily screening. The second image is removed from the first image, and the remaining is the third image. Due to the influence of factors such as the incomplete luminescence of the vial surface and the poor consistency of the product, the connected domain of some single vials in the first image will be divided into multiple discontinuous connected domains. The lettuce does not conform to the third image of the morphological characteristics of the vial, so the third image needs to be debonded.
[0059] Step S104, performing de-adhesion processing on the third image based on a preset size kernel filter, extracting a contour of the de-adhesion processed third image based on the morphological features of the vial, and obtaining a fourth image that conforms to the morphological features of the vial.
[0060] The de-bonding process of step S104 is to perform targeted processing based on the ratio of the distance between the center points of the two connected domains to the diameter of the minimum circumscribed circle of the two connected domains. If the area where the background and the roller are adhered is relatively large, a large-size morphological opening operation is required. Otherwise, a small-size kernel can be set for the opening operation, and the contour is extracted based on the processing result.
[0061] Due to the incomplete luminescence of the surface of the vial, poor product consistency, and the inability to illuminate at certain angles of the surface of the vial, some connected areas of the rollers in the binary image g4 (x, y) will adhere to the background, which does not meet the judgment condition of step S103. Therefore, the third image needs to be de-adhesioned. The main processing process of de-adhesion is to perform targeted processing based on the adhesion ratio of the third image and the background pixels. If the area where the background and the roller are adhered is relatively large, a large size kernel is required for morphological opening operation. Otherwise, a small size kernel can be set for opening operation. The result of the processing is contour extracted, and the judgment condition of step S103 is repeated. The opening operation is mainly performed by first corroding the third image and then dilating it (it seems to separate the two slightly connected targets). The opening operation can remove isolated small dots and burrs, while the overall position and shape remain unchanged. The opening operation is a filter based on geometric operations. Different sizes of structural elements will lead to different filtering effects. The selection of different structural elements leads to different segmentation, that is, different features are extracted. This embodiment selects different preset size kernel filters according to different adhesion ratios, so as to extract the connected domain of the material image to the maximum extent.
[0062] Among them, the filter has a corresponding filter matrix and kernel function. The filter matrix is an n*n*m matrix with three dimensions of length, width and depth. Among them, the length and width are usually the same (both are n), which can be manually specified. The depth m of the filter matrix is the same as the depth of the image to be processed (the number of layers of the feature map feature map). If the image to be processed is a grayscale image and the number of layers of its feature map is 1, then m=1. If the image to be processed is an RGB color image and the number of layers of its feature map is 3, then m=3. Filtering is a neighborhood operation operator. When processing an image, given the image to be processed, the pixels in a small area of the image to be processed are weighted averaged to become each corresponding pixel in the output image, that is, the values of the pixels around the given pixel are used to determine the final output value of this pixel. For example, the mean filter replaces the original pixel value with the average value of the pixels around its pixel point. The kernel size of the filter is a numerical value used to limit the size of the area of the "domain", specifically the above-mentioned length*width (n*n). Commonly used kernel sizes are 3*3, 5*5, etc. The matrix elements of the filter matrix are the weights used in the weighted average calculation, which are defined by the kernel function calculation. Therefore, when specifying a filter, you only need to specify one parameter n, the kernel size.
[0063] In one embodiment, the third image is de-adhesion processed based on a preset size kernel filter, including: extracting the material contour from the third image based on the morphological features of the vial to obtain the first material image; determining the adhesion ratio of the first material image and background pixels, and extracting the material contour from the first material image according to the adhesion ratio, a preset adhesion threshold and a preset size kernel filter to complete the de-adhesion processing.
[0064] In this embodiment, the preset size kernel filter includes a first size kernel filter and a second size kernel filter, wherein the size of the operation kernel of the first size kernel filter is smaller than the size of the operation kernel of the second size kernel filter.
[0065] Specifically, the pixels of the first material image can be decomposed into two components, high frequency and low frequency. The frequency of the image is an indicator of the intensity of the grayscale change in the image, and is the gradient of the grayscale in the plane space. For the image, the edge part of the image is a sudden change part, which changes rapidly, so it is reflected in the frequency domain as a high-frequency component; the noise of the image is mostly a high-frequency part; the gently changing part of the image is a low-frequency component. The kernel size of the filter directly determines the separation effect and the clarity of the separated image. In theory, when there is a filter with a suitable kernel size, the illumination (oil light generated during the transmission process) in the image to be processed can be separated at one time to obtain an image without illumination. However, such a kernel size is usually very difficult to find, and a filter with a single kernel size often finds it difficult to achieve a good balance between the illumination removal effect and the image clarity. In order to solve the above problems, the embodiment of the present application uses two filters with different kernel sizes to process the image to be processed respectively.
[0066] The filter of the first kernel size is used to retain as many details as possible in the image to be processed at the expense of the illumination removal effect. The filter of the second kernel size is used to filter out as much illumination as possible in the image to be processed at the expense of image clarity. By selecting different preset kernel sizes according to different adhesion ratios, the filter corresponding to the first material image can be selected as much as possible according to the image illumination conditions.
[0067] In one embodiment, a material contour is extracted from a first material image according to an adhesion ratio, a preset adhesion threshold and a preset size kernel filter to obtain a second material image, including: when the adhesion ratio is less than the preset adhesion threshold, using a first size kernel filter to extract a material wheel from the first material image; when the adhesion ratio is not less than the preset adhesion threshold, using a second size kernel filter to extract a material contour image from the first material image.
[0068] In this embodiment, the computer device dynamically determines the first kernel size and the second kernel size of the filter according to the pixel size of the image to be processed. Alternatively, after the computer device converts the image to be processed into a preset standard size, it adopts a preset kernel size that is common to images of the standard size. In other words, images of different pixel sizes are preset with corresponding first and second kernel sizes. For example, when the bilateral filter is a Gaussian filter, the corresponding first kernel size can be 3, and the second kernel size can be 12; when the bilateral filter is a WLS filter, the corresponding first kernel size can be 0.6, and the second kernel size can be 10.
[0069] Optionally, the kernel size parameter of the first size kernel filter is selected as 3, and the kernel size of the second size kernel filter is selected as 3. The filtering formula of the specific preset size kernel filter is shown in formula (3):
[0070]
[0071] Among them, g5(g4(x,y),K) is an opening operation. K is the opening kernel size, and h2 is the adhesion threshold. g4(x,y) is the first material image, and g5(g4(x,y),K) is the image after the first material image is de-adhesion processed. For the g5(g4(x,y),K) image, the contour extraction operation needs to be performed again.
[0072] Step S105, correcting the second image and the fourth image according to the imaging characteristics of the vial to obtain a candidate vial image.
[0073] Since the material pixels screened out in step S105 still have the problem of background misjudgment, it is necessary to correct the second image and the fourth image according to the imaging characteristics of the material itself and the material distribution characteristics.
[0074] In one embodiment, the second image and the fourth image are corrected according to the imaging characteristics of the vial to obtain a candidate vial image, including: adjusting the brightness distribution of the second image and the fourth image according to the imaging characteristics of the vial to obtain the vial image with adjusted brightness distribution; and offsetting the vial image with adjusted brightness distribution according to a preset offset to obtain the candidate vial image.
[0075] In one embodiment, according to the imaging characteristics of the vial, the brightness distribution of the second image and the fourth image is adjusted to obtain the vial image with adjusted brightness distribution, including: acquiring the imaging characteristics of the material, adjusting the brightness distribution of the second image and the fourth image; and correcting the position of the material image in the adjusted second image so that the material image in the second image is in a horizontal position.
[0076] In one embodiment, the vial image after adjusting the brightness distribution is offset according to a preset offset to obtain a candidate vial image, including: extracting a single vial image of the vial image after adjusting the brightness distribution, extracting a minimum circumscribed rectangle of a connected domain of the single vial image, and offsetting the left boundary, right boundary, upper boundary, and lower boundary of the minimum circumscribed rectangle accordingly according to a preset boundary offset to obtain the candidate vial image.
[0077] The candidate vial image offset in this embodiment is to identify the image of the medicine powder that may be spilled into the vial image.
[0078] Step S106, extracting candidate vial images according to the powder imaging features to obtain a powder image corresponding to each vial, and when the powder image is smaller than a preset minimum powder image, determining that the vial corresponding to the powder image has a defect.
[0079] In one embodiment, candidate vial images are extracted based on powder imaging features to obtain a powder image corresponding to each vial, including: obtaining a preset powder grayscale threshold based on the powder imaging features; and binarizing the candidate vial images based on the powder grayscale threshold to obtain a powder image and a vial background image.
[0080] Since the bounding rectangle image after the offset is binarized, the grayscale threshold of the powder is low, so the background and the connected domain of the powder are separated. As shown in formula (4): where h is the set segmentation threshold, and g2(x, y) is the binarized image. Set the minimum height and minimum width of the powder. The height and width of the minimum rectangle of the binarized image should be higher than the set minimum height and minimum width, otherwise the product is considered unqualified.
[0081] Formula (4);
[0082] The powder image extracted in step S106 is an image of the powder in a single vial. Since there is a minimum powder filling standard in the vial, when the powder image is smaller than the preset minimum powder image, it can be determined that the vial has defects such as powder leakage or empty bottle.
[0083] After step S106, after the defects of a single vial are detected, the conveyor belt is controlled to move the vial, and the next vial is sent to the detection area, and steps S101 to S106 are repeated for detection. Finally, the vial is placed into different material baskets using a kicking mechanism according to the detection results.
[0084] like Figure 2 As shown, the second aspect of the present application provides a vial defect detection device based on image recognition, comprising:
[0085] The detection module 201 is used to identify the region of interest of the collected image and extract the image to be detected;
[0086] A first extraction module 202 is used to preprocess the image to be detected, extract the contour of the preprocessed image to be detected, and obtain a first image;
[0087] A second extraction module 203 is used to extract the contour of the first image based on the morphological features of the vial, so as to obtain a second image that meets the morphological features of the vial and a third image that does not meet the morphological features of the vial;
[0088] A third extraction module 204 is used to perform a de-adhesion process on the third image based on a preset size kernel filter, and extract a contour of the de-adhesion processed third image based on the morphological features of the vial to obtain a fourth image that meets the morphological features of the vial;
[0089] A correction module 205, configured to correct the second image and the fourth image according to the imaging characteristics of the vial to obtain a candidate vial image;
[0090] The defect inspection module 206 is used to extract the candidate vial images according to the powder imaging features to obtain the powder image corresponding to each vial, and when the powder image is smaller than a preset minimum powder image, determine that the vial corresponding to the powder image has a defect.
[0091] In one embodiment, the image to be detected is preprocessed, including: performing image enhancement operation on the image to be detected to obtain a first candidate image; performing binarization processing on the first candidate image to obtain a second candidate image; performing noise reduction processing on the second candidate image according to a median filtering operation and a size feature of a vial to obtain a preprocessed image to be detected.
[0092] In one embodiment, a contour is extracted from a first image based on morphological features of a vial to obtain a second image that meets the morphological features of the vial and a third image that does not meet the morphological features of the vial, including: determining a minimum circumscribed rectangle of a connected domain of the vial image based on the morphological features of the vial; and judging the first image based on the minimum circumscribed rectangle of the connected domain of the vial image to obtain a second image and a third image.
[0093] In one embodiment, the third image is de-adhesion processed based on a preset size kernel filter, including: extracting the material contour from the third image based on the morphological features of the vial to obtain the first material image and background pixels; determining the adhesion ratio of the first material image and the background pixels, and extracting the material contour from the first material image according to the adhesion ratio, a preset adhesion threshold and a preset size kernel filter.
[0094] In one embodiment, the preset size kernel filter includes a first size kernel filter and a second size kernel filter, wherein the size of the operation kernel of the first size kernel filter is smaller than the size of the operation kernel of the second size kernel filter.
[0095] In one embodiment, according to the imaging characteristics of the vial, the second image and the fourth image are corrected to obtain a candidate vial image, including: according to the imaging characteristics of the vial, adjusting the brightness distribution of the second image and the fourth image to obtain the vial image with adjusted brightness distribution; and offsetting the vial image with adjusted brightness distribution according to a preset offset to obtain the candidate vial image.
[0096] In one embodiment, candidate vial images are extracted based on powder imaging features to obtain a powder image corresponding to each vial, including: obtaining a preset powder grayscale threshold based on the powder imaging features; and binarizing the candidate vial images based on the powder grayscale threshold to obtain a powder image and a vial image.
[0097] The technical solution provided by the present application may include the following beneficial effects: First, the present application extracts an image to be detected by identifying a region of interest of a captured image; pre-processes the image to be detected, extracts a contour of the pre-processed image to be detected, and obtains a first image; extracts a contour from the first image based on the morphological features of the vial, and obtains a second image that meets the morphological features of the vial and a third image that does not meet the morphological features of the vial; de-adhesions the third image based on a preset size kernel filter, and extracts a contour from the de-adhesioned third image based on the morphological features of the vial, and obtains a fourth image that meets the morphological features of the vial; corrects the second image and the fourth image according to the imaging characteristics of the vial, and obtains a candidate vial image; the present application reduces misjudgment of vial images and improves the accuracy of identifying vials through multiple image processing processes of vial images.
[0098] In the second aspect, the method of the present application includes: extracting candidate vial images based on drug powder imaging features, obtaining a drug powder image corresponding to each vial, and determining that the vial corresponding to the drug powder image is defective when the drug powder image is smaller than a preset minimum drug powder image. The present application further separates the drug powder from the vial background based on the drug powder imaging features, and determines whether the vial is qualified by identifying the drug powder image.
[0099] Figure 3 It is a schematic diagram of the structure of an electronic device shown in an embodiment of the present application.
[0100] See also Figure 3 , the electronic device 300 includes a memory 310 and a processor 320.
[0101] The processor 320 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.
[0102] The memory 310 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage. Among them, ROM can store static data or instructions required by the processor 320 or other modules of the computer. The permanent storage device may be a readable and writable storage device. The permanent storage device may be a non-volatile storage device that does not lose the stored instructions and data even after the computer is powered off. In some embodiments, the permanent storage device uses a large-capacity storage device (such as a magnetic or optical disk, flash memory) as a permanent storage device. In some other embodiments, the permanent storage device may be a removable storage device (such as a floppy disk, optical drive). The system memory may be a readable and writable storage device or a volatile readable and writable storage device, such as a dynamic random access memory. The system memory may store some or all instructions and data required by the processor at run time. In addition, the memory 310 may include any combination of computer-readable storage media, including various types of semiconductor storage chips (such as DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and disks and / or optical disks may also be used. In some embodiments, the memory 310 may include a readable and / or writable removable storage device, such as a laser disc (CD), a read-only digital versatile disc (such as a DVD-ROM, a double-layer DVD-ROM), a read-only Blu-ray disc, an ultra-density optical disc, a flash memory card (such as an SD card, a mini SD card, a Micro-SD card, etc.), a magnetic floppy disk, etc. Computer-readable storage media do not include carrier waves and transient electronic signals transmitted wirelessly or wired.
[0103] The memory 310 stores executable codes, and when the executable codes are processed by the processor 320 , the processor 320 can execute part or all of the methods described above.
[0104] In addition, the method according to the present application may also be implemented as a computer program or a computer program product, which includes computer program code instructions for executing some or all of the steps in the above method of the present application.
[0105] Alternatively, the present application can also be implemented as a computer-readable storage medium (or non-transitory machine-readable storage medium or machine-readable storage medium) on which executable code (or computer program or computer instruction code) is stored. When the executable code (or computer program or computer instruction code) is executed by a processor of an electronic device (or server, etc.), the processor executes part or all of the steps of the above-mentioned method according to the present application.
[0106] The embodiments of the present application have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A method for detecting defects in vials based on image recognition, characterized in that: include: Identify the region of interest of the acquired image and extract the image to be detected; Preprocessing the image to be detected, extracting contours from the preprocessed image to be detected, and obtaining a first image; Extracting the contour of the first image based on the morphological features of the vial to obtain a second image that meets the morphological features of the vial and a third image that does not meet the morphological features of the vial; extracting the contour of the first image based on the morphological features of the vial to obtain a second image that meets the morphological features of the vial and a third image that does not meet the morphological features of the vial, including: determining the minimum circumscribed rectangle of a connected domain of the vial image based on the morphological features of the vial; judging the first image based on the minimum circumscribed rectangle of the connected domain of the vial image to obtain the second image and the third image; The third image is subjected to de-adhesion processing based on a preset size kernel filter, and the contour of the de-adhesion processed third image is extracted based on the morphological features of the vial to obtain a fourth image that conforms to the morphological features of the vial; the de-adhesion processing of the third image based on the preset size kernel filter includes: extracting the material contour from the third image based on the morphological features of the vial to obtain a first material image and background pixels; determining the adhesion ratio of the first material image and the background pixels, and extracting the material contour from the first material image according to the adhesion ratio, a preset adhesion threshold and the preset size kernel filter; the preset size kernel filter includes a first size kernel filter and a second size kernel filter, and when the adhesion ratio is less than the preset adhesion threshold, the first size kernel filter is used to extract the material contour from the first material image; when the adhesion ratio is not less than the preset adhesion threshold, the second size kernel filter is used to extract the material contour image from the first material image; According to the imaging characteristics of the vial, the brightness distribution of the second image and the fourth image is adjusted to obtain the vial image after the brightness distribution is adjusted; and the vial image after the brightness distribution is adjusted is offset according to a preset offset to obtain a candidate vial image; The candidate vial images are extracted according to the powder imaging features to obtain a powder image corresponding to each vial, and when the powder image is smaller than a preset minimum powder image, it is determined that the vial corresponding to the powder image is defective.
2. The method according to claim 1, characterized in that: The preprocessing of the image to be detected includes: Performing an image enhancement operation on the image to be detected to obtain a first candidate image; Binarizing the first candidate image to obtain a second candidate image; The second candidate image is subjected to noise reduction processing according to the median filtering operation and the size characteristics of the vial, so as to obtain the preprocessed image to be detected.
3. The method according to claim 1, characterized in that The size of the operation kernel of the first-size kernel filter is smaller than the size of the operation kernel of the second-size kernel filter.
4. The method according to claim 1, characterized in that: The step of extracting the candidate vial images according to the powder imaging features to obtain the powder image corresponding to each vial includes: According to the imaging characteristics of the powder, a preset powder gray threshold is obtained; The candidate vial image is binarized according to the medicine powder grayscale threshold to obtain a medicine powder image and a medicine bottle vial image.
5. A medical vial defect detection device, characterized in that: include: A detection module is used to identify the region of interest of the collected image and extract the image to be detected; A first extraction module is used to preprocess the image to be detected, extract the contour of the preprocessed image to be detected, and obtain a first image; A second extraction module is used to extract the contour of the first image based on the morphological features of the vial to obtain a second image that meets the morphological features of the vial and a third image that does not meet the morphological features of the vial; the extraction of the contour of the first image based on the morphological features of the vial to obtain the second image that meets the morphological features of the vial and the third image that does not meet the morphological features of the vial includes: determining the minimum circumscribed rectangle of the connected domain of the vial image based on the morphological features of the vial; judging the first image based on the minimum circumscribed rectangle of the connected domain of the vial image to obtain the second image and the third image; a third extraction module, configured to perform de-adhesion processing on the third image based on a preset size kernel filter, extract contours from the de-adhesion processed third image based on the morphological features of the vial, and obtain a fourth image that conforms to the morphological features of the vial; the de-adhesion processing on the third image based on the preset size kernel filter comprises: extracting material contours from the third image based on the morphological features of the vial to obtain a first material image and background pixels; determining an adhesion ratio between the first material image and the background pixels, and extracting material contours from the first material image according to the adhesion ratio, a preset adhesion threshold, and the preset size kernel filter; the preset size kernel filter comprises a first size kernel filter and a second size kernel filter, and when the adhesion ratio is less than the preset adhesion threshold, the first size kernel filter is used to extract material contours from the first material image; when the adhesion ratio is not less than the preset adhesion threshold, the second size kernel filter is used to extract material contour images from the first material image; A correction module, configured to adjust the brightness distribution of the second image and the fourth image according to the imaging characteristics of the vial, to obtain the vial image after the brightness distribution is adjusted; and to offset the vial image after the brightness distribution is adjusted according to a preset offset to obtain a candidate vial image; The defect inspection module is used to extract the candidate vial image according to the powder imaging feature to obtain the powder image corresponding to each vial, and when the powder image is smaller than a preset minimum powder image, determine that the vial corresponding to the powder image has a defect.
6. An electronic device, characterized in that: include: processor; as well as A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to execute the method according to any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that: An executable code is stored thereon, and when the executable code is executed by a processor of an electronic device, the processor is caused to execute the method according to any one of claims 1 to 4.
