A method for detecting surface defects of medicine capsules based on machine vision

CN122928820APending Publication Date: 2026-10-16TONGHUA JINHUI PHARMA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611146760.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-30
Publication Date
2026-10-16

AI Technical Summary

Technical Problem

若药物胶囊表面存在细小裂纹、针孔、凹陷、壳体局部薄弱、微破损或污染粘附等缺陷,可能导致内容物受潮、泄漏或外界污染进入药物胶囊内部

Benefits of technology

[0032] This invention discloses a machine vision-based method for detecting surface defects in drug capsules. First, it utilizes the transient response differences of the drug capsule shell material to trace amounts of moisture: the reflection change on an intact shell surface is relatively smooth and recovers quickly after micro-wetting excitation; cracks, pinholes, and weak areas of the shell will cause moisture retention, local darkening, or polarization reflection attenuation, and exhibit significant hysteresis during the recovery phase. By acquiring polarization image sequences before, during, and after excitation, defect retention response values ​​are constructed and located, effectively distinguishing real shell defects from static interference such as printed images, seams, and highlights. This allows for accurate identification of the normal structure of the drug capsule and significantly reduces the missed detection rate of real micro-defects on the drug capsule surface.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122928820A_ABST
    Figure CN122928820A_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of image processing, and more particularly to a medicine capsule surface defect detection method based on machine vision, which comprises the following steps: setting a medicine capsule surface polarization vision acquisition device, and wetting and exciting the medicine capsule to be detected; acquiring a polarization time sequence image of the medicine capsule surface through the polarization vision acquisition device, and pre-processing the polarization time sequence image; based on the polarization time sequence image of the medicine capsule surface, extracting a suspected defect candidate area, and correcting the suspected defect candidate area to obtain a real defect candidate area; reviewing the real defect candidate area to obtain a reviewed real defect candidate area, and outputting a detection result of the medicine capsule surface defect according to the defect retention response value and the reviewed real defect candidate area. The present application has the advantages of being able to accurately identify the normal structure of the medicine capsule, significantly reducing the missed detection rate of the real micro-defects on the surface of the medicine capsule, and the like.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image processing technology, and more particularly to a method for detecting defects on the surface of drug capsules based on machine vision. Background Technology

[0002] Drug capsules are typically made of gelatin, hydroxypropyl methylcellulose, or enteric-coated materials. Their outer shells have a certain degree of hygroscopicity and translucency, and their surface quality directly affects the drug's sealing performance, stability, and appearance compliance rate. If the surface of a drug capsule has defects such as fine cracks, pinholes, dents, localized thinness of the shell, micro-damage, or contamination adhesion, the contents may become damp, leak, or external contaminants may enter the capsule.

[0003] Current machine vision inspection typically acquires static images of drug capsules and then uses threshold segmentation, edge detection, or deep learning models to identify surface anomalies. However, drug capsules have normal visual structures such as curved highlights, two-color splicing, interlocking seams, printed images, and semi-transparent shells. Many microcracks and pinholes have extremely low contrast in static images, while printed images and interlocking seams tend to show strong edge responses. This makes it easy for static vision methods to miss real micro-defects and misdetect normal structures.

[0004] Therefore, accurately identifying the normal structure of drug capsules and reducing the missed detection rate of real micro-defects on the surface of drug capsules has become an urgent problem to be solved. Summary of the Invention

[0005] In view of this, embodiments of the present invention provide a machine vision-based method for detecting defects on the surface of drug capsules, in order to improve the above-mentioned problems in the prior art.

[0006] In a first aspect, embodiments of the present invention provide a machine vision-based method for detecting surface defects in drug capsules, the method comprising the following steps:

[0007] A polarization vision acquisition device is set up on the surface of a drug capsule, and a short-term controllable humidification excitation is performed on the drug capsule to be tested; the polarization time sequence image of the drug capsule surface is acquired by the polarization vision acquisition device, and the polarization time sequence image is preprocessed. The polarization time sequence image includes: a reference polarization time sequence image before excitation, a response polarization time sequence image after humidification excitation, and a recovery polarization time sequence image after short-term recovery.

[0008] Based on the polarization time-series image of the drug capsule surface, suspected defect candidate regions are extracted, and the suspected defect candidate regions are corrected to obtain the true defect candidate regions.

[0009] The actual defect candidate regions are reviewed to obtain the reviewed actual defect candidate regions. Based on the defect retention response value and the reviewed actual defect candidate regions, the detection results of the drug capsule surface defects are output.

[0010] Preferably, the preprocessing of the polarization time-series image includes:

[0011] The acquired polarization time-series images are preprocessed by white balance correction, geometric registration, and subject segmentation.

