Health care capsule product foreign matter detection method and system

By employing a multimodal technology collaboration and data-driven decision-making approach, combined with surface image analysis and near-infrared spectroscopy, the challenge of identifying complex foreign objects in the production of health capsules was solved. This approach enabled the accurate detection of metal fragments and plant fiber entanglements, improving the sensitivity and accuracy of the detection.

CN121114039BActive Publication Date: 2026-02-17SHAANXI HEMING HEALTH TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511657362.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-11-13
Publication Date
2026-02-17
Estimated Expiration
2045-11-13

AI Technical Summary

Technical Problem

Existing technologies struggle to effectively identify complex foreign matter in the production of health capsules, especially complex foreign matter formed by the entanglement of metal fragments and plant fibers. This results in insufficient detection sensitivity and poor identification accuracy, and a lack of adaptive adjustment capabilities.

Method used

A multimodal technology collaboration and data-driven decision-making approach is adopted, which combines surface image analysis and near-infrared spectroscopy to obtain multi-source information for the accurate identification of complex foreign objects, including surface localization, extraction of internal physical properties and identification of chemical composition.

Benefits of technology

It enables precise identification of complex foreign objects, improves the sensitivity and accuracy of detection, and ensures the comprehensiveness and reliability of the determination of harmful foreign objects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121114039B_ABST
    Figure CN121114039B_ABST
Patent Text Reader

Abstract

The application provides a foreign matter detection method and system for health capsule products, and relates to the technical field of health foods.The method comprises the following steps: acquiring a surface image of a health capsule; defining a reference sample area in the surface image; performing image feature analysis on the reference sample area to extract a reference feature set; obtaining an image processing sensitivity coefficient according to the relative deviation value of the reference feature set and a preset standard feature; obtaining optimized detection parameters based on the image processing sensitivity coefficient; and processing the surface image by using the optimized detection parameters to obtain surface foreign matter positioning data containing geometric coordinates.The application realizes the whole process detection from surface positioning, internal physical property extraction to chemical component identification through multi-modal technology cooperation and data-driven decision-making, and finally completes the accurate identification of composite foreign matters through multi-source information fusion.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of health food technology, and in particular to a method and system for detecting foreign matter in health capsule products. Background Technology

[0002] Foreign matter contamination is a key factor affecting product safety during the production of health capsules. Among these, complex foreign matter formed by the entanglement of metal fragments from equipment wear and tear with plant fibers mixed in with raw materials is one of the most difficult to detect and poses the highest risk due to its complex physical structure and diverse composition. Currently, the industry commonly employs detection technologies such as machine vision, X-ray transmission, and near-infrared spectroscopy, deployed in series or independently on production lines. However, these technologies have significant limitations in data processing, potentially leading to poor identification of complex foreign matter.

[0003] First, the existing system suffers from data silos, with data generated by each detection module being independent and lacking effective correlation. For example, information on the location of surface anomalies detected by the machine vision system cannot be used to guide the X-ray system to perform targeted scanning of specific areas, which may lead to insufficient sensitivity in detecting tiny foreign objects inside.

[0004] Secondly, the reliance on a single feature for judgment limits the accuracy of identification. X-ray systems rely solely on density features for judgment and cannot distinguish between isolated mineral crystals, metals, and fibrous complexes. Furthermore, the lack of a mechanism in the data processing flow to cross-modal correlate physical density features with chemical composition features makes it impossible for the system to recognize the crucial composite feature of spatial coexistence.

[0005] Finally, linear decision-making logic may lead to insufficient system flexibility. The results of previous detections cannot dynamically optimize the parameter settings and judgment thresholds of subsequent modules. The entire data processing flow lacks adaptive adjustment capabilities and is difficult to cope with complex and ever-changing foreign object forms. Summary of the Invention

[0006] The technical problem to be solved by the present invention is to provide a method and system for detecting foreign objects in health capsule products. Through multimodal technology collaboration and data-driven decision-making, the method and system can realize the detection of the entire process from surface positioning and extraction of internal physical properties to identification of chemical components. Finally, the method and system can achieve accurate identification of complex foreign objects through multi-source information fusion.

[0007] To solve the above-mentioned technical problems, the technical solution of the present invention is as follows:

[0008] Firstly, a method for detecting foreign objects in health capsule products, the method comprising:

[0009] Acquire a surface image of the health capsule; delineate a reference sample region in the surface image; perform image feature analysis on the reference sample region to extract its baseline feature set; obtain the image processing sensitivity coefficient based on the relative deviation between the baseline feature set and the preset standard features; obtain optimized detection parameters based on the image processing sensitivity coefficient; process the surface image using the optimized detection parameters to obtain surface foreign object location data containing geometric coordinates.

[0010] Based on the geometric coordinates contained in the surface foreign object location data, the corresponding capsule is oriented and scanned to obtain a binarized projection image; high-density foreign object targets are separated from the binarized projection image, and internal foreign object characteristic data that characterizes its physical properties are extracted by contour tracking and geometric measurement of the high-density foreign object targets.

[0011] Based on the internal foreign matter characteristics data, near-infrared spectra of the foreign matter region inside the capsule were collected; feature analysis was performed on the near-infrared spectra to extract feature spectra; the feature spectra were compared with a preset standard spectral database to obtain foreign matter component identification data;

[0012] Based on surface foreign object location data, internal foreign object characteristic data, and foreign object component identification data, multi-source information matching is performed to obtain matching results. Based on the matching results, composite foreign object characteristics that simultaneously possess metallic properties and plant fiber components are identified, and the presence of harmful foreign objects is determined based on the composite foreign object characteristics.

[0013] Secondly, a foreign object detection system for health capsule products includes:

[0014] The surface foreign object detection module is used to acquire surface images of health capsules; delineate reference sample areas in the surface images; perform image feature analysis on the reference sample areas to extract their baseline feature set; obtain image processing sensitivity coefficients based on the relative deviation between the baseline feature set and preset standard features; obtain optimized detection parameters based on the image processing sensitivity coefficients; and process the surface image using the optimized detection parameters to obtain surface foreign object positioning data containing geometric coordinates.

[0015] The internal foreign object detection module is used to perform directional scanning on the corresponding capsule based on the geometric coordinates contained in the surface foreign object positioning data to obtain a binary projection image; high-density foreign object targets are separated from the binary projection image, and internal foreign object characteristic data characterizing their physical properties are extracted by contour tracking and geometric measurement of the high-density foreign object targets.

[0016] The component analysis module is used to collect near-infrared spectra of the foreign matter region inside the capsule based on the internal foreign matter characteristic data; perform feature analysis on the near-infrared spectra to extract feature spectra; and compare the feature spectra with a preset standard spectral database to obtain foreign matter component identification data.

[0017] The foreign object identification module is used to perform multi-source information matching based on surface foreign object location data, internal foreign object characteristic data, and foreign object component identification data to obtain matching results; based on the matching results, it identifies composite foreign object characteristics that simultaneously possess metallic properties and plant fiber components, and determines whether there are harmful foreign objects based on the composite foreign object characteristics.

[0018] Thirdly, a computing device includes:

[0019] One or more processors;

[0020] A storage device for storing one or more programs that, when executed by one or more processors, cause the one or more processors to implement the method.

[0021] Fourthly, a computer-readable storage medium storing a program that, when executed by a processor, implements the method.

[0022] The above-described solution of the present invention has at least the following beneficial effects:

[0023] After acquiring images of the capsule surface, a reference sample area is delineated to focus on the effective analysis area and reduce redundant data. Image feature analysis is performed on the reference sample area to extract a baseline feature set, which can capture the core features of the normal texture of the capsule surface. The image processing sensitivity coefficient is obtained based on the relative deviation between the baseline feature set and the preset standard features, achieving dynamic adaptation of detection sensitivity to the actual state of the capsule. Optimized detection parameters are obtained based on the sensitivity coefficient, making the parameter settings fit the specific image characteristics. Processing the surface image with the optimized detection parameters can enhance the suppression of interference by foreign object features, obtaining surface foreign object location data containing geometric coordinates, providing accurate location guidance for subsequent detection. Oriented scanning is performed based on the geometric coordinates of the surface foreign object location data, avoiding indiscriminate scanning of the entire area and reducing data processing volume. After obtaining the binarized projection image, high-density foreign object targets are separated, enabling targeted screening of high-risk foreign object candidates. Contour tracking and... Geometric measurements extract internal foreign object characteristic data, providing comprehensive information on the physical properties of foreign objects and offering physical characteristic support for component analysis. Near-infrared spectroscopy is acquired based on internal foreign object characteristic data, ensuring precise correlation between spectral acquisition and foreign object location, guaranteeing data relevance. Feature analysis of the near-infrared spectrum extracts characteristic spectra, effectively removing interfering information and preserving component characteristics. Comparison of the characteristic spectra with a pre-set standard spectral database yields foreign object component identification data, enabling chemical component identification and providing core component basis for foreign object type determination. Multi-source information matching is performed based on surface foreign object location data, internal foreign object characteristic data, and foreign object component identification data, achieving deep integration of surface location, physical properties, and chemical composition data to form a comprehensive judgment basis. Identification of composite foreign object characteristics based on matching results captures key features of coexisting metals and plant fibers. Combining composite foreign object characteristics to determine harmful foreign objects, multi-dimensional data collaborative verification ensures the comprehensiveness and reliability of harmful foreign object determination. Attached Figure Description

[0024] Figure 1 This is a schematic flowchart of a foreign matter detection method for health capsule products provided by an embodiment of the present invention.

[0025] Figure 2 This is a schematic diagram of a foreign object detection system for health capsule products provided in an embodiment of the present invention. Detailed Implementation

[0026] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.

