A pharmaceutical raw material foreign matter detection method, system and terminal based on image analysis
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA NAT PHARM IND CORP LTD
- Filing Date
- 2026-03-10
- Publication Date
- 2026-06-05
Smart Images

Figure CN121810686B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of pharmaceutical raw material detection technology, specifically relating to a method, system, and terminal for detecting foreign matter in pharmaceutical raw materials based on image analysis. Background Technology
[0002] In the entire pharmaceutical production chain, the purity and cleanliness of raw materials determine the quality of the final product. In order to meet the mandatory requirements of Good Manufacturing Practice (GMP) for pharmaceuticals, foreign matter detection is carried out on pharmaceutical raw materials in the initial stage of pharmaceutical production and processing to remove various foreign impurities, eliminate potential safety hazards from the source, and ensure the safety of pharmaceuticals.
[0003] Existing foreign object detection technologies for pharmaceutical raw materials have functional defects in terms of detection accuracy and reliability. Many systems rely on threshold judgment based on simple features of a single frame of static image. This processing logic cannot distinguish between real foreign objects and the complex shape of the pharmaceutical raw material itself. During detection, it often misjudges the reflective particles on the surface of the raw material as foreign objects.
[0004] Furthermore, in terms of analytical dimensions, existing detection systems typically perform isolated analysis on image frames only. Interference such as light spots often appears randomly and only appears in a single image or intermittent images. Considering that real foreign objects are always present in a continuous image sequence during material transportation, while other interference such as light spots shows significant differences in continuous images, independent analysis of individual images may lead to interference such as light spots affecting the determination of real foreign objects, resulting in normal medicines being treated as impurities and wasting them.
[0005] In view of this, the present invention provides a method, system and terminal for detecting foreign objects in pharmaceutical raw materials based on image analysis. Summary of the Invention
[0006] The purpose of this invention is to provide a method, system, and terminal for detecting foreign matter in pharmaceutical raw materials based on image analysis, which solves the technical problem in the prior art where the limited detection images lead to interference such as light spots in the determination of real foreign matter, resulting in normal medicines being treated as impurities and wasting them.
[0007] To achieve the above objectives, the technical solution adopted by the present invention is as follows: A method for detecting foreign matter in pharmaceutical raw materials based on image analysis, the method comprising:
[0008] Perform position correction on the image containing foreign objects to obtain the corrected image containing foreign objects;
[0009] Performing position correction on an image containing foreign objects includes: selecting a first reference image from the image containing foreign objects, and selecting a comparison image from a standard image that does not contain foreign objects; calculating the degree of matching between the comparison image and the first reference image at each candidate offset position in the candidate offset position set; determining the candidate offset position with the maximum degree of matching as the correction position, and correcting the image containing foreign objects based on the correction position;
[0010] A second suspected image is obtained by performing a verification and identification process on the corrected image containing foreign objects.
[0011] When the number of second suspicious images exceeds a preset threshold, an updated offset value is generated, and the position correction of the image containing the foreign object is re-executed based on the updated offset value.
[0012] Preferably, before performing position correction, the method further includes: acquiring images of the pharmaceutical raw materials to obtain an initial image set;
[0013] Perform preprocessing operations on the initial image set to generate a basic image set; perform foreign object identification operations on the basic image set to determine the basic image containing foreign objects as an image containing foreign objects.
[0014] Preferably, performing foreign object identification on the basic image set includes: calculating the similarity value between the region to be identified in the basic image and the preset standard raw material template; when the similarity value is not greater than the preset similarity threshold, it is determined that there is a foreign object in the region to be identified.
[0015] Preferably, generating the updated offset value includes: determining the corrected position of the corrected image containing foreign objects that causes the number of second suspicious images to exceed a preset number threshold as the first reference offset;
[0016] The adjustment factor is determined based on the number of second suspicious images; the first baseline offset is mathematically calculated with the adjustment factor to obtain the updated offset value.
[0017] Preferably, performing position correction on an image containing foreign objects further includes: classifying the image containing foreign objects into a preset shape group based on the shape characteristics of the foreign objects in the image; calculating the average offset of each shape group; and determining the average offset of the group as the correction position for performing position correction.
[0018] Preferably, the preprocessing operation on the initial image set includes: normalizing the color grayscale values and filtering the random values of the initial image set, setting a screening area in the processed image; and selecting the screening area where the color channel difference value is greater than a preset fluctuation threshold as the area to be identified for foreign object identification operation.
[0019] A pharmaceutical raw material foreign object detection system based on image analysis, used to implement the above-mentioned image analysis-based pharmaceutical raw material foreign object detection method, the system comprising:
[0020] The foreign object recognition module is used to perform foreign object recognition operations on the basic image set to identify images containing foreign objects;
[0021] The position correction module is used to perform position correction on the image containing foreign objects based on the correction position, so as to generate a corrected image containing foreign objects;
[0022] The correction and verification module is used to perform verification and identification on the corrected image containing foreign objects to obtain a second suspected image, and generate a trigger signal when the number of second suspected images exceeds a preset number threshold.
[0023] The offset update module is used to respond to the trigger signal, generate an updated offset value, and provide the updated offset value to the position correction module for re-performing position correction on images containing foreign objects.
[0024] Preferably, the offset update module is used to: determine the correction position previously used by the position correction module that causes the number of second suspicious images to be greater than a preset number threshold as the first reference offset.
[0025] Preferably, the offset update module is further configured to: determine an adjustment factor based on the number of second suspicious images; and calculate an updated offset value based on the first reference offset and the adjustment factor.
[0026] A pharmaceutical raw material foreign object detection terminal based on image analysis includes a processor and a memory communicatively connected to the processor. The memory stores a computer program, and when the computer program is executed by the processor, it implements the aforementioned pharmaceutical raw material foreign object detection method based on image analysis.
[0027] Beneficial effects
[0028] 1. After performing the foreign object identification operation, the present invention performs position correction on the image containing foreign objects and performs verification identification on the corrected image containing foreign objects. It can identify false alarms caused by positional shift during image acquisition and mark images that are still judged to contain foreign objects after positional correction, thereby improving the accuracy and reliability of foreign object detection.
[0029] 2. Before performing position correction, this invention classifies images containing foreign objects into shape groups according to the shape characteristics of the foreign objects, calculates the average offset of each shape group independently, and uses it as the basis for performing position correction on images containing foreign objects within that group. Based on this technical solution, it can compensate for position deviations caused by different types of foreign objects and different causes. Compared with a uniform correction method, it can achieve targeted position correction and provide a more accurate image basis for subsequent verification and identification.
[0030] 3. This invention introduces a closed-loop feedback mechanism and a self-optimization mechanism. After performing the verification and identification, the effectiveness of the position correction is evaluated by counting the number of second suspicious images. When the number of second suspicious images is greater than the preset number threshold, it is determined that the current offset has a deviation, and the offset value is calculated and updated to guide the new round of position correction. By dynamically adjusting its core correction parameters, it can adapt to dynamic interferences such as conveyor belt vibration changes that may occur in the production environment. Attached Figure Description
[0031] Figure 1 This is a flowchart of the foreign object detection process of the present invention;
[0032] Figure 2 This is a flowchart of the image processing procedure for foreign objects according to the present invention;
[0033] Figure 3 This is a structural diagram of an embodiment of the present invention. Detailed Implementation
[0034] To make the objectives, features, and advantages of the present invention more apparent and understandable, the specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
[0035] Example 1
[0036] See Figure 1-2 As shown, this embodiment provides a method for detecting foreign objects in pharmaceutical raw materials based on image analysis, which improves the detection effect of foreign objects in the production process of pharmaceutical raw materials and reduces misjudgment and missed judgment caused by slight changes in the image acquisition position or interference from the texture of the raw materials themselves.
[0037] Specifically, the following steps are included:
[0038] On the automated conveying path of pharmaceutical raw materials, image acquisition devices are set up in the preset acquisition area to continuously acquire images of the pharmaceutical raw materials moving on the conveyor belt in order to obtain an initial image set. For example, the acquisition rate of 20 frames per second is set to ensure uninterrupted visual coverage of the materials on the conveyor belt.
[0039] Then, a pre-processing operation is performed on each initial image in the initial image set to generate a basic image set, which provides a standardized data foundation for subsequent foreign object identification. This pre-processing operation is to eliminate the interference of changes in ambient light and to initially highlight potential abnormal features.
[0040] Specifically, the initial images are normalized to reflect their grayscale values, mapping the pixel values of color images acquired under different lighting conditions to a standard grayscale value space, such as the range of 0 to 255, thus providing a consistent data foundation for subsequent comparative analysis.
[0041] Then, smoothing is applied to the normalized grayscale image. The grayscale values of a group of pixels in the pixel neighborhood are statistically calculated, such as taking the median or performing a weighted average, in order to filter out random noise points generated during image acquisition, while preserving the edge contour details of the raw material particles and avoiding key features from becoming blurred due to excessive smoothing.
[0042] Then, for each smoothed image, multiple preset screening areas are divided, and the color statistical characteristics of each screening area are calculated one by one, such as the average value or histogram distribution of its three color channels R, G, and B, and the difference between the area and the adjacent area or the standard color background obtained based on the statistical analysis of qualified raw material images is quantified.
[0043] This difference can be determined by calculating the distance in the multidimensional color space, thereby obtaining the color channel difference value to measure the degree of color abnormality. Screening areas with color channel difference values greater than the preset fluctuation threshold are selected, representing the normal fluctuation range of the raw material's texture and color. If the area exceeds this range, it means that there may be objects with colors or reflective properties that are significantly different from normal raw materials. These screened areas are defined as areas to be identified, serving as the key analysis objects for subsequent foreign object identification operations. The preset fluctuation threshold is set based on statistical analysis of a large number of qualified raw material images.
[0044] Furthermore, a foreign object identification operation is performed on each basic image in the basic image set to determine whether the basic image contains foreign objects other than pharmaceutical raw materials. Specifically, the foreign object identification operation includes calculating the similarity value between the area to be identified and a preset standard raw material template. The preset standard raw material template is a standard raw material image that has been confirmed to be free of foreign objects by collecting and analyzing a large number of such images. The benchmark data representation, constructed by image averaging or extracting common texture and color features, is used as a standard for comparison with the area to be identified.
[0045] The similarity value can be calculated using a predetermined matching measurement method. For example, by calculating the normalized cross-correlation coefficient between the region to be identified and the preset standard material template at the pixel level, or by comparing the comprehensive similarity index of the two in terms of brightness, contrast and structure, the result can quantify the degree of matching between the region to be identified and the preset standard material template.
[0046] Then, the calculated similarity value is compared with the preset similarity evaluation threshold, such as 0.85. This threshold is set to achieve a balance between detection sensitivity and false alarm rate to determine whether there are foreign objects in the area to be identified, thus balancing detection sensitivity and false alarm rate.
[0047] If the similarity value is not greater than the preset similarity threshold, it is determined that there is a foreign object in the area to be identified; otherwise, if the similarity value is greater than the threshold, it is determined that there is no foreign object in the area to be identified. Based on this judgment result, if a basic image does not contain any area that is determined to contain foreign objects, the basic image is defined as a standard image, that is, an image without foreign objects. These images can be collected for subsequent updates and optimization of the preset standard raw material template.
[0048] If the judgment result is a basic image containing a foreign object, then the foreign object is formally defined as a foreign object, and the basic image is defined as an image containing a foreign object. At the same time, the coordinates, outline, and area information of the region where the foreign object is located are recorded.
[0049] Furthermore, due to the mechanical vibration of the conveyor belt and the slight shift in the camera's installation position over time, pixel-level displacement occurs in the images of the same batch of raw materials, interfering with subsequent accurate verification; therefore, position correction is performed on the images to eliminate this effect.
[0050] Specifically, from the images containing foreign objects, one image containing foreign objects is selected as the first reference image, which serves as an image in the reference coordinate system during the position correction process; and from the standard images, one or more standard images are selected as comparison images, which are compared with the first reference image to calculate the position offset; after defining the image containing foreign objects as the first reference image, a search grid consisting of multiple candidate offset positions is generated using the first reference image as the reference coordinate system.
[0051] Each grid point is a comparison node, and its coordinates represent a potential translation correction amount (Δx, Δy). Then, the comparison image is translated according to the offset represented by each comparison node, and the matching degree value between the comparison node and the first reference image at each candidate offset position is calculated. The comparison node with the maximum matching degree value is determined as the optimal matching point, and its corresponding candidate offset position is determined as the correction position.
[0052] After determining the correction position, in order to further isolate and analyze the foreign object itself, the absolute value of the gray level difference between the aligned comparison image and the first reference image is calculated pixel by pixel based on the position of the optimal matching point; and compared with the preset difference threshold, the outline of the foreign object is accurately delineated. This process is called offset analysis, and its result can delineate the outline of the foreign object and eliminate the interference of background texture.
[0053] As a preferred implementation, the step of determining the correction position can employ an iterative optimization search process. A pre-set upper limit for the number of replacements is used to control computational resource consumption, and a candidate offset direction set containing multiple basic displacement directions is defined. Before reaching the upper limit for the number of replacements, the following operations are repeated: one or more directions are selected from the candidate offset direction set, the current optimal correction position is fine-tuned, and a new correction position to be tested is generated; the comparison image is placed at the new position and the matching degree value with the first reference image is calculated; if the matching degree value is better than the currently recorded optimal value, the current optimal correction position is updated.
[0054] The above process helps to search for the optimal solution globally, avoiding being satisfied with only the local optimal matching result. The final output of the current optimal correction position is the correction position. Before proceeding to the next step, a preferred implementation introduces a classification correction strategy based on foreign object features to perform refined position correction, classifying the foreign objects in each image containing foreign objects according to their shape features.
[0055] Then, the average offset is calculated for each group, and the group-specific offset is used to uniformly correct the position of all images containing foreign objects in that group, such as aspect ratio, roundness, or edge complexity. Based on these shape characteristics, the foreign objects are classified into preset shape groups, such as fibrous, granular, or sheet-like. Foreign objects of different shapes may originate from different stages in the production process, and the systematic displacement patterns generated when they are introduced may also be different.
[0056] Then, each image containing foreign objects is grouped according to the shape category of the foreign objects it contains. For each shape category, the average value of the corrected position of all images containing foreign objects in that category relative to the standard image is calculated to obtain the average offset of that category. This average offset is then used as a unified image displacement value to perform position correction on all images containing foreign objects in that category, i.e., a corrected set of images containing foreign objects is obtained after spatial alignment.
[0057] Furthermore, for each corrected image containing foreign objects in the corrected image set, the foreign object identification operation is performed again to obtain a verification identification result, which is used to verify the accuracy of the initial detection. This result is used as a second judgment criterion to verify the accuracy of the initial detection. If the verification identification result is still a corrected image containing foreign objects, it indicates that after correcting the potential positional deviation, the abnormal feature still exists stably, thus highly confirming the authenticity of the foreign object.
[0058] The corrected image containing foreign objects is then defined as the second suspected image, and a re-examination judgment mark is generated for the original image containing foreign objects corresponding to the second suspected image. This mark is used to trigger subsequent manual re-examination, alarm, or automatic rejection processes. At the same time, an alarm signal can be triggered to prompt the operator to intervene or start the automatic rejection device. Conversely, if the re-examination result is that there are no foreign objects, it means that the initial judgment was likely a false positive caused by image displacement. The detection record of this image is marked as resolved, thereby effectively reducing the overall false alarm rate.
[0059] In practical applications, this method also includes an adaptive correction parameter update mechanism; if the number of second suspicious images generated in this step exceeds the preset number threshold within a statistical period, it is determined that the current forward offset correction parameter has a deviation, and the deviation is greater than the allowable deviation range.
[0060] Then, the average offset of the class group used to generate the current batch of corrected images containing foreign objects is defined as the first reference offset, which is used to generate the updated offset value; and the first reference offset is weighted and combined with the pre-stored original reference offset, which is the reference offset in the pre-stored initial state or long-term stable state.
[0061] The specific steps for generating the updated offset value are as follows: a weight coefficient, i.e., an adjustment factor, is determined based on the degree to which the number of second suspicious images exceeds a preset threshold; then, the first reference offset is combined with the pre-stored original reference offset using a preset weighted summation formula to generate the updated offset value, which is used to replace the original correction parameter.
[0062] The weighted summation formula can be: Update offset value = (α × first reference offset) + [(1-α) × original reference offset], where the value of the adjustment factor α is positively correlated with the degree to which the number of second suspicious images exceeds the threshold;
[0063] This updated offset value replaces the original correction position or original reference offset, and the position of all subsequent images containing foreign objects is corrected to generate a new set of corrected images containing foreign objects. This is then used to perform the next round of foreign object identification operations, enabling the detection method to dynamically adapt to the gradual changes in the production line environment.
[0064] Example 2
[0065] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to specific embodiments. It should be understood that the specific embodiments described herein are merely for explaining the invention and are not intended to limit the scope of protection of the invention.
[0066] Please see Figure 3This embodiment provides a foreign object detection system for pharmaceutical raw materials based on image analysis. By performing position correction and verification on the initially identified foreign object-containing image, and dynamically updating the correction parameters when the verification result is not ideal, the system achieves closed-loop optimization of the foreign object detection process in pharmaceutical raw materials.
[0067] In its specific implementation, the system can be embodied as a software program deployed on a pharmaceutical raw material foreign object terminal based on image analysis. The terminal may include a personal computer, server, industrial control computer or dedicated embedded device. The terminal includes a processor and a memory. When the computer program stored in the memory is executed by the processor, it implements the logic of the following functional modules.
[0068] The system includes the following modules:
[0069] The image acquisition and processing unit is responsible for acquiring images of pharmaceutical raw materials from the image acquisition device and performing pre-processing operations in preparation for subsequent foreign object identification operations. By processing the acquired images, an initial image set is generated, and then the pre-processing operation is performed on the initial image set to generate a basic image set.
[0070] Specifically, the preprocessing operation includes normalizing the color grayscale values of each image in the initial image set to eliminate the influence of environmental factors such as uneven lighting, and performing random value filtering to suppress image noise. After processing, one or more screening areas are set in the image, and the color channel difference value of the pixels in each screening area is calculated. When the color channel difference value of a certain screening area is greater than a preset fluctuation threshold, it indicates that there may be color abnormalities in the area, and the unit determines this screening area as the area to be identified for subsequent foreign object identification operations.
[0071] The foreign object identification module receives a basic image containing the area to be identified, generated by the image acquisition and processing unit, and is configured to perform a foreign object identification operation to identify images containing foreign objects. Specifically, the module compares the area to be identified in the basic image with one or more preset standard raw material templates and calculates the similarity value between them. The preset standard raw material templates are image templates of standard pharmaceutical raw materials that do not contain any foreign objects and are stored in advance. When the calculated similarity value is not greater than a preset similarity threshold, it is determined that there is a foreign object in the area to be identified, and the entire basic image containing the area to be identified is identified as an image containing foreign objects for subsequent processing.
[0072] The core task of the position correction module is to perform position correction on the image containing foreign objects identified by the foreign object recognition module based on the corrected position, so as to generate a corrected image containing foreign objects. The position correction aims to correct the image acquisition position deviation caused by mechanical vibration, conveyor belt offset, etc.
[0073] Specifically, in order to determine the correction position, the module first selects an image from the images containing foreign objects as the first reference image, and selects an image from the standard images that do not contain foreign objects as the comparison image; then, in the preset set of candidate offset positions, it calculates the degree of matching between the comparison image and the first reference image at each candidate offset position; the candidate offset position with the maximum degree of matching is determined as the correction position, and the entire batch of images containing foreign objects is corrected by translation, rotation or affine transformation based on the correction position;
[0074] It can also automatically classify images containing foreign objects into preset shape groups based on the shape characteristics of the foreign objects in the images, such as strip-shaped, granular, or fibrous; then calculate the statistical average of the positional offset of all images in each shape group, and determine the average offset of the group as the correction position for performing positional correction on the images in that group.
[0075] The correction and verification module is used to perform quality verification on the corrected images containing foreign objects output by the position correction module. It performs verification identification on each corrected image containing foreign objects to determine the second suspected image. The verification identification can use the same or more stringent algorithm as the foreign object identification operation to confirm again whether the foreign object exists or whether the position is accurate.
[0076] After reviewing the corrected image set containing foreign objects, the number of second suspected images generated is counted. If the number is greater than the preset threshold, it indicates that the previous position correction was ineffective and there is a systematic deviation. Then, a trigger signal is generated and sent to the offset update module.
[0077] The offset update module responds to the trigger signal generated by the correction and verification module. Its task is to generate an updated offset value for the position correction module to perform a more accurate secondary correction. Specifically, the correction position previously used by the position correction module that caused the number of second suspicious images to exceed a preset threshold is determined as the first reference offset.
[0078] Then, the adjustment factor is determined based on the number of the second suspected images. The first reference offset is then subjected to a preset mathematical operation with the adjustment factor to obtain an updated offset value. This updated offset value is then provided to the position correction module, which uses the updated offset value as the new correction position to re-perform position correction on the original image containing the foreign object.
[0079] Through the collaborative work of the aforementioned image acquisition and processing units and modules, a closed-loop detection process with feedback adjustment capability is implemented to identify foreign objects in pharmaceutical raw materials. By reviewing the correction results and dynamically and adaptively updating the correction parameters, the detection process is continuously optimized, thus solving the problem of image acquisition position drift that may occur during the production process.
[0080] The above are merely preferred embodiments of this application and are not intended to limit this application. For those skilled in the art, this application can have various modifications and variations. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A method for detecting foreign matter in pharmaceutical raw materials based on image analysis, characterized in that, The method includes: Perform position correction on the image containing foreign objects to obtain the corrected image containing foreign objects; The process of performing position correction on an image containing foreign objects includes: selecting a first reference image from the image containing foreign objects, and selecting a comparison image from a standard image that does not contain foreign objects; calculating the degree of matching between the comparison image and the first reference image at each candidate offset position in the candidate offset position set; determining the candidate offset position with the maximum degree of matching as the correction position, and correcting the image containing foreign objects based on the correction position. A second suspected image is obtained by performing a verification and identification process on the corrected image containing foreign objects. When the number of second suspicious images exceeds a preset threshold, an updated offset value is generated, and the position correction of the image containing the foreign object is re-executed based on the updated offset value. Generating the updated offset value includes: The correction position used to generate the corrected image containing foreign objects that causes the number of second suspicious images to exceed a preset threshold is determined as the first reference offset. The adjustment factor is determined based on the number of second suspicious images; The first baseline offset is mathematically calculated with the adjustment factor to obtain the updated offset value; Performing position correction on images containing foreign objects also includes: Based on the shape characteristics of the foreign object in the image, the image containing the foreign object is classified into a preset shape group; Calculate the average offset for each shape group and determine the correction position for performing position correction.
2. The method for detecting foreign matter in pharmaceutical raw materials based on image analysis according to claim 1, characterized in that, Before performing position correction, the method also includes: Image acquisition is performed on pharmaceutical raw materials to obtain an initial image set; Perform preprocessing operations on the initial image set to generate a basic image set; Perform a foreign object identification operation on the basic image set to identify the basic image containing the foreign object as the foreign object image.
3. The method for detecting foreign matter in pharmaceutical raw materials based on image analysis according to claim 2, characterized in that, Performing foreign object identification operations on a basic image set includes: Calculate the similarity value between the region to be identified in the basic image and the preset standard raw material template; when the similarity value is not greater than the preset similarity threshold, it is determined that there is a foreign object in the region to be identified.
4. The method for detecting foreign matter in pharmaceutical raw materials based on image analysis according to claim 1, characterized in that, Preprocessing operations on the initial image set include: The initial image set is subjected to color grayscale value normalization and random value filtering, and a screening area is set in the processed image. The screening area where the color channel difference value is greater than the preset fluctuation threshold is selected as the area to be identified for foreign object identification.
5. A pharmaceutical raw material foreign object detection system based on image analysis, used to implement the pharmaceutical raw material foreign object detection method based on image analysis as described in any one of claims 1-4, characterized in that, The system includes: The foreign object recognition module is used to perform foreign object recognition operations on the basic image set to identify images containing foreign objects; The position correction module is used to perform position correction on the image containing foreign objects based on the correction position, so as to generate a corrected image containing foreign objects; The correction and verification module is used to perform verification and identification on the corrected image containing foreign objects to obtain a second suspected image, and generate a trigger signal when the number of second suspected images exceeds a preset number threshold. The offset update module is used to respond to the trigger signal, generate an updated offset value, and provide the updated offset value to the position correction module for re-performing position correction on the image containing foreign objects. The offset update module is also used to: determine the adjustment factor based on the number of second suspicious images; and calculate the updated offset value based on the first reference offset and the adjustment factor.
6. The pharmaceutical raw material foreign object detection system based on image analysis according to claim 5, characterized in that, The offset update module is used to determine the correction position previously used by the position correction module that caused the number of second suspicious images to exceed a preset number threshold as the first reference offset.
7. A pharmaceutical raw material foreign object detection terminal based on image analysis, characterized in that, It includes a processor and a memory communicatively connected to the processor. The memory stores a computer program, which, when executed by the processor, implements a method for detecting foreign matter in pharmaceutical raw materials based on image analysis as described in any one of claims 1-4.