[0012] Preferably, the step of extracting potential defect candidate regions based on the polarization time-series image of the drug capsule surface, and correcting the potential defect candidate regions to obtain true defect candidate regions, includes:

[0013] Based on the polarization time-series image of the drug capsule surface, a net polarization response value is constructed. The net polarization response value is used to reduce the static interference of the drug capsule surface highlights on defect judgment.

[0014] Based on the net polarization response value, candidate regions for suspected defects are extracted;

[0015] By utilizing the non-moisture retention characteristics of the printed image and the seam image in the response polarization time sequence image, the suspected defect region is corrected to obtain the true defect candidate region.

[0016] Preferably, the step of constructing the net polarization response value based on the polarization time-series image of the drug capsule surface includes:

[0017] The polarization time-series image of the drug capsule surface is divided into a parallel polarization time-series image and a cross-polarization time-series image. Based on the brightness of the parallel polarization time-series image and the brightness of the cross-polarization time-series image, a net polarization response value is constructed.

[0018] Preferably, the parallel polarization timing image and the cross polarization timing image include:

[0019] The difference between the parallel polarization time series image and the cross polarization time series image is used to distinguish between the specular reflection on the surface of the drug capsule and the scattering response inside the drug capsule shell.

[0020] Preferably, the step of extracting candidate regions for suspected defects based on the net polarization response value includes:

[0021] Based on the polarization net response value, a wetting retention response value and a recovery residual amplitude are constructed. A defect retention response value is constructed using the wetting retention response value and the recovery residual amplitude. Based on the defect retention response value, a localized retention significance value is constructed. A suspected defect candidate region is extracted using the localized retention significance value.

[0022] Preferably, the locally standardized retention significance value includes:

[0023] Based on the local significant regions reflected by the local standardized retention significance value, the candidate regions of suspected defects are generated. The slender high-response regions are extracted as candidate regions of suspected defects such as cracks or scratches. The point-like high-response regions are extracted as candidate regions of suspected defects such as pinholes or discolored contamination. The sheet-like response regions are extracted as candidate regions of suspected defects such as depressions, thin shells or adhesive residues.

[0024] Preferably, the non-moisture retention characteristics of the printed image and the overlay seam image in the response polarization time-series image include:

[0025] When the printed image and the fitting seam image in the response polarization time series image are extracted as suspected defect candidate regions, the overlap ratio between any suspected defect connected region and the normal static structure region and the average defect retention response value of the suspected defect candidate region are obtained. Based on the overlap ratio and the average defect retention response value, the non-moisture retention characteristics of the printed image and the fitting seam image in the response polarization time series image are obtained.

[0026] Preferably, the correction of the suspected defective area includes:

[0027] When any of the suspected defect areas coincides with the printed image or the overlay seam image in the response polarization time sequence image, it is determined whether any of the suspected defect areas has a higher response value than the surrounding normal static structure area. If so, any of the suspected defect areas are retained; otherwise, any of the suspected defect areas are discarded.

[0028] Preferably, the step of reviewing the suspected defect candidate regions to obtain the true defect candidate regions includes:

[0029] A lightweight deep learning model is trained using specific training samples. The baseline polarization time series image before excitation, the response polarization time series image after wetting excitation, the recovered polarization time series image after recovery, and the defect retention response value corresponding to the suspected defect candidate region are jointly input into the lightweight deep learning model for verification to obtain the true defect candidate region.

[0030] In a second aspect, embodiments of the present invention provide a machine vision-based drug capsule surface defect detection system, which includes: a memory, a processor, and a computer program stored in the memory and running on the processor. When the processor runs the computer program, it implements the steps of a machine vision-based drug capsule surface defect detection method.

[0031] The beneficial effects of the embodiments of the present invention compared with the prior art are as follows:

[0032] This invention discloses a machine vision-based method for detecting surface defects in drug capsules. First, it utilizes the transient response differences of the drug capsule shell material to trace amounts of moisture: the reflection change on an intact shell surface is relatively smooth and recovers quickly after micro-wetting excitation; cracks, pinholes, and weak areas of the shell will cause moisture retention, local darkening, or polarization reflection attenuation, and exhibit significant hysteresis during the recovery phase. By acquiring polarization image sequences before, during, and after excitation, defect retention response values ​​are constructed and located, effectively distinguishing real shell defects from static interference such as printed images, seams, and highlights. This allows for accurate identification of the normal structure of the drug capsule and significantly reduces the missed detection rate of real micro-defects on the drug capsule surface. Attached Figure Description

[0033] To more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0034] Figure 1 This is a flowchart of a machine vision-based method for detecting surface defects in drug capsules, provided by an embodiment of the present invention. Detailed Implementation