[0027] like Figure 1 As shown, an embodiment of the present invention proposes a method for detecting foreign objects in health capsule products, the method comprising the following steps:

[0028] Step 100: Obtain a surface image of the health capsule; delineate a reference sample area in the surface image; perform image feature analysis on the reference sample area to extract its baseline feature set; obtain the image processing sensitivity coefficient based on the relative deviation between the baseline feature set and the preset standard features; obtain optimized detection parameters based on the image processing sensitivity coefficient; process the surface image using the optimized detection parameters to obtain surface foreign object positioning data containing geometric coordinates.

[0029] Step 200: Based on the geometric coordinates contained in the surface foreign object location data, perform directional scanning on the corresponding capsule to obtain a binarized projection image; separate the high-density foreign object target from the binarized projection image, and extract the internal foreign object characteristic data that characterizes its physical properties by performing contour tracking and geometric measurement on the high-density foreign object target.

[0030] Step 300: Based on the internal foreign matter characteristic data, collect the near-infrared spectrum of the foreign matter region inside the capsule; perform feature analysis on the near-infrared spectrum and extract the feature spectrum; compare the feature spectrum with the preset standard spectral database to obtain the foreign matter component identification data;

[0031] Step 400: Based on surface foreign object location data, internal foreign object characteristic data, and foreign object component identification data, perform multi-source information matching to obtain matching results; identify composite foreign object characteristics that simultaneously possess metallic properties and plant fiber components based on the matching results, and determine whether there are harmful foreign objects based on the composite foreign object characteristics.

[0032] In this embodiment of the invention, a reference sample region is defined for image feature analysis to extract a baseline feature set. The relative deviation between the baseline feature set and a preset standard feature is used to obtain an image processing sensitivity coefficient. Based on this coefficient, detection parameters are optimized to improve the targeting of surface image data processing, resulting in surface foreign object location data containing geometric coordinates. A binary projection image is obtained by directional scanning based on the geometric coordinates of the surface foreign object location data. By separating high-density foreign object targets and performing contour tracking and geometric measurement, the physical property data of internal foreign objects is extracted. Near-infrared spectra are collected based on the internal foreign object characteristic data, and feature spectra are extracted through feature analysis. These spectra are then compared with a preset standard spectral database to efficiently acquire foreign object component identification data. Finally, surface foreign object location data, internal foreign object characteristic data, and foreign object component identification data are integrated for multi-source information matching to identify composite foreign object characteristics, effectively determining harmful foreign objects.

[0033] In a preferred embodiment of the present invention, step 100 involves: acquiring a surface image of the health capsule; defining a reference sample region in the surface image; performing image feature analysis on the reference sample region to extract its baseline feature set; obtaining an image processing sensitivity coefficient based on the relative deviation between the baseline feature set and preset standard features; obtaining optimized detection parameters based on the image processing sensitivity coefficient; and processing the surface image using the optimized detection parameters to obtain surface foreign object location data containing geometric coordinates, including:

[0034] Step 101: Acquire a surface image of the health capsule and convert the surface image into a grayscale image. Specifically, this includes: capturing a surface image of the health capsule using an industrial camera with a resolution of at least 2 megapixels under diffuse light (illuminance of 500 to 800 lux). This image contains complete visual information of the capsule surface. Subsequently, a weighted average method is used to perform a grayscale conversion algorithm. Specifically, for each pixel in the color surface image, the grayscale values ​​of its red (R), green (G), and blue (B) channels are extracted, and the weighting coefficients are set to 0.299 (R channel), 0.587 (G channel), and 0.114 (B channel), respectively. The grayscale value of this pixel is the sum of the results of multiplying the red channel grayscale value by 0.299, the green channel grayscale value by 0.587, and the blue channel grayscale value by 0.114. This operation converts the color surface image into a single-channel grayscale image, reducing the image data dimension from 3 channels to 1 channel, while retaining core brightness features, providing basic data for subsequent targeted image analysis.

[0035] Step 102: Based on the grayscale image, the imaging area of ​​the capsule body is determined through edge detection and contour fitting. Based on the imaging area of ​​the capsule body, combined with the curvature distribution characteristics of the capsule surface and the evaluation of illumination uniformity, edges and reflective areas with optical interference are eliminated to obtain a candidate region set. According to the candidate region set, a statistically representative reference sample region is delineated in the central region with clear surface texture. Specifically, this includes: first, smoothing the grayscale image using a Gaussian filter with a standard deviation of 0.8 to 1.2 to suppress noise; then, calculating the gradient values ​​of the image in the x-direction (horizontal) and y-direction (vertical) respectively using a 3×3 Sobel operator. The gradient magnitude is the square root of the sum of the squares of the gradient values ​​in the x-direction and y-direction, and the gradient direction is the arctangent of the ratio of the gradient values ​​in the y-direction to the gradient values ​​in the x-direction; finally, performing non-maximum suppression using a 3×3 window to retain local maxima pixels in the gradient direction and eliminate non-edge pixels. Pixels; finally, initial dual thresholds are set, with a high threshold of 60 to 90 and a low threshold of 20 to 40. Pixels with gradient values ​​greater than the high threshold are marked as strong edges, and pixels between the high and low thresholds and connected to strong edges are marked as weak edges. The rest are non-edges, thus completing edge information extraction. The least squares contour fitting method is combined to determine the capsule's main imaging area. Specifically, the extracted edge pixels are used as samples, and an ellipse equation is used as the fitting model. In the ellipse equation, a is the major semi-axis and b is the minor semi-axis. The sum of squared residuals from each edge pixel to the ellipse is calculated. This sum of squared residuals is the sum of the squares of the x-coordinate of each edge pixel divided by the square of the major semi-axis, plus the square of the y-coordinate of the pixel divided by the square of the minor semi-axis, and then minus 1. By iteratively adjusting the major semi-axis, minor semi-axis, and the center coordinates of the ellipse, the sum of squared residuals is minimized. The area enclosed by the fitted ellipse is the capsule's main imaging area, and background interference outside the area is eliminated.

[0036] The curvature distribution characteristics are calculated based on the determined imaging region of the capsule body. Specifically, five consecutive edge pixels are taken as a group, and the tangent slope of two adjacent pixels is calculated. The first tangent slope is the difference between the y-coordinates of the second and first pixels, divided by the difference between the x-coordinates of the second and first pixels. The second tangent slope is the difference between the y-coordinates of the third and second pixels, divided by the difference between the x-coordinates of the third and second pixels. The curvature of this group of pixels is the absolute value of the difference between the two tangent slopes, divided by (1 plus the square of the first tangent slope) and (1 plus the square of the first tangent slope). The square root of the product of the squares of the slopes of the two tangents is multiplied by the arc length between adjacent pixels (taking the pixel spacing as 1). If the curvature is greater than the preset threshold (0.15), it is judged as an abnormal edge contour and is excluded. At the same time, an 8×8 sliding window is used to perform illumination uniformity evaluation on each region of the image. The gray-level variance in each window is calculated. The gray-level variance is the sum of the squares of the differences between the gray value of each pixel in the window and the gray mean value in the window, and then divided by the total number of pixels in the window (64). If the variance is greater than 200, it is judged as an uneven illumination region, including high brightness regions caused by reflection, and is excluded, resulting in a set of candidate regions without interference.

[0037] The central region with clear surface texture and no distortion is selected from the candidate regions and delineated as a reference sample region according to a preset size ratio, that is, 30% to 40% of the imaging area of ​​the capsule body, to ensure the accuracy of subsequent feature analysis.

[0038] Step 103: Based on the grayscale image data of the reference sample region, construct a grayscale co-occurrence matrix with a fixed pixel spacing; based on the grayscale co-occurrence matrix with a fixed pixel spacing, calculate the three second-order statistics of contrast, correlation, and entropy in each direction, specifically including: extracting the grayscale image data of the reference sample region, setting the fixed pixel spacing to 1 (i.e., adjacent pixels are spaced 1 pixel apart) and the grayscale level to 256 levels, constructing a grayscale co-occurrence matrix: counting the occurrence times of all pixel pairs (g1, g2) with a spacing of 1 pixel along a specified direction (initially 0°) within the reference sample region, where g1 and g2 are the grayscale values ​​(0 to 255) of the two pixels, forming a 256×256 grayscale co-occurrence matrix M, and then performing normalization processing on M, where the matrix element P(g1, g2) is the value of the corresponding element M(g1, g2) in the grayscale co-occurrence matrix divided by the total number of pixel pairs N that meet the spacing condition within the reference sample region.

[0039] Based on the normalized gray-level co-occurrence matrix, the following second-order statistics are calculated for the four directions of 0°, 45°, 90°, and 135°, respectively, in the following manner: Contrast: For all possible gray-level pairs (g1, g2) in the gray-level co-occurrence matrix, first calculate the difference between g1 and g2, then square the difference, and then multiply it by the probability value P(g1, g2) of this gray-level pair in the matrix. Finally, add all these product results together to obtain the contrast in that direction.

[0040] Correlation: First, based on the probability distribution of the gray-level co-occurrence matrix, calculate the mean of gray level g1 and the mean of gray level g2 respectively. The mean of gray level g1 is the sum of all g1 values ​​multiplied by their corresponding probabilities P(g1, g2), and the mean of gray level g2 is the sum of all g2 values ​​multiplied by their corresponding probabilities P(g1, g2). Next, for each gray level pair (g1, g2), calculate the difference between the mean of g1 and g1, and the difference between the mean of g2 and g2. Multiply these two differences by the probability P(g1, g2) of that gray level pair. (g2) and sum all these results to get a total; then, calculate the standard deviation of g1 and the standard deviation of g2 respectively. The standard deviation of g1 is based on the mean and probability of g1, and is obtained by summing the squared differences of each g1 with the mean multiplied by the corresponding probability, and then taking the square root. The standard deviation of g2 is based on the mean and probability of g2, and is obtained by summing the squared differences of each g2 with the mean multiplied by the corresponding probability, and then taking the square root. Multiply these two standard deviations to get a product; finally, divide the sum obtained above by this product to get the correlation in that direction.