[0035] Embodiments of this disclosure are described in detail below, with examples of these embodiments illustrated in the accompanying drawings. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain this disclosure, and should not be construed as limiting it.

[0036] It should be noted that the terms "first," "second," etc., used in this disclosure and the accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this disclosure described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure.

[0037] To illustrate the technical solution of the present invention, specific embodiments are described below.

[0038] See Figure 1 This is a flowchart of a method for detecting surface defects of drug capsules based on machine vision, as provided in Embodiment 1 of the present invention. Figure 1 As shown, the machine vision-based method for detecting defects on the surface of drug capsules may include the following steps:

[0039] Step S1: Set up a polarization vision acquisition device for the surface of the drug capsule and perform a wet excitation on the drug capsule to be tested; acquire a polarization time-series image of the surface of the drug capsule through the polarization vision acquisition device, and preprocess the polarization time-series image. The polarization time-series image includes: a reference polarization time-series image before excitation, a response polarization time-series image after wet excitation, and a recovered polarization time-series image after recovery.

[0040] Specifically, step S1 can be:

[0041] An industrial camera is installed above the capsule transport track as a polarization vision acquisition device for the drug capsule surface. A switchable polarizer or a polarized camera is installed in front of the lens of the industrial camera. A ring-shaped diffuse reflection light source is placed above or to the side of the capsule to provide stable illumination to the capsule surface. To reduce the interference of specular highlights on the curved surface of the capsule, a first polarizer is installed at the light source end and a second polarizer is installed at the lens end, enabling the system to acquire parallel polarization time-series images and cross-polarization time-series images. The parallel polarization time-series images mainly retain the specular reflection and specular highlight information of the capsule surface, while the cross-polarization time-series images mainly enhance the internal scattering of the shell and the true surface structure information.

[0042] A micro-water vapor jet unit or a constant humidity micro-airflow unit is placed in front of the industrial camera's acquisition area to apply a very short-duration, low-intensity humidification excitation to the capsule surface passing through the detection area. This humidification excitation is not intended to soak the capsule, but only to create a brief, thin, and rapidly volatile water vapor contact state on the capsule surface. The surface of an intact capsule shell is relatively continuous, and the optical changes after humidification are smooth in space; however, microcracks, pinholes, or weak areas of the shell will produce more obvious short-term darkening and recovery hysteresis due to capillary action, micro-indentation retention, or local material structure loosening.

[0043] Images of the same capsule are acquired sequentially in three stages: a reference polarization time-series image before excitation, a response polarization time-series image after humidification excitation, and a recovery polarization time-series image after recovery. Parallel polarization time-series images and cross-polarization time-series images are acquired in each stage, thus forming a polarization time-series image group. For high-speed production line scenarios, the camera and injection unit can be triggered by the encoder to enable the capsule to complete synchronous image acquisition at a fixed position.

[0044] The acquired polarization time-series images were preprocessed with white balance correction, geometric registration, and subject segmentation: First, the capsule subject mask was extracted and the background area was removed; then, pixel-level registration of the polarization time-series images before excitation, after excitation, and after recovery was completed according to the capsule outline and major axis direction to avoid subsequent differential errors caused by slight capsule movement; then, mild denoising was performed on each polarization time-series image to preserve the subtle response changes at microcracks and pinholes.

[0045] Through the above step S1, polarization time-series images of the same capsule before, after, and after excitation can be obtained, providing a data basis for subsequent analysis of the dynamic response of capsule surface defects.

[0046] Step S2: Based on the polarization time-series image of the drug capsule surface, extract the suspected defect candidate region, and correct the suspected defect candidate region to obtain the true defect candidate region.

[0047] The principle of step S2 is as follows: In ordinary static images, the color difference between tiny cracks, pinholes, and weak areas on the surface of a drug capsule and the background shell is usually very small. This is especially true when there are printed characters, seams, or curved highlights on the capsule surface, making the defect features easily overlooked. In step S2, the defect is not understood as "abnormal texture in a single frame," but rather as "shell areas exhibiting abnormal retention responses under short-term wetting excitation." While complete drug capsule shells, normal printed characters, and seam images show obvious edge or color differences in static images, they typically do not produce sustained local responses in images after wetting excitation. Real microcracks and pinholes, however, will exhibit more pronounced scattering changes in cross-polarized time-series images due to capillary adsorption in micro-slits, brief moisture retention, or loose local shell structures, and will maintain high retention during the recovery phase. Based on these characteristics, this step sequentially establishes polarization differential response, wetting retention response, and normal structure exclusion logic to extract real defect candidate regions on the drug capsule surface from dynamic optical changes.

[0048] The specific implementation steps for step S2 are as follows:

[0049] Step a: Based on the polarization time-series image of the drug capsule surface, construct the net polarization response value. Through the net polarization response value, reduce the static interference of the drug capsule surface highlights on defect judgment.

[0050] Step b: Based on the net polarization response value, extract the candidate regions for suspected defects;

[0051] Step c: Based on the non-moisture retention characteristics of the printed image and the seam image in the response polarization time series image, the suspected defect area is corrected to obtain the real defect candidate area.

[0052] The principle of step a: The surface of a drug capsule is usually an arc-shaped structure, and it is easy to see strip-shaped highlights under normal light. The highlight area may cover microcracks in a single frame image, or it may form a bright-dark boundary similar to a scratch. Therefore, the scheme in step a uses the difference between parallel polarization time series images and cross polarization time series images to distinguish between surface specular reflection and internal scattering response of the shell.

[0053] Let the brightness of the parallel polarization time series image at the t-th stage be... The brightness of the cross-polarization time series image is ,in This represents any pixel within the main body area of ​​the capsule. Indicates before moistening stimulation, Indicates that after moistening stimulation, This indicates the recovery phase.

[0054] The method for constructing the net polarization response value is as follows:

[0055] ,

[0056] in, Indicates the first stage pixels The net polarization response value; The brightness of the cross-polarized time-series image is better reflected in terms of the scattering inside the capsule shell and the fine surface structure. It represents the brightness of a parallel polarization time sequence image, which contains a lot of specular reflection and specular information; It is a very small positive number. + + The sum is not zero.

[0057] The method for constructing this net polarization response value can be understood as "the response ratio of the shell structure after removing strong reflections"; the capsule is curved, and directly observing the brightness can easily be misled by highlights; using this ratio, the highlight areas are suppressed because the parallel polarization component is strong; the scattering changes caused by cracks, pinholes, and weak areas are relatively preserved. If a certain location only has very strong highlights, then the parallel polarization brightness... It will be very large; the denominator It will also increase; at this point, even if there is some brightness in the cross-polarization time series image, the proportion will not be abnormally amplified. However, if a certain location is a crack, pinhole, or weak area in the shell, it causes internal scattering of the shell or changes in the surface structure, and these changes are more likely to be reflected in the cross-polarization component. Therefore, the position is... It will better reflect the true structural changes.

[0058] The corresponding physical principle is that specular reflection and shell scattering behave differently in the polarization channel. Highlights are more prominent in parallel polarization time-series images, while subtle changes in shell structure are more preserved in cross-polarization time-series images. Dividing the cross-polarization brightness by the total brightness of both can reduce the intensity of areas with high total brightness but mainly caused by reflection, while retaining responses caused by changes in shell structure. This reduces the interference of bright bands and highlight edges on the capsule's curved surface for defect detection, allowing subsequent judgments to focus more on changes in the drug capsule shell itself, thus obtaining the net polarization response value before excitation. Net polarization response value after excitation and the net polarization response value during the recovery phase .

[0059] The principle of step b is as follows: Real microcracks, pinholes, and weak areas on the surface of the drug capsule do not simply exhibit a darkening or brightening of brightness after short-term wetting stimulation; instead, they possess a dynamic characteristic of "enhanced response and delayed recovery." The moisture contact on the surface of an intact drug capsule shell is relatively uniform, and the changes during the recovery phase decrease rapidly. However, defective areas, due to gaps, micropores, local depressions, or material porosity, will retain moisture, maintaining a strong response during the recovery phase. Therefore, the scheme in step b constructs a wetting retention response value to identify areas on the drug capsule surface with defective physical properties.

[0060] Step b can be specifically described as follows:

[0061] First, the wetting retention response value is constructed. The method for constructing the wetting retention response value can be as follows:

[0062] ,

[0063] in, Represents pixels The wetting retention response value is used to reflect the amplitude of the change in polarization response relative to the reference state after wetting excitation, indicating whether the location is sensitive to trace amounts of water vapor. This represents the net polarization response value after excitation; This represents the net polarization response value before excitation. The surface of a complete drug capsule is relatively flat, and the change after being slightly affected by moisture is relatively uniform; the change in the wetting retention response value after the drug capsule surface becomes wet is not significant. However, cracks, pinholes, dents, and weak areas on the surface of the drug capsule shell easily absorb or retain moisture, and the change in the wetting retention response value after the drug capsule surface becomes wet is very obvious; the wetting retention response value... The larger the value, the more sensitive the location is to micro-moistening stimuli.