[0041] Entropy: For all possible gray level pairs (g1, g2) in the gray-level co-occurrence matrix, first add 10 to the power of -6 to the probability value P(g1, g2) of the gray level pair (to avoid the logarithm calculation being meaningless when the probability is 0), then calculate the base-2 logarithm of this sum, and then multiply this logarithm by the original probability value P(g1, g2); then add all these products together, and finally take the negative value of this sum to obtain the entropy in that direction.

[0042] Step 104: Normalize the three second-order statistics—contrast, correlation, and entropy—in each direction to obtain normalized multi-directional texture features. Combine the normalized multi-directional texture features according to preset rules to form a benchmark feature set representing the normal texture state of the capsule surface. Specifically, this includes: First, the preset rule combination includes a min-max linear normalization correlation preset rule and a feature dimension alignment rule. The preset method for the min-max linear normalization correlation rule is as follows: Select capsules from different production batches and under different production environments. After manual comprehensive inspection to confirm that there are no foreign objects, no surface defects, and no texture abnormalities, a preset normal capsule sample set is formed. The number of samples is strictly controlled to be no less than 500 to ensure that the samples can cover the common variation range of normal capsule surface texture. For each capsule in this sample set, extract the contrast, correlation, and entropy features in the four directions of 0°, 45°, 90°, and 135° using the same method as in step 103.

[0043] For each feature in each direction, iterate through all samples to find the corresponding feature values, and statistically determine the minimum and maximum values ​​of that feature. These values ​​are then used as the minimum value C required for subsequent normalization calculations of that feature. min and maximum value C max The default method for feature dimension alignment rules is to select four directions—0°, 45°, 90°, and 135°—based on the spatial distribution characteristics of the capsule surface texture. These four directions can fully cover the main directions of the capsule surface texture, ensuring that no texture direction is missed. The direction order is arranged clockwise to ensure the consistency of feature integration. The feature arrangement order within each direction is set as contrast, correlation, and entropy. This order is based on the logical association of the three types of features to the texture representation, from the representation of texture brightness difference to the representation of pixel correlation degree and then to the representation of information complexity, forming an ordered feature description system.

[0044] The aforementioned pre-defined min-max linear normalization method is used to process the contrast, correlation, and entropy in each direction. Specifically, for a contrast feature in a certain direction, the minimum value C corresponding to that feature in the pre-defined normal capsule sample set is retrieved. min and maximum value C max The normalized contrast ratio is the current contrast ratio minus C. min The difference, divided by C max Subtract C min The difference; the normalization calculation method of correlation and entropy is the same as that of contrast. This operation eliminates the difference in dimensions between different statistics and obtains the normalized multi-directional texture features; according to the above-mentioned preset feature dimension alignment rules, the 12 normalized features in 4 directions are integrated into a 12-dimensional feature vector to form a benchmark feature set that can characterize the normal texture state of the capsule surface, providing a standard basis for subsequent anomaly judgment.

[0045] Step 105: Compare the baseline feature set with the preset normal capsule surface feature database item by item, and calculate the relative deviation value of each texture feature item; input the relative deviation value of each texture feature item into the pre-trained weight allocation model to obtain the dynamic weight coefficient corresponding to each deviation value. Specifically, this includes: comparing the constructed baseline feature set with the preset normal capsule surface feature database one by one, the database containing 12-dimensional standard feature vectors of no less than 1000 normal capsules, calculating the relative deviation value of each texture feature item. For the k-th feature item, k is 1 to 12, the relative deviation value is the absolute value of the difference between the current baseline feature value and the standard feature value divided by the standard feature value and then multiplied by 100%. The standard feature value is the mean of the feature item in the database. This calculation quantifies the degree of abnormality of the texture features.

[0046] The relative deviation values ​​of each texture feature item are input into the pre-trained weight allocation model. The model is constructed by first determining that the random forest algorithm is used as the core algorithm, and then preparing 1500 sets of training samples, which cover data of normal and abnormal capsules. Each set of samples contains the relative deviation values ​​of 12 feature items and manually labeled feature weights. When manually labeling the weights, the actual impact of different feature deviations on foreign object recognition is taken into account. Referring to the characteristics that contrast deviation has the strongest indication effect on the presence of foreign objects, followed by correlation deviation, and entropy deviation has the weakest, the weight coefficient range of each type of deviation is defined. That is, the weight coefficient range of contrast deviation is 0.6 to 0.8, correlation deviation is 0.3 to 0.5, entropy deviation is 0.1 to 0.3, and the overall weight coefficient range is controlled within 0.1 to 0.8.

[0047] The training process of the model involves dividing 1500 training samples into a training set and a validation set according to a preset ratio. The training set is used for model parameter learning, and the validation set is used for model performance evaluation. The feature deviation values ​​in the training set are used as input features, and the manually labeled feature weights are used as output labels. The random forest algorithm is used for model training. By iteratively adjusting model hyperparameters such as the number and depth of decision trees, the error between the model's predicted weights and the manually labeled weights is minimized. At the same time, the model's prediction accuracy is continuously evaluated using the validation set until the model's weight prediction error on the validation set reaches a preset standard, thus completing the training. The implementation process of this model is that after training, it has the ability to calculate the correlation between the input feature deviation values ​​and the probability of the presence of foreign objects, and then output dynamic weight coefficients that meet the requirements of the corresponding interval. After inputting the relative deviation values ​​of each texture feature item into the pre-trained model, the model calculates the correlation between the feature deviation values ​​and the probability of the presence of foreign objects, and outputs the dynamic weight coefficients corresponding to each deviation value, realizing the differentiated consideration of different feature deviations.

[0048] Step 106: Based on the relative deviation values ​​of each texture feature item and the corresponding dynamic weight coefficients, calculate the overall anomaly index through weighted fusion; input the overall anomaly index into a nonlinear mapping function to obtain the image processing sensitivity coefficient, specifically including: multiplying the relative deviation values ​​of each texture feature item with the corresponding dynamic weight coefficients, and then summing all the product results. The overall anomaly index is the sum of the results of multiplying the relative deviation values ​​of the 1st to 12th feature items by their respective weight coefficients.

[0049] The calculated overall anomaly index is input into a preset nonlinear mapping function. This index ranges from 0 to 100%. The nonlinear mapping function is an S-shaped function, whose core function is to nonlinearly transform the wide-ranging and linearly distributed overall anomaly index into an image processing sensitivity coefficient within the range of 0.3 to 0.9. This nonlinear transformation avoids abrupt changes in the sensitivity coefficient at extreme points in the anomaly index range, achieving a match between the anomaly level and processing sensitivity. Simultaneously, it makes the change in the sensitivity coefficient more closely reflect the actual image processing requirements for anomaly response. The formula is: ,in, This represents the overall anomaly index.

[0050] The image processing sensitivity coefficient generated by this function serves as the core basis for deriving and optimizing detection parameters in subsequent step 107. Specifically, it is used to derive the high threshold parameter, the corresponding low threshold parameter, and the gray-level similarity threshold required for region growing in Canny edge detection, providing quantitative support for the dynamic adjustment of subsequent image processing parameters. This function also converts the overall anomaly index into an image processing sensitivity coefficient in the range of 0.3 to 0.9, achieving a match between the degree of anomaly and the processing sensitivity.

[0051] Step 107: Based on the image processing sensitivity coefficient, derive the high threshold parameter for Canny edge detection through a preset first threshold mapping relationship; based on the high threshold parameter, derive the corresponding low threshold parameter through a preset proportional relationship; simultaneously, based on the image processing sensitivity coefficient, determine the gray-level similarity threshold required for region growth through a preset transformation relationship, specifically including: querying a preset first threshold mapping relationship table based on the image processing sensitivity coefficient. The preset method for this first threshold mapping relationship is to construct it through 120 sets of experimental data. The experiment selects multiple gradient values ​​of sensitivity coefficients in the range of 0.3 to 0.9, corresponding to the optimal value of the high threshold for Canny edge detection under different sensitivities, and determines the inverse correspondence between the sensitivity coefficient and the high threshold, that is, a sensitivity coefficient of 0.3 corresponds to a high threshold of 120, a sensitivity coefficient of 0.6 corresponds to a high threshold of 75, and a sensitivity coefficient of 0.9 corresponds to a high threshold of 30. For the intermediate value of the sensitivity coefficient between the above gradient values, calculate the corresponding high threshold by linear interpolation, and organize these correspondences into a preset first threshold mapping relationship table; derive the high threshold parameter required by the Canny edge detection algorithm through this mapping relationship.

[0052] Based on the derived high threshold parameters, the corresponding low threshold parameters are calculated and derived according to a preset fixed ratio. This fixed ratio is preset through extensive experimental verification, determining that a low threshold of 0.4 times the high threshold ensures both edge detection accuracy and edge integrity, avoiding missed weak edges. Therefore, this fixed ratio is set to guarantee the integrity of edge detection. Simultaneously, based on the image processing sensitivity coefficient, the gray-level similarity threshold required by the region growing algorithm is calculated using a preset linear transformation relationship. This linear transformation relationship is preset by setting a base value of 50 for the gray-level similarity threshold, combined with the region growing algorithm's requirement for identifying gray-level differences. It is then dynamically adjusted according to changes in the sensitivity coefficient, i.e., by linearly calculating 50 plus 50 multiplied by the sensitivity coefficient, the gray-level similarity threshold changes synchronously with the sensitivity coefficient, ensuring that the value range is controlled between 50 and 100, adapting to the region growing requirements under different anomaly levels. Therefore, this linear transformation relationship is preset to achieve adaptation of the detection parameters to the actual state of the capsule surface.