[0064] The meaning of constructing the wetting retention response value is as follows: if a certain position on the surface of the drug capsule does not change significantly before and after wetting, it represents the net polarization response value after excitation. and The net polarization response values ​​before excitation are very close, that is: the net polarization response values ​​after excitation are... and The difference between the net polarization response values ​​before excitation is small; if a certain location on the surface of the drug capsule is significantly affected by moisture, the net polarization response value after excitation after wetting will be much smaller. and The net polarization response values ​​before excitation vary greatly, while the net polarization response value after excitation at a certain location on the surface of the drug capsule is significantly different. and The difference between the net polarization response values ​​before excitation increases. The absolute value is used because the response directions of different defects may differ: some locations become darker and more scattering-enhanced after wetting; others become brighter. The technical solution of this invention only concerns the "magnitude of change," not the direction of change. The excitation in the above construction method is short-term, slight moisture contact; the optical responses of the actual defect area and the intact shell area differ after wetting. The difference before and after excitation can precisely extract this "change caused by excitation," while static printing, fixed color differences, etc., do not necessarily show the same strong change before and after excitation. The above method for constructing the wetting retention response value can transform inconspicuous microcracks and pinholes in ordinary static images into dynamic features with "significant changes before and after wetting."

[0065] Next, the residual amplitude is reconstructed. The method for constructing the residual amplitude is as follows:

[0066] ,

[0067] in, This represents the residual recovery amplitude, which reflects the response amplitude that is still retained relative to the baseline state during the recovery phase, indicating whether there is residual moisture or response hysteresis at that location. This represents the net polarization response value during the recovery phase. This represents the net polarization response value before excitation. If a suspected defect candidate region only exhibits ordinary surface reflection or normal illumination fluctuations, it indicates that the suspected defect candidate region is typically close to its pre-excitation state during the recovery phase, recovering the residual amplitude. The value is relatively small; if a suspected defect candidate area is a microcrack or pinhole, it indicates that the suspected defect candidate area has recovered its residual amplitude due to water vapor retention. Larger.

[0068] Formula meaning: Moisture on the surface of a normal, intact drug capsule evaporates quickly, and the recovery phase will approach the pre-excitation state, thus restoring the residual amplitude. Smaller; cracks, pinholes, dents, and weak areas can trap moisture or cause localized scattering to recover more slowly, thus reducing the residual amplitude. The impact of wetness on the surface of micro-defects is relatively large; even if highlights and ordinary shadows change briefly after wetting, they usually do not remain significantly residual during the recovery phase. The key to identifying true micro-defect areas is not "whether there is a change after wetting," but rather "whether the change recovers slowly." If only changes after wetting are considered, changes in the normal surface water film and highlights of some drug capsule shells may be misjudged. By incorporating recovery residue, the retention characteristics of cracks and pinholes on the surface of drug capsules can be better captured. Through the above technical solutions, it is possible to effectively distinguish between "brief optical disturbances" and "retention responses caused by true defects."

[0069] Then, the defect retention response value is constructed, and the method for constructing the defect retention response value is as follows:

[0070] ,

[0071] in, For pixels The defect retention response value; For pixels The wet retention response value; For pixels The residual amplitude of the recovery; The condition for constructing the defect retention response value is that a certain area changes after wetting excitation, and this change is retained during the recovery phase.

[0072] The meaning of constructing this defect retention response value: Real cracks, pinholes, and weak areas on the surface of the drug capsule: Significant changes occur after wetting, and residues remain after recovery. Therefore, the defect retention response value... Larger; ordinary highlight changes: there may be temporary changes, but the residue is small after recovery, therefore, the defect retention response value is relatively small. Not significant; random noise: there may be abnormal changes in a certain frame, but it does not have stable retention, therefore, the defective retention response value Not significant; normal printing: clearly visible in static conditions, but not necessarily exhibiting a sustained response to wetting stimuli, therefore, the defect retention response value... Not big.

[0073] The physical processes corresponding to defects on the surface of drug capsules are as follows: water vapor comes into contact with the defect area; the defect area is adsorbed, penetrated or retained due to microcracks, micropores or depressions; during the recovery stage, the defect area is still different from the normal shell; this is not a simple image difference, but a combination of "excitation response" and "recovery hysteresis" into a judgment index.

[0074] The beneficial effects of constructing defect retention response values: If a suspected defect candidate region is random noise, then the wet retention response value... Unstable and lacking persistence; if a suspected defect candidate region is a highlight or slight shadow, it may change after excitation, but disappears quickly during the recovery phase, thus recovering the residual amplitude. The defect retention response value is relatively small; if a suspected defect candidate area is a real crack, pinhole, or shell weakness, it will be sensitive to wetting excitation and exhibit retention during the recovery phase. The defect retention response value construction method transforms the defect from a static visual anomaly into a material response anomaly, which can be clearly distinguished from the conventional edges, textures, and colors of the drug capsule surface.

[0075] Subsequently, the defect retention response value was... Perform local adaptive saliency extraction for any pixel within the main region on the surface of the drug capsule. Take pixel points Neighboring areas with the same shell color The method for constructing locally standardized retention significance values ​​is as follows:

[0076] ,

[0077] in, Indicates the significant value of localized stagnation; Representing the neighborhood Inner pixel; This represents the median; Indicates the absolute deviation of the median. Represents pixels The defect retention response value, The reason for using the median and median absolute deviation is that the capsule surface itself may have gradient colors or local normal printing. Using robust statistics can reduce the impact of a small number of outliers on the local baseline.

[0078] The meaning behind constructing this locally standardized retention significance value is as follows: Different drug capsules have different colors, and even the brightness and wettability response benchmarks of the same drug capsule vary at different curved surface positions. Therefore, a single fixed threshold cannot be directly used to judge pixel points. Defect retention response value Is it abnormal? Representing the neighborhood Defect retention response value of an inner pixel. First, observe the normal retention level of the area surrounding the pixel; then, observe how much higher the pixel level is compared to the surrounding normal level; finally, normalize using the fluctuation level within the pixel's neighborhood. The median represents the typical level within the neighborhood, and MAD represents the normal fluctuation magnitude within the neighborhood.

[0079] The localized stagnation significance value This indicates "how anomalous this point is relative to the surrounding capsule shell"; if the entire capsule area has a slightly higher response due to color or surface curvature, but a particular pixel is not more prominent than its surrounding pixels, then the localized lag significance value is considered significant. Not significant; if a crack or pinhole location is significantly more confined than the surrounding intact shell, then the localized normalized confinement value is significant. The median and MAD are relatively large, allowing for a relatively stable assessment method to be used for drug capsule surfaces of different colors, batches, and curved surfaces. Defects on the drug capsule surface are usually localized anomalies rather than uniform variations across the entire surface; using a local neighborhood as a reference better aligns with the assessment method of "defects being abnormal relative to the surrounding drug capsule shell." The median and MAD are less susceptible to the influence of a few defect points than the mean and variance, making them more suitable for polarization time-series images of drug capsule surfaces containing markings, edges, and localized anomalies.

[0080] Based on the local standardized retention significance value The candidate regions for suspected defects generated from the reflected local salient areas are: slender high-response areas are extracted as candidate regions for water vapor retention characteristics of cracks or scratches; point-like high-response areas are extracted as candidate regions for water vapor retention characteristics of pinholes or discolored contamination; and sheet-like response areas are extracted as candidate regions for water vapor retention characteristics of depressions, thin shells, or adhering residues.

[0081] The principle of step c is as follows: The printed text and seams on the surface of the drug capsule are the most likely normal structures to be misjudged. In traditional static vision, the edges of the printed text and the shadows of the seams have strong edges, strong gray-scale differences, and relatively stable connected forms, which are easily misidentified as cracks or scratches. However, in the wetting excitation timing of the technical solution of this invention, although the normal printed text and seams on the surface of the drug capsule are very obvious in the reference polarization timing image, they usually do not have the water vapor retention response characteristics of real defects. Based on this characteristic, in the technical solution of step c, instead of simply shielding the printed text and seams, it is determined whether the polarization timing image of the normal printed text and seams has water vapor retention characteristics.

[0082] Step c is as follows:

[0083] First, extract the static structure region from the image before excitation. It includes the printed area, the narrow band of the seam, and the stable highlight band area.

[0084] Then, obtain any suspected defect candidate region. The method for obtaining the overlap ratio between the suspected defect candidate region and the normal static structure region is as follows:

[0085] ,

[0086] in, Indicates the first The overlap ratio between the suspected defect candidate region and the normal static structure region; Indicates the first One suspected defect candidate region; The static structural mask representing the printed text, overlay seam, and stable highlight; Indicates the first Area of ​​each suspected defective candidate region; This represents the area where a suspected defect candidate region falls within the static structure region.

[0087] Formula meaning: False positives are most likely to occur in printed text, seams, and highlights. Therefore, it is necessary to know how much of a suspected defect candidate area falls on these normal structures. The larger the overlap area, the more likely the suspected defect candidate area is caused by printed text, seams, or highlights; the smaller the overlap area, the more likely it is an abnormal area independent of normal structures. This indicates the degree of spatial overlap between a suspected area and the normal structure. If a suspected defect falls exactly on the edge of the printed text, it cannot be immediately identified as a crack; if a suspected defect extends along the seam, it may simply be a shadow of a normal seam; however, if it falls on the printed text or seam but still shows a significant moisture retention response, it may be a real defect superimposed on these locations. Capsule-shaped printed text and seams are normal structures, but they resemble defects in static images. The overlap ratio can be used to first identify "high-risk false positive areas," and then combined with the retention response to decide whether to retain them.