[0053] Step 108 involves configuring the high threshold parameter, low threshold parameter, and gray-level similarity threshold together to form optimized detection parameters. Specifically, this includes storing the derived Canny edge detection high threshold parameter, low threshold parameter, and gray-level similarity threshold required for region growing into the same parameter configuration file, and performing the association binding configuration: establishing a one-to-one correspondence between the sensitivity coefficient and the three threshold parameters in the configuration file, forming a parameter combination that includes the sensitivity coefficient, high threshold, low threshold, and gray-level similarity threshold, and integrating them into a unified parameter set, i.e., optimized detection parameters, to ensure that each parameter works synergistically in subsequent image processing.

[0054] Step 109: Perform multi-scale edge enhancement on the surface image based on the optimized detection parameters to obtain an intermediate image containing edge gradient information. Specifically, this includes: calling the optimized detection parameters to perform multi-scale edge enhancement processing on the original health capsule surface image. The specific calculation process is as follows: using three Gaussian kernels of different scales, namely, scale 1: 1×1 Gaussian kernel, standard deviation 0.8; scale 2: 3×3 Gaussian kernel, standard deviation 1.2; scale 3: 5×5 Gaussian kernel, standard deviation 1.6, convolution operations are performed on the original surface image to obtain smooth images of three scales; for each smooth image of scale, the gradient magnitude is calculated using the 3×3 Sobel operator to obtain gradient images of three scales; for each pixel in the image, the maximum gradient value of the pixel in the three scale gradient images is selected as the enhanced gradient value, replacing the original gradient value to form an intermediate image containing edge gradient information. This operation strengthens the edge gradient information of the foreign object and the capsule surface and suppresses irrelevant noise interference.

[0055] Step 110: Perform region growing processing based on the intermediate image to obtain preliminary foreign object candidate regions. Specifically, this includes: selecting initial seed points based on the intermediate image containing edge gradient information: selecting pixels with gradient values ​​greater than 80% of the Canny high threshold as initial seed points. For example, if the high threshold is 100, then the gradient value of the seed point is greater than or equal to 80. According to the preset region growing rules, 4-neighborhood growing is used, that is, judging the four adjacent pixels above, below, left, and right of the seed point, calculating the gray level difference between the adjacent pixels and the seed point. If the gray level difference is less than the optimized gray level similarity threshold, then the adjacent pixel is merged into the region where the seed point is located, and it is used as a new seed point to continue growing. Repeat the above growing process until there are no adjacent pixels that meet the conditions to be merged, to obtain preliminary foreign object candidate regions and achieve preliminary localization of foreign objects.

[0056] Step 111: Perform morphological closing operation on the foreign object candidate region to obtain a morphologically optimized binary image. Specifically, this includes: using a circular structuring element of a preset size (radius 2 pixels), performing morphological closing operation on the initially obtained foreign object candidate region: first, perform a dilation operation, sliding the circular structuring element on the foreign object candidate region, calculating the maximum gray value within the area covered by the structuring element, and replacing the gray value of the central pixel of the structuring element with this maximum gray value to fill the small gap of 1 to 2 pixels within the foreign object candidate region; then, perform an erosion operation, sliding the circular structuring element on the dilated region, calculating the minimum gray value within the area covered by the structuring element, and replacing the gray value of the central pixel of the structuring element with this minimum gray value to smooth the uneven parts of the region edge; through the combined operation of dilation and erosion, obtain a morphologically optimized binary image with complete shape and regular edges, with a foreground pixel gray value of 255 and a background pixel gray value of 0.

[0057] Step 112: Based on the morphologically optimized binary image, perform connected component analysis. Through contour extraction and geometric center calculation, obtain surface foreign object location data containing geometric coordinates. Specifically, this includes: Based on the morphologically optimized binary image, perform connected component analysis using a 4-neighborhood connected component labeling algorithm: Starting from the top-left pixel of the image, scan line by line. When encountering a pixel with a grayscale value of 255 that is unlabeled, assign it a new label number, incrementing from 1. Simultaneously, judge the 4 neighboring pixels of that pixel. If the neighboring pixels also have a grayscale value of 255 and are unlabeled, assign the same label number. Continue until all pixels in the connected component are labeled. Repeat this process for all pixels to complete connected component identification. Extract the contour information of each connected component using the chain code method: using the top-left image of the connected component... Starting from a single point, the contour pixels are tracked clockwise, recording the direction of each contour pixel relative to the previous pixel using an 8-direction chain code: 0 corresponds to right, 1 to upper right, 2 to top, 3 to upper left, 4 to left, 5 to lower left, 6 to bottom, and 7 to lower right. The geometric center coordinates of each contour region are calculated by summing the x and y coordinates of all pixels within the connected region. The average x-coordinate is the sum of the x-coordinates of all pixels within the region divided by the total number of pixels in the region, and the average y-coordinate is the sum of the y-coordinates of all pixels within the region divided by the total number of pixels in the region. This average value is the geometric center coordinate. The geometric center coordinates of all connected regions are integrated to form surface foreign object localization data containing geometric coordinates, providing location guidance for subsequent internal foreign object detection.

[0058] In this embodiment of the invention, the surface image is converted into a grayscale image to remove color redundancy and simplify the data dimension, providing an efficient processing foundation for subsequent image analysis. The imaging area of ​​the capsule body is locked by edge detection and contour fitting. Optical interference edges and reflective areas are eliminated by combining curvature distribution and illumination evaluation. Reference sample areas with clear surface texture and statistical representativeness are delineated from the candidate area set. A grayscale co-occurrence matrix with a fixed pixel spacing is constructed based on the grayscale data of the reference sample area. Contrast, correlation and entropy, three types of second-order statistics in each direction are extracted to fully capture the surface texture features. The second-order statistics in multiple directions are normalized to eliminate dimensional differences and combined according to preset rules to form a standardized benchmark feature set to characterize the normal texture state of the capsule surface.

[0059] The relative deviation value is calculated by comparing the benchmark feature set with the preset normal feature database item by item. A pre-trained weight allocation model is used to assign dynamic weight coefficients to each deviation value to achieve differentiated consideration of the deviation. The overall anomaly index is calculated by weighted fusion of the relative deviation value and the dynamic weight coefficients. The image processing sensitivity coefficient is obtained by transformation through a nonlinear mapping function to reasonably match the actual image processing needs. Based on the sensitivity coefficient, the high threshold of Canny edge detection is derived through a preset mapping relationship, and the low threshold is determined according to the proportional relationship. At the same time, the gray-level similarity threshold of region growth is determined through a preset transformation relationship to achieve targeted optimization of detection parameters. The high and low thresholds are associated with the gray-level similarity threshold to form highly adaptable optimized detection parameters, providing parameter support for subsequent image processing.

[0060] Multi-scale edge enhancement is performed on surface images based on optimized detection parameters to strengthen edge gradient information and clearly present surface details, thereby improving the foundation for foreign object recognition. Region growing is performed on intermediate images containing edge gradient information to efficiently screen out preliminary candidate regions for foreign objects, improving the initial efficiency of foreign object localization. Morphological closing operations are performed on the candidate regions to fill in the gaps between regions and smooth the edges, obtaining a morphologically optimized binary image, which improves the integrity and accuracy of the foreign object region. Connectivity analysis is performed on the morphologically optimized binary image, and surface foreign object localization data containing geometric coordinates is obtained through contour extraction and geometric center calculation, providing location information for subsequent foreign object detection.

[0061] In a preferred embodiment of the present invention, step 200 involves directional scanning of the corresponding capsule based on the geometric coordinates contained in the surface foreign object location data to obtain a binarized projection image; separating the high-density foreign object target from the binarized projection image; and extracting internal foreign object characteristic data representing its physical properties by contour tracking and geometric measurement of the high-density foreign object target, including:

[0062] Step 201: Based on the geometric coordinates contained in the surface foreign object location data, perform directional scanning on the corresponding capsule to obtain an X-ray attenuation image reflecting the internal material density distribution. Specifically, this includes: first, reading the surface foreign object location data and extracting the geometric center coordinates of each foreign object region, denoted as (x0, y0); setting the directional scanning range of the X-ray scanning system based on these geometric coordinates, defining a circular scanning area with a diameter of 2 to 3 mm centered on the geometric center coordinates to cover the possible internal extension area corresponding to the surface foreign object, avoiding indiscriminate scanning of the entire capsule area; adjusting the X-ray scanning system parameters to tube voltage of 40 to 60 kV, tube current of 0.5 to 1 mA, and scanning time of 0.2 to 0.5 s, and performing a scan on the directional area to collect the attenuation signal after X-rays penetrate the capsule; converting the attenuation signal into a grayscale image, where the grayscale value is positively correlated with the material attenuation coefficient, i.e., the larger the attenuation coefficient, the lower the grayscale value, forming an X-ray attenuation image that reflects the internal material density distribution of the capsule, thus realizing the correlation between the surface foreign object location data and the X-ray scanning data.

[0063] Step 202 involves performing threshold segmentation based on the maximum inter-class variance method on the X-ray attenuation image to obtain a binarized projection image. Specifically, this includes: after acquiring the X-ray attenuation image, determining the grayscale range of the image, i.e., 0 to 255; performing threshold segmentation using the maximum inter-class variance method, specifically as follows: traversing all possible grayscale thresholds T, i.e., from 0 to 255, dividing the image pixels into two categories: a background class with grayscale values ​​less than or equal to T, and a target class with grayscale values ​​greater than T; calculating the pixel count percentage w0 and average grayscale value u0 of the background class, and the pixel count percentage w1 and average grayscale value u1 (w0 + w1 = 1) of the target class; and calculating the inter-class variance σ. 2 =w0×w1×(u0-u1) 2 Recording the inter-class variance σ 2 The grayscale threshold T that reaches the maximum value max Use this threshold as the segmentation threshold; select X-ray attenuation images with gray values ​​less than or equal to T. max Set the pixel as the background, with a grayscale value of 255, and the grayscale value is greater than T. max The pixels are set as the target area with a grayscale value of 0, resulting in a binarized projected image, which enables automatic and accurate segmentation of regions with different densities.