[0088] When the The overlap ratio between suspected defect candidate regions and normal static structure regions A higher value indicates that the suspected area may originate from printing or a seam. However, this solution does not directly delete the area, but instead further obtains the average defect retention response value of the suspected defect candidate area. The calculation method for the average defect retention response value of the suspected defect candidate area is as follows:

[0089]

[0090] in, Indicates the first The average defect retention response value of each suspected defect candidate region; Represents pixels This is a suspected defect candidate region. , Represents pixels The defect retention response value.

[0091] Formula meaning: Individual pixels may be affected by noise. Therefore, when judging a suspected defect candidate region, one cannot only look at the response value of a single point, but must consider the average retention level of the entire suspected defect candidate region. This average defect retention response value is calculated by averaging the defect retention response values ​​of all pixels within the suspected defect candidate region. Average defect retention response value of the suspected defect candidate region. This indicates whether the entire suspected defect candidate region exhibits overall retention characteristics. If a suspected defect candidate region is merely the edge of the printed text, only local pixels at the edge may change, but the overall retention is not significant. If a suspected defect candidate region is a real crack or pinhole, its corresponding suspected defect candidate region will typically exhibit a high overall retention response. If a suspected defect candidate region coincides with the printed text or seam, but the average defect retention response value of that suspected defect candidate region is... A significantly larger value indicates that the suspected defect candidate region may contain not only normal structures but also potentially real defects. Real defects are typically not single-point random variations but rather form continuous or concentrated responses within a connected region. The average defect persistence response value can reduce the influence of noise and more stably reflect whether defects within the suspected defect candidate region are real.

[0092] If a suspected defect candidate area coincides with the printed text or seam, but the average defect retention response value of the suspected defect candidate area is... If the response value is significantly higher than that of the surrounding normal static structural area, it indicates that there may be a crack penetrating the printed text, damage near the seam, cap cracking, or local pinholes at that location, and it should be retained. If the suspected defect candidate area only has a static edge but lacks a residual response, it should be rejected as normal printed text or normal seam. The innovation of this correction for suspected defect areas lies in the fact that it does not rely on the simple exclusion of "printed text areas are not detected," but allows real defects to be identified even when superimposed on the printed text or seam, avoiding missed detections due to the shielding of normal structures.

[0093] In the three progressive steps a, b, and c above, the polarization net response is first used to strip the highlights on the curved surface, then the wet retention response is used to capture the material response features of microcracks and pinholes, and finally, the non-moisture retention characteristics of the printed image and the fitting seam image are used to eliminate the situation where the printed image and the fitting seam are mistakenly detected as defects on the surface of the drug capsule, thereby obtaining the true defect candidate region on the surface of the drug capsule.

[0094] Step S3: Verify the real defect candidate region to obtain the verified real defect candidate region. Based on the defect retention response value and the verified real defect candidate region, output the detection result of the surface defect of the drug capsule.

[0095] Specifically, step S3 can be:

[0096] Based on the obtained defect retention response value and the actual defect candidate region, the defects on the surface of the drug capsule are finally confirmed and output.

[0097] Connectivity merging, boundary refinement, and area filtering are performed on candidate regions for real defects. For elongated regions, their length, width, and directional continuity are calculated to identify cracks or scratches; for point-like regions, their area, roundness, and retention response peak are calculated to identify pinholes, discolored spots, or contamination; for sheet-like regions, the response distribution is combined to identify dents, thin shells, or adhesive residues.

[0098] The baseline polarization time-series image before excitation, the response polarization time-series image after wet excitation, the recovered polarization time-series image after recovery, and the defect retention response value corresponding to the candidate region are jointly input into a lightweight deep learning model for verification. The input of this lightweight deep learning model is not an ordinary single-frame image, but a multi-channel image patch containing dynamic information of "before excitation - after excitation - after recovery". Therefore, the lightweight deep learning model can learn the response process of defects, rather than just learning static textures. The training samples of this lightweight deep learning model include samples of categories such as normal printing, normal overlay seams, ordinary highlights, real cracks, pinholes, broken edges, dents, and contamination residues.

[0099] For areas verified as genuine defects, the system outputs the defect category, defect location, defect area, retention response intensity, and defect confidence level. For defects affecting capsule sealing, such as cracks, pinholes, broken edges, thin shells, and broken fitting seams, the capsule is directly deemed unqualified. For minor scratches or surface contamination, a grade can be output according to production quality standards, and the capsule can be rejected or re-inspected.

[0100] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.

Claims