[0064] Step 203: Perform connected component labeling processing on the binarized projection image to obtain a labeled image containing multiple independent regions; based on the labeled image, extract the morphological features of each independent region, including pixel area, circumscribed rectangle position, and centroid coordinates; according to the preset foreign object size range and spatial distribution constraints, filter the morphological features of each independent region to obtain candidate foreign object regions, specifically including: performing processing on the binarized projection image using an 8-neighbor connected component labeling algorithm: starting from the top left corner pixel of the image, scan line by line, when encountering a pixel with a gray value of 0 and no label, assign it a unique label number, with the label number incrementing from 1; at the same time, check the 8 neighboring pixels of the pixel, including the top, bottom, left, right and four diagonal directions, if the neighboring pixels also have a gray value of 0 and no label, assign the same label number, until all pixels in the connected region are labeled, forming a labeled image containing multiple independent regions.

[0065] Morphological features of each independent region are extracted based on the marked image: the total number of pixels with a gray value of 0 in each marked region is counted as the pixel area of ​​that region; the minimum bounding rectangle of each marked region is determined, and the position of the bounding rectangle is represented by the pixel coordinates of the upper left corner (x1, y1) and the pixel coordinates of the lower right corner (x2, y2); the average value of the x coordinates of all pixels in each marked region is calculated as the centroid x coordinate, and the average value of the y coordinates of all pixels is calculated as the centroid y coordinate; each independent region is screened according to the preset foreign object size range and spatial distribution constraints. The preset method for the foreign object size range is to collect common metal scraps, plant fibers and composite foreign object samples formed by their entanglement during the production process, obtain the binary projection image of the sample through the same X-ray scanning parameters as in step 201, count the pixel area distribution of each sample in the image, and determine that the range of 10 to 500 pixels can cover the pixel area of ​​most target foreign objects, while excluding small noise points below 10 pixels and non-foreign object impurities above 500 pixels. Therefore, this foreign object size range is preset.

[0066] The spatial distribution constraint is preset by selecting multiple capsule samples that have been manually verified to correspond to surface anomalies and internal foreign objects. The geometric center coordinates of the surface foreign objects are obtained through machine vision, and the centroid coordinates of the internal foreign object targets are obtained through X-ray scanning. The straight-line distance between the geometric center of the surface foreign object and the centroid of the internal foreign object in each sample is calculated. The maximum value of these distances is counted, and a threshold of 1.5 mm is determined to cover the positional deviation between the surface and internal foreign objects in normal production scenarios. This avoids the mistaken removal of truly associated foreign object areas due to excessive positional deviation. Therefore, this spatial distribution constraint is preset, that is, the straight-line distance between the centroid of an independent region and the geometric center coordinates of the surface foreign object does not exceed 1.5 mm. Areas that exceed the range or whose spatial positions do not match are removed to obtain candidate foreign object areas, reducing interference from non-target areas.

[0067] Step 204 involves a secondary screening of the candidate foreign object region based on a preset density threshold to separate high-density foreign object targets. Specifically, the preset density threshold Tden is determined by first collecting common metal debris samples from production equipment wear, covering different materials such as iron, copper, and stainless steel, as well as different particle sizes, to ensure the samples cover the types of metal foreign objects that may occur in actual production. Then, using the same X-ray scanning parameters as in step 201, these 100 groups of metal debris samples are scanned to obtain X-ray attenuation images for each group. Finally, these X-ray attenuation images undergo threshold segmentation processing based on the maximum inter-class variance method, consistent with step 202, to obtain various... The binarized projection image of the sample is used; the region corresponding to each metal debris sample is extracted from the binarized projection image, and the average gray value of all pixels in each region is calculated; the distribution of the average gray value of these 100 groups of metal debris samples is statistically analyzed, and the average gray value of non-target substances such as plant fiber in the capsule contents is compared with that of the sample. It is determined that the gray value range of 50 to 80 can effectively cover the average gray value of most metal debris samples, and the attenuation coefficient of the material in this range meets the high-density characteristics, which can be clearly distinguished from the low-density non-target substances; therefore, this gray value range is determined as the gray value threshold range corresponding to high-density foreign matter, and an appropriate value is selected from it as the preset density threshold Tden.

[0068] For each candidate foreign object region, the average gray value of all pixels within the region is calculated. This average gray value is then compared with a preset density threshold Tden. If the average gray value is less than or equal to Tden, it indicates that the region has a high material attenuation coefficient and high density, and the region is retained. If the average gray value is greater than Tden, it indicates that the region has low material density and may be capsule contents or plant fibers, and the region is removed. Through this secondary screening, high-density foreign object targets that match the density characteristics of metal debris are separated, thus overcoming the shortcomings of relying solely on a single density judgment.

[0069] Step 205: Perform morphological opening operation on the high-density foreign object target to obtain a denoised binary image; based on the denoised binary image, extract continuous contour point sets for each independent region; perform polygon approximation on the continuous contour point sets for each independent region to eliminate jagged edges and retain the main contour features to obtain contour data, specifically including: selecting a 3×3 square structuring element and performing morphological opening operation on the binary image corresponding to the high-density foreign object target: first, perform an erosion operation, slide the structuring element on the binary image; if all pixels in the area covered by the structuring element are grayscale values ​​of 0 (target area), then the center pixel of the structuring element is retained as 0, otherwise it is set to 255, removing small noise points in the target area, i.e., 1 to 2 pixels in size; then, perform a dilation operation, slide the structuring element on the eroded image; if there is at least one pixel with a grayscale value of 0 in the area covered by the structuring element, then the center pixel of the structuring element is set to 0, restoring the main shape of the target area, and obtaining a denoised binary image.

[0070] An edge tracking algorithm is used to extract continuous contour point sets of independent regions in the denoised binary image: starting from the pixel whose gray value changes from 255 to 0 on the region boundary, the algorithm moves clockwise along the boundary, recording the coordinates of each boundary pixel in turn, until returning to the starting point, forming a continuous contour point set; the Douglas-Puk algorithm is used to perform polygon approximation on the continuous contour point set: an approximation error threshold of 0.5 to 1 pixel is set, the start and end points of the contour are connected to form an initial line segment, and the point on the contour that is furthest from this line segment is found. If the distance is greater than the error threshold, the point is used as a split point, and the above operation is repeated for the two line segments respectively; if the distance is less than the error threshold, the point is deleted; this process is repeated until all line segments meet the error requirements, resulting in contour data composed of polylines, eliminating jagged edges and simplifying the data, while retaining the main contour features.

[0071] Step 206: Based on the contour data, calculate the geometric feature parameters of the high-density foreign object target and extract its centroid coordinates as the spatial location information of the foreign object, forming internal foreign object characteristic data representing its physical properties and spatial location. Specifically, this includes: calculating the geometric feature parameters of the high-density foreign object target based on the contour data: calculating the total length of the polylines in the contour data as the perimeter of the foreign object; calculating the pixel area of ​​the region enclosed by the contour, consistent with step 203, for verification; calculating the length of the major axis, the length of the minor axis, and the angle between the major axis and the horizontal direction of the contour using the minimum bounding rectangle algorithm, as the shape parameters of the foreign object, where the length of the major axis is the length of the longer side of the bounding rectangle, and the length of the minor axis is the length of the shorter side of the bounding rectangle; calculating the roundness of the contour, roundness = 4π × area / perimeter. 2The closer the value is to 1, the closer the shape is to a circle. Extract the centroid coordinates of the high-density foreign object target calculated in step 203 as the spatial location information of the foreign object. Integrate the above geometric feature parameters such as perimeter, area, major axis length, minor axis length, major axis angle, and circularity with the centroid coordinates to form internal foreign object characteristic data containing physical properties (shape, size) and spatial location, providing associated data for target area localization and multi-source information matching in subsequent near-infrared spectroscopy detection.

[0072] In this embodiment of the invention, directional scanning is performed based on the geometric coordinates of the surface foreign object location data to avoid indiscriminate scanning of the entire area and reduce redundant data generation; the acquired X-ray attenuation image can directly reflect the density distribution of the material inside the capsule, providing density dimension data support for subsequent separation of high-density foreign objects; threshold segmentation of the X-ray attenuation image is performed using the maximum inter-class variance method, which can automatically determine the optimal threshold for distinguishing different density regions, ensuring clear division of density difference regions in the binarized projection image, laying the foundation for subsequent independent region extraction; connected component labeling of the binarized projection image can distinguish multiple independent regions in the image; morphological features such as pixel area, bounding rectangle position, and centroid coordinates of each independent region are extracted, and candidate regions are screened in combination with preset foreign object size range and spatial distribution constraints, which can initially eliminate regions that do not conform to the morphological characteristics of foreign objects, reduce the amount of subsequent data processing, and improve processing efficiency; based on the preset density... A threshold is used to perform secondary screening of candidate foreign object regions, which can selectively retain high-density areas and effectively separate high-density foreign object targets that match the density characteristics of the target foreign object (such as metal debris), reducing the interference of non-target areas on subsequent processing. Morphological opening operations are performed on high-density foreign object targets to remove tiny noise points within the target area and optimize image quality. Extracting continuous contour point sets can completely preserve the contour information of high-density foreign object targets. By using polygon approximation processing to eliminate jagged edges of the contour, the main contour features are preserved while simplifying the contour data, providing a regular contour basis for subsequent geometric parameter calculations. The geometric feature parameters of high-density foreign object targets are calculated based on the contour data, which can obtain key information characterizing their physical properties. The centroid coordinates are extracted as the spatial location information of the foreign object, and the physical property data and spatial location data are integrated to form internal foreign object characteristic data, providing comprehensive and correlated data support for subsequent multi-source information matching.