1. A method for detecting surface defects of drug capsules based on machine vision, characterized in that, The machine vision-based method for detecting defects on the surface of drug capsules includes the following steps: A polarization vision acquisition device is set up on the surface of a drug capsule, and the drug capsule to be tested is subjected to a wet excitation. The polarization time sequence image of the drug capsule surface is acquired by the polarization vision acquisition device, and the polarization time sequence image is preprocessed. The polarization time sequence image includes: a reference polarization time sequence image before excitation, a response polarization time sequence image after wet excitation, and a recovered polarization time sequence image after recovery. Based on the polarization time-series image of the drug capsule surface, suspected defect candidate regions are extracted, and the suspected defect candidate regions are corrected to obtain the true defect candidate regions. The actual defect candidate regions are reviewed to obtain the reviewed actual defect candidate regions. Based on the defect retention response value and the reviewed actual defect candidate regions, the detection results of the drug capsule surface defects are output.

2. The method for detecting surface defects of drug capsules based on machine vision according to claim 1, characterized in that, The preprocessing of the polarization time-series image includes: The acquired polarization time-series images are preprocessed by white balance correction, geometric registration, and subject segmentation.

3. The method for detecting surface defects of drug capsules based on machine vision according to claim 1, characterized in that, The step of extracting potential defect candidate regions based on the polarization time-series image of the drug capsule surface, and correcting the potential defect candidate regions to obtain true defect candidate regions, includes: Based on the polarization time-series image of the drug capsule surface, a net polarization response value is constructed. The net polarization response value is used to reduce the static interference of the drug capsule surface highlights on defect judgment. Based on the net polarization response value, candidate regions for suspected defects are extracted; By utilizing the non-moisture retention characteristics of the printed image and the seam image in the response polarization time sequence image, the suspected defect region is corrected to obtain the true defect candidate region.

4. The method for detecting surface defects of drug capsules based on machine vision according to claim 3, characterized in that, The construction of the net polarization response value based on the polarization time-series image of the drug capsule surface includes: The polarization time-series image of the drug capsule surface is divided into a parallel polarization time-series image and a cross-polarization time-series image. Based on the brightness of the parallel polarization time-series image and the brightness of the cross-polarization time-series image, a net polarization response value is constructed.

5. The method for detecting surface defects of drug capsules based on machine vision according to claim 4, characterized in that, The parallel polarization timing image and the cross polarization timing image include: The difference between the parallel polarization time series image and the cross polarization time series image is used to distinguish between the specular reflection on the surface of the drug capsule and the scattering response inside the drug capsule shell.

6. The method for detecting surface defects of drug capsules based on machine vision according to claim 3, characterized in that, The step of extracting candidate regions for suspected defects based on the net polarization response value includes: Based on the polarization net response value, a wetting retention response value and a recovery residual amplitude are constructed. A defect retention response value is constructed using the wetting retention response value and the recovery residual amplitude. Based on the defect retention response value, a localized retention significance value is constructed. A suspected defect candidate region is extracted using the localized retention significance value.

7. The method for detecting surface defects of drug capsules based on machine vision according to claim 6, characterized in that, The locally standardized retention significance values ​​include: Based on the local significant regions reflected by the local standardized retention significance value, the candidate regions of suspected defects are generated. The slender high-response regions are extracted as candidate regions of suspected defects such as cracks or scratches. The point-like high-response regions are extracted as candidate regions of suspected defects such as pinholes or discolored contamination. The sheet-like response regions are extracted as candidate regions of suspected defects such as depressions, thin shells or adhesive residues.

8. The method for detecting surface defects of drug capsules based on machine vision according to claim 3, characterized in that, The non-moisture retention characteristics of the printed image and the overlay seam image in the response polarization time series image include: When the printed image and the fitting seam image in the response polarization time series image are extracted as suspected defect candidate regions, the overlap ratio between any suspected defect connected region and the normal static structure region and the average defect retention response value of the suspected defect candidate region are obtained. Based on the overlap ratio and the average defect retention response value, the non-moisture retention characteristics of the printed image and the fitting seam image in the response polarization time series image are obtained.

9. The method for detecting surface defects of drug capsules based on machine vision according to claim 8, characterized in that, The correction of the suspected defective area includes: When any of the suspected defect areas coincides with the printed image or the overlay seam image in the response polarization time sequence image, it is determined whether any of the suspected defect areas has a higher response value than the surrounding normal static structure area. If so, any of the suspected defect areas are retained; otherwise, any of the suspected defect areas are discarded.

10. The method for detecting surface defects of drug capsules based on machine vision according to claim 1, characterized in that, The step of reviewing the suspected defect candidate regions to obtain the actual defect candidate regions includes: A lightweight deep learning model is trained using specific training samples. The baseline polarization time series image before excitation, the response polarization time series image after wetting excitation, the recovered polarization time series image after recovery, and the defect retention response value corresponding to the suspected defect candidate region are jointly input into the lightweight deep learning model for verification to obtain the true defect candidate region.