[0073] In a preferred embodiment of the present invention, step 300 involves collecting the near-infrared spectrum of the foreign matter region inside the capsule based on the internal foreign matter characteristic data; performing feature analysis on the near-infrared spectrum to extract feature spectra; and comparing the feature spectra with a preset standard spectral database to obtain foreign matter component identification data, including:

[0074] Step 301: Based on the spatial location information of the foreign object contained in the internal foreign object characteristic data, perform fixed-point spectral acquisition on the corresponding region inside the capsule to obtain raw near-infrared spectral data. Specifically, this includes: first reading the internal foreign object characteristic data, extracting the centroid coordinates of the high-density foreign object target, denoted as (x... c y c This information serves as the spatial location information of the foreign object. Based on this information, the position of the sampling probe in the near-infrared spectroscopy acquisition system is adjusted so that the probe focus is aligned with a circular area 1 to 2 mm in diameter centered on the centroid coordinates. This covers the component distribution range that the high-density foreign object may extend into, avoiding indiscriminate spectral acquisition of non-foreign object areas inside the capsule. The near-infrared spectrometer parameters are set as follows: wavelength range 780 to 2500 nm, spectral resolution 8 cm⁻¹. -1 With an integration time of 300 to 500 ms and 32 scans, the spectral acquisition function is activated to collect the spectral signal of the fixed-point area. The collected spectral signal is converted into raw near-infrared spectral data with wavelength as the abscissa and absorbance as the ordinate, realizing the correlation between the physical location data of the internal foreign object and the near-infrared spectral data, providing a spectral basis for subsequent component analysis.

[0075] Step 302: Perform preprocessing on the raw near-infrared spectral data to obtain preprocessed spectral data. Specifically, this includes performing three levels of preprocessing on the raw near-infrared spectral data: The first level is smoothing, using an 11-point moving average method. Taking a certain wavelength point as the center, the absorbance values ​​of the five adjacent wavelength points to the left and right are taken, and the average value is calculated as the smoothed absorbance value of that wavelength point to eliminate random noise interference; The second level is baseline correction, using a polynomial fitting baseline method, selecting 3 to 5 wavelength bands in the spectrum without characteristic absorption, such as 780 to 800 nm. For the absorbance values ​​in the 2400 to 2500 nm wavelength range, a third-order polynomial fitting was performed to obtain the baseline curve. The baseline absorbance value for the corresponding wavelength was subtracted from the original absorbance value to eliminate the influence of baseline drift. The third stage was normalization processing, which used the standard normal variable transformation method to calculate the mean and standard deviation of the absorbance values ​​across the entire wavelength range. The absorbance value at each wavelength point was subtracted from the mean and then divided by the standard deviation to eliminate spectral interference caused by ambient light fluctuations and differences in capsule shell thickness, resulting in preprocessed spectral data that ensures the spectrum accurately reflects the chemical composition characteristics of the foreign substance.

[0076] Step 303: Based on the preprocessed spectral data, dimensionality reduction is performed using principal component analysis (PCA) while retaining a predetermined number of principal components to construct a feature vector characterizing the chemical composition of the foreign substance. Specifically, this includes: performing PCA dimensionality reduction on the preprocessed spectral data: First, the preprocessed spectral data is organized into a matrix, with rows representing wavelength points (2000 to 3000 in total) and columns representing spectral samples acquired in a single session; the matrix is ​​then centered, and the mean absorbance value for each wavelength point is calculated. The mean is then subtracted from the absorbance values ​​of all samples at that wavelength point to eliminate dimensional differences; based on the centered matrix… The covariance matrix is ​​calculated, and the eigenvalues ​​and corresponding eigenvectors of the covariance matrix are obtained. The eigenvalues ​​are sorted in descending order, and the variance contribution rate of each eigenvalue to the sum of the total eigenvalues ​​is calculated. The eigenvectors corresponding to the top n eigenvalues ​​with a cumulative variance contribution rate of 85% or more are selected as principal components, usually n=5 to 8. The preprocessed spectral data is linearly combined with the eigenvectors of these n principal components to obtain an n-dimensional vector. This vector is the feature vector characterizing the chemical composition of the foreign substance. This simplifies the data scale while retaining the key chemical information of the foreign substance and improves the efficiency of subsequent spectral comparison.

[0077] Step 304: The feature vector is compared with the spectral features of various substances stored in the preset standard spectral database. The similarity of the spectral features is then quantified by calculating the cosine similarity measure to obtain a similarity set with each standard substance. Based on this similarity set, a spectral matching index is obtained. Specifically, the preset standard spectral database is configured as follows: First, the types of target foreign matter-related substances to be stored in the standard spectral database are determined, including metal fragments, plant fibers, and capsule contents. The metal fragment samples cover common materials such as iron, copper, and stainless steel. Five to ten samples of different particle sizes are selected for each material to ensure coverage of metal foreign matter types that may be generated by equipment wear during production. The plant fiber samples cover common impurities in raw materials such as cotton, flax, and wood fiber. Five to ten samples of each type are selected to ensure coverage of plant fiber foreign matter from different sources. The capsule contents samples include powdered raw materials and excipients used in production. Three to five samples of each type are selected to distinguish foreign matter from normal contents. For all the above samples, fixed-point spectral acquisition is performed using the same near-infrared spectral acquisition parameters as in step 301 to obtain the raw near-infrared spectral data of each sample. The raw near-infrared spectral data is subjected to preprocessing operations that are completely consistent with step 302, including 11-point moving average smoothing, polynomial fitting baseline correction, and standard normal variable transformation normalization. Then, the preprocessed spectral data is subjected to principal component analysis dimensionality reduction processing in the same way as in step 303. The top n principal components with a cumulative variance contribution rate of more than 85% are selected to construct feature vectors to ensure that the feature vector dimensions of all standard substances are consistent. The material type label of each sample is associated with its corresponding feature vector and stored to form a preset standard spectral database.

[0078] The cosine similarity of the foreign object feature vector with the feature vector of each standard substance in the database is calculated one by one. The cosine value of the angle between the two vectors is calculated to quantify the similarity of the vector directions. The closer the value is to 1, the more similar the spectral features are. All the calculated cosine similarities are compiled into a list to form a similarity set with each standard substance. The spectral matching index is calculated based on this set, and the maximum value in the set is selected as the main matching index. At the same time, the standard substance type corresponding to the maximum value is recorded to provide a quantifiable comparison basis for the identification of foreign object components and realize cross-modal correlation between physical density features from X-rays and chemical composition features from near-infrared rays.

[0079] Step 305: Based on the spectral matching index, select standard substance types with similarity exceeding a preset threshold as identification results to obtain foreign substance component identification data for identifying the chemical composition of foreign objects. Specifically, this includes: setting a preset similarity threshold by conducting spectral comparison experiments on 100 groups of foreign object samples with known components, including metals, plant fibers, and composite foreign objects. The minimum cosine similarity at which correct identification is achieved is calculated and set as the preset threshold, typically between 0.85 and 0.9; comparing the spectral matching index with the preset threshold. If the index is greater than or equal to the threshold, the corresponding standard substance type is used as the preliminary identification result; if multiple standard substances have similarity indices exceeding the threshold, such as simultaneously detecting the spectral characteristics of metals and plant fibers, which conform to the characteristics of composite foreign objects, these standard substance types are all included in the identification results; and finally, organizing the identification results into structured data containing the main component types of foreign objects and the similarity indices of each component, which is the foreign substance component identification data.

[0080] In this embodiment of the invention, fixed-point spectral acquisition is performed based on the spatial location information of the foreign object in the internal foreign object characteristic data, eliminating the need for indiscriminate acquisition of the entire internal area of ​​the capsule and reducing the generation of redundant spectral data. Simultaneously, it can pinpoint the location of the foreign object, ensuring that the acquired raw near-infrared spectral data is directly correlated with the foreign object components, providing targeted data support for subsequent component analysis. Preprocessing the raw near-infrared spectral data eliminates baseline drift, noise interference, and ambient light effects, making the preprocessed spectral data more closely match the spectral characteristics of the true chemical components of the foreign object, laying a reliable data foundation for accurate analysis of the foreign object components. Principal component analysis (PCA) is used to reduce the dimensionality of the preprocessed spectral data, removing redundant dimensions and irrelevant information while retaining a predetermined number of principal components (covering key components). The chemical composition information simplifies the data scale while highlighting the core characteristics of the foreign object's chemical composition, improving the efficiency of subsequent feature comparison. By calculating the cosine similarity metric to quantify the similarity between the feature vector and the spectral characteristics of the standard substance, the spectral matching status of the two can be reflected. Item-by-item similarity calculation can comprehensively cover all kinds of substances in the preset standard spectral database. The resulting similarity set and spectral matching index provide a clear and quantifiable basis for subsequent component identification. Based on the spectral matching index and preset threshold to screen the type of standard substance, the judgment criteria for component identification can be clarified, ensuring the consistency and objectivity of the identification results. The obtained foreign object component identification data can clearly identify the chemical composition of the foreign object, providing key component dimension data support for subsequent multi-source information matching (combining surface positioning and internal physical properties).

[0081] In a preferred embodiment of the present invention, step 400 above involves performing multi-source information matching based on surface foreign object location data, internal foreign object characteristic data, and foreign object component identification data to obtain a matching result; identifying composite foreign object characteristics that simultaneously possess metallic properties and plant fiber components based on the matching result; and determining whether harmful foreign objects exist based on the composite foreign object characteristics, including:

[0082] Step 401: Based on the geometric coordinates in the surface foreign object location data and the spatial location information of the foreign object in the internal foreign object characteristic data, calculate the spatial distance between the surface anomaly area and the internal foreign object target; filter the spatial distance according to a preset spatial tolerance threshold to determine valid correlation pairs that satisfy the positional correspondence; based on the valid correlation pairs, obtain positional correlation information representing the spatial consistency between the surface and the internal foreign object, specifically including: firstly, reading the surface foreign object location data, extracting the geometric center coordinates of each surface anomaly area, denoted as (x... s y s ), and assign a unique identifier to each surface anomaly region, such as S1, S2, etc.; at the same time, read the internal foreign object characteristic data output in step 206, extract the centroid coordinates of each internal foreign object target, and denot them as (x i yi Similarly, each internal foreign object target is assigned a unique identifier, such as I1, I2, etc. For each surface anomalous area, such as S1, the spatial distance between it and all internal foreign objects, such as I1, I2, etc., is calculated in turn. The calculation method is to take the sum of the square of the difference between the coordinates of the two points in the x direction and the square of the difference in the y direction, and then take the square root of the sum to obtain the spatial distance between a single surface area and a single internal target.

[0083] The preset spatial tolerance threshold is set by first collecting 50 capsule samples that have been manually verified to have a correspondence between surface anomalies and internal composite foreign objects, ensuring that the samples cover different production batches and different foreign object distribution states; performing surface foreign object location detection in step 112 and internal foreign object characteristic data extraction in step 206 on these samples respectively, obtaining the geometric center coordinates of the surface anomaly area and the centroid coordinates of the internal foreign object target in each sample group; calculating the spatial distance between the two coordinates in each sample group, which is the positional deviation between the surface anomaly area and the corresponding internal foreign object target; statistically analyzing the positional deviation values ​​of all 50 samples, analyzing their distribution range, and considering factors such as the system error of the small displacement detection equipment during capsule transmission in the production process, determining that the maximum value of the positional deviation is usually between 0.8 and 1.2 mm; to ensure that no truly associated surface and internal foreign object pairs are missed, the maximum value of the statistically obtained positional deviation is set as the preset spatial tolerance threshold.

[0084] The calculated spatial distance is compared with a preset spatial tolerance threshold. If the distance is less than or equal to the threshold, the surface anomaly region and the internal foreign object target are determined to be a valid association pair; if the distance is greater than the threshold, they are discarded. All valid association pairs are organized into structured data, including the surface anomaly region identifier and the surface geometric coordinates (x, y, y). s y s ), internal foreign object target identifier, internal spatial coordinates (x) i y i The spatial distance and other spatial relationships are used to form positional correlation information that characterizes the consistency between the surface and the internal foreign object space, thereby realizing the effective correlation between surface and internal detection data.

[0085] Step 402: Based on the positional association information representing the consistency between the surface and the internal foreign object space, extract the metal density feature and plant fiber component identifier at the corresponding location; by determining that the metal density feature meets the preset conditions and the plant fiber component identifier is present, identify the composite foreign object feature of metal and plant fiber. Specifically, this includes: based on the effective association pair, associating the internal foreign object target identifier with the internal foreign object characteristic data output in step 206, extracting the metal density feature corresponding to the internal foreign object target, i.e., the average gray value used to screen high-density foreign objects in step 204. The preset judgment conditions for the metal density feature are: the average gray value must be less than or equal to the density threshold Tden determined in step 204, i.e., 50 to 80, and the pixel area of ​​the internal foreign object target screened in step 203 must be within the typical size range of metal debris, 15 to 400 pixels, corresponding to an actual size of 0.1 to 0.5 mm. 2 Simultaneously, the component identification result of the internal foreign object target is extracted by associating the internal foreign object target identification number with the foreign object component identification data output in step 305.

[0086] The judgment conditions for the plant fiber component identification are as follows: the component identification results contain plant fiber type, and the similarity index corresponding to the type must be greater than or equal to the preset threshold determined in step 305, i.e., 0.85 to 0.9; the metal density feature and plant fiber component identification corresponding to the same valid association pair are judged simultaneously. If both meet the above preset conditions, the foreign object corresponding to the association pair is marked as a composite foreign object of metal and plant fiber, and the composite foreign object feature of metal and plant fiber coexisting is identified, realizing cross-modal association between physical density feature and chemical composition feature.

[0087] Step 403: Based on the characteristics of the composite foreign object, extract its morphological parameters and component ratio information; when the morphological parameters meet the entanglement characteristics and the component ratio meets the preset conditions, it is determined that there is a harmful foreign object. Specifically, this includes: for the identified metal and plant fiber composite foreign object, extract the morphological parameters output in step 206 through its internal foreign object target identifier, including the major axis length, minor axis length, roundness, and pixel area; the preset judgment condition for the morphological parameters to meet the entanglement characteristics is: the ratio of the major axis length to the minor axis length is greater than or equal to 3, indicating that the foreign object is elongated and conforms to the geometric characteristics of an entanglement structure; the roundness is less than or equal to 0.3, and the closer the roundness is to 0, the more irregular the shape. Entangled foreign objects are usually irregular due to the interweaving of fibers and metal, and the pixel area is greater than or equal to 50 pixels, corresponding to an actual size of 0.08mm. 2 Eliminate interference from minute impurities.

[0088] Simultaneously, the similarity index between the metal component and the plant fiber component in the foreign object component identification data output in step 305 is extracted, and the component ratio is calculated: the metal component ratio is the metal similarity index divided by (the sum of the metal similarity index and the plant fiber similarity index), and the plant fiber component ratio is the plant fiber similarity index divided by (the sum of the metal similarity index and the plant fiber similarity index). The preset component ratio conditions are: the metal component ratio is between 30% and 70%, and the plant fiber component ratio is between 30% and 70%. Through the detection of 30 groups of entangled composite foreign object samples, this ratio range can effectively distinguish entangled composite foreign objects from simple mixed foreign objects. When the morphological parameters meet the entanglement feature judgment conditions and the component ratio meets the preset conditions, the composite foreign object is judged to contain harmful foreign objects, and a final report containing the foreign object location, morphological parameters, component ratio, and harmfulness judgment results is generated, realizing multi-dimensional dynamic judgment.

[0089] In this embodiment of the invention, a bridge is established between surface detection data and internal detection data by calculating the spatial distance between the geometric coordinates of surface foreign object location data and the spatial location information of foreign object in internal foreign object characteristic data. Valid association pairs are filtered based on a preset spatial tolerance threshold to exclude irrelevant data with mismatched positions, ensuring the validity of the association results. Based on the location association information, the metal density features and plant fiber component identifiers at the corresponding locations are extracted in a targeted manner. The metal density features originate from the physical properties of the internal foreign object characteristic data, and the plant fiber component identifiers originate from the chemical properties of the foreign object component identifier data, achieving cross-modal integration of physical and chemical component features. By determining that the metal density features meet preset conditions and the plant fiber component identifiers are present, composite foreign object features where metal and plant fibers coexist can be specifically identified, improving the targeting of feature recognition. Morphological parameters and component ratio information are extracted from the composite foreign object features to form a multi-dimensional judgment basis. The morphological parameters reflect the physical structure, and the component ratio information reflects the component composition. By judging whether the morphological parameters meet the entanglement characteristics and whether the component ratio meets preset conditions, simple coexisting foreign objects and harmful composite foreign objects with entanglement structures can be distinguished, avoiding misjudgments caused by relying solely on a single dimension.

[0090] like Figure 2 As shown, embodiments of the present invention also provide a foreign object detection system for health capsule products, comprising:

[0091] The surface foreign object detection module is used to acquire surface images of health capsules; delineate reference sample areas in the surface images; perform image feature analysis on the reference sample areas to extract their baseline feature set; obtain image processing sensitivity coefficients based on the relative deviation between the baseline feature set and preset standard features; obtain optimized detection parameters based on the image processing sensitivity coefficients; and process the surface image using the optimized detection parameters to obtain surface foreign object positioning data containing geometric coordinates.

[0092] The internal foreign object detection module is used to perform directional scanning on the corresponding capsule based on the geometric coordinates contained in the surface foreign object positioning data to obtain a binary projection image; high-density foreign object targets are separated from the binary projection image, and internal foreign object characteristic data characterizing their physical properties are extracted by contour tracking and geometric measurement of the high-density foreign object targets.

[0093] The component analysis module is used to collect near-infrared spectra of the foreign matter region inside the capsule based on the internal foreign matter characteristic data; perform feature analysis on the near-infrared spectra to extract feature spectra; and compare the feature spectra with a preset standard spectral database to obtain foreign matter component identification data.

[0094] The foreign object identification module is used to perform multi-source information matching based on surface foreign object location data, internal foreign object characteristic data, and foreign object component identification data to obtain matching results; based on the matching results, it identifies composite foreign object characteristics that simultaneously possess metallic properties and plant fiber components, and determines whether there are harmful foreign objects based on the composite foreign object characteristics.

[0095] It should be noted that this system is a system corresponding to the above method. All implementation methods in the above method embodiments are applicable to this embodiment and can achieve the same technical effect.

[0096] The above description represents the preferred embodiments of the present invention. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A method for detecting foreign matter in health capsule products, characterized in that, The method includes: Step 100: Obtain a surface image of the health capsule; delineate a reference sample area in the surface image; perform image feature analysis on the reference sample area to extract its baseline feature set; obtain the image processing sensitivity coefficient based on the relative deviation between the baseline feature set and the preset standard features; obtain optimized detection parameters based on the image processing sensitivity coefficient; process the surface image using the optimized detection parameters to obtain surface foreign object positioning data containing geometric coordinates. Step 200: Based on the geometric coordinates contained in the surface foreign object location data, perform directional scanning on the corresponding capsule to obtain a binarized projection image; separate the high-density foreign object target from the binarized projection image, and extract the internal foreign object characteristic data that characterizes its physical properties by performing contour tracking and geometric measurement on the high-density foreign object target. Step 300: Based on the internal foreign matter characteristic data, collect the near-infrared spectrum of the foreign matter region inside the capsule; perform feature analysis on the near-infrared spectrum and extract the feature spectrum; compare the feature spectrum with the preset standard spectral database to obtain the foreign matter component identification data; Step 400: Based on surface foreign object location data, internal foreign object characteristic data, and foreign object component identification data, multi-source information matching is performed to obtain matching results. Based on the matching results, composite foreign object characteristics possessing both metallic properties and plant fiber components are identified. The presence of harmful foreign objects is determined based on these composite foreign object characteristics, including: calculating the spatial distance between the abnormal surface area and the internal foreign object target based on the geometric coordinates in the surface foreign object location data and the spatial location information of the foreign object in the internal foreign object characteristic data; filtering the spatial distance according to a preset spatial tolerance threshold to determine valid correlation pairs that satisfy the positional correspondence; obtaining positional correlation information representing the spatial consistency between the surface and internal foreign object based on the valid correlation pairs; extracting the metal density characteristics and plant fiber component identification at the corresponding locations based on the positional correlation information representing the spatial consistency between the surface and internal foreign object; identifying composite foreign object characteristics of metal and plant fiber by determining that the metal density characteristics meet preset conditions and the plant fiber component identification is present; extracting morphological parameters and component ratio information based on the composite foreign object characteristics; determining the presence of harmful foreign objects when the morphological parameters meet entanglement characteristics and the component ratio meets preset conditions.

2. The method for detecting foreign matter in health capsule products according to claim 1, characterized in that, Step 100: Obtain a surface image of the health capsule; delineate a reference sample area in the surface image; Image feature analysis is performed on the reference sample region to extract its baseline feature set, including: Acquire a surface image of the health capsule and convert the surface image into a grayscale image; Based on grayscale images, the imaging area of ​​the capsule body is determined by edge detection and contour fitting; based on the imaging area of ​​the capsule body, combined with the curvature distribution characteristics of the capsule surface and the evaluation of illumination uniformity, edges and reflective areas with optical interference are excluded to obtain a candidate region set; based on the candidate region set, a statistically representative reference sample region is delineated in the central region with clear surface texture. Based on the grayscale image data of the reference sample region, a grayscale co-occurrence matrix with a fixed pixel spacing is constructed; based on the grayscale co-occurrence matrix with a fixed pixel spacing, three second-order statistics, contrast, correlation and entropy, are calculated in each direction respectively. The three second-order statistics of contrast, correlation and entropy in each direction are normalized to obtain normalized multi-directional texture features. The normalized multi-directional texture features are combined according to preset rules to form a benchmark feature set that characterizes the normal texture state of the capsule surface.

3. The method for detecting foreign matter in health capsule products according to claim 2, characterized in that, Based on the relative deviation between the baseline feature set and the preset standard features, the image processing sensitivity coefficient is obtained; based on the image processing sensitivity coefficient, the optimized detection parameters are obtained, including: The benchmark feature set is compared item by item with the preset normal capsule surface feature database to calculate the relative deviation value of each texture feature item; the relative deviation value of each texture feature item is input into the pre-trained weight allocation model to obtain the dynamic weight coefficient corresponding to each deviation value. Based on the relative deviation values ​​of each texture feature item and the corresponding dynamic weight coefficients, the overall anomaly index is calculated by weighted fusion; the overall anomaly index is input into a nonlinear mapping function to obtain the image processing sensitivity coefficient. Based on the image processing sensitivity coefficient, the high threshold parameter of Canny edge detection is derived through a preset first threshold mapping relationship; based on the high threshold parameter, the corresponding low threshold parameter is derived through a preset proportional relationship; at the same time, based on the image processing sensitivity coefficient, the gray-level similarity threshold required for region growth is determined through a preset transformation relationship. The high threshold parameter, low threshold parameter and gray-scale similarity threshold are associated and configured to form the optimized detection parameters.

4. The method for detecting foreign matter in health capsule products according to claim 3, characterized in that, The surface image is processed using optimized detection parameters to obtain surface foreign object localization data containing geometric coordinates, including: Based on the optimized detection parameters, multi-scale edge enhancement is performed on the surface image to obtain an intermediate image containing edge gradient information; Based on the intermediate image, region growing processing is performed to obtain preliminary foreign object candidate regions; A morphological closing operation is performed on the candidate foreign object region to obtain a morphologically optimized binary image. Connectivity analysis is performed on the morphologically optimized binary image, and surface foreign object location data containing geometric coordinates is obtained through contour extraction and geometric center calculation.

5. The method for detecting foreign matter in health capsule products according to claim 4, characterized in that, Step 200: Based on the geometric coordinates contained in the surface foreign object location data, perform directional scanning on the corresponding capsule to obtain a binarized projection image; separate the high-density foreign object target from the binarized projection image, and extract internal foreign object characteristic data representing its physical properties by contour tracking and geometric measurement of the high-density foreign object target, including: Based on the geometric coordinates contained in the surface foreign object location data, the corresponding capsule is directionally scanned to obtain an X-ray attenuation image reflecting the internal material density distribution. The X-ray attenuation image is subjected to threshold segmentation based on the maximum inter-class variance method to obtain a binarized projection image; The binarized projection image is processed by connected component labeling to obtain a labeled image containing multiple independent regions; based on the labeled image, the morphological features of each independent region are extracted, including pixel area, circumscribed rectangle position and centroid coordinates; according to the preset foreign object size range and spatial distribution constraints, the morphological features of each independent region are screened to obtain candidate foreign object regions; The candidate foreign object region is further screened based on a preset density threshold to separate high-density foreign object targets. Morphological opening operations are performed on high-density foreign objects to obtain a denoised binary image. Based on the denoised binary image, continuous contour point sets of each independent region are extracted. Polygon approximation processing is performed on the continuous contour point sets of each independent region to eliminate jagged edges and retain the main contour features, thus obtaining contour data. Based on contour data, the geometric feature parameters of high-density foreign objects are calculated and their centroid coordinates are extracted as spatial location information of the foreign objects, forming internal foreign object characteristic data that characterizes their physical properties and spatial location.

6. The method for detecting foreign matter in health capsule products according to claim 5, characterized in that, Step 300: Based on the internal foreign matter characteristic data, collect the near-infrared spectrum of the foreign matter region inside the capsule; Near-infrared spectroscopy is characterized to extract characteristic spectra; these characteristic spectra are then compared with a pre-defined standard spectral database to obtain foreign substance component identification data, including: Based on the spatial location information of the foreign object contained in the internal foreign object characteristic data, fixed-point spectral acquisition is performed on the corresponding area inside the capsule to obtain the raw near-infrared spectral data. Perform preprocessing on the raw near-infrared spectral data to obtain preprocessed spectral data; Based on the preprocessed spectral data, a feature vector characterizing the chemical composition of the foreign substance is constructed by reducing the dimensionality of the foreign substance and retaining a preset number of principal components through principal component analysis. The feature vector is compared with the spectral features of various substances stored in the preset standard spectral database. The similarity between the feature vector and the spectral features is calculated item by item. The cosine similarity is used to quantify the similarity of the spectral features to obtain a similarity set with each standard substance. Based on the similarity set, a spectral matching index is obtained. Based on the spectral matching index, standard substance types with similarity exceeding a preset threshold are selected as identification results to obtain foreign substance component identification data for identifying foreign chemical components.

7. A foreign matter detection system for health capsule products, wherein the system implements the method as described in any one of claims 1 to 6, characterized in that, include: The surface foreign object detection module is used to acquire surface images of the health capsules; Delineate the reference sample region in the surface image; Image feature analysis is performed on the reference sample area to extract its baseline feature set; based on the relative deviation between the baseline feature set and the preset standard features, the image processing sensitivity coefficient is obtained; based on the image processing sensitivity coefficient, the optimized detection parameters are obtained; the optimized detection parameters are used to process the surface image to obtain surface foreign object location data containing geometric coordinates. The internal foreign object detection module is used to perform directional scanning on the corresponding capsule based on the geometric coordinates contained in the surface foreign object positioning data to obtain a binary projection image; high-density foreign object targets are separated from the binary projection image, and internal foreign object characteristic data characterizing their physical properties are extracted by contour tracking and geometric measurement of the high-density foreign object targets. The component analysis module is used to collect near-infrared spectra of the foreign matter region inside the capsule based on the characteristics of the internal foreign matter. Near-infrared spectra are analyzed to extract characteristic spectra; the characteristic spectra are compared with a preset standard spectral database to obtain foreign substance component identification data; The foreign object identification module is used to perform multi-source information matching based on surface foreign object location data, internal foreign object characteristic data, and foreign object component identification data to obtain matching results; based on the matching results, it identifies composite foreign object characteristics that simultaneously possess metallic properties and plant fiber components, and determines whether there are harmful foreign objects based on the composite foreign object characteristics.

8. A computing device, characterized in that, include: One or more processors; A storage device for storing one or more programs that, when executed by one or more processors, cause the one or more processors to implement the method as described in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a program that, when executed by a processor, implements the method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Method for rapidly and nondestructively detecting seed quality based on near infrared spectrum technology

    CN119595590A

  • Material multi-mode X-ray foreign matter detection method

    CN120446171A