A target ball positioning circle measurement defect detection method and device based on SOD-YOLOv5 model
Through the target pill positioning and detection method based on the SOD-YOLOv5 model, combined with the fine defect detection of the difference method, the problem of target pill position offset, color diversity, insufficient depth of field and small defect detection in the prior art is solved, and the detection of target pill surface defects with high accuracy and high reliability is achieved.
Patent Information
- Application Number
- CN202411499284.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-25
- Publication Date
- 2025-05-06
- Estimated Expiration
- 2044-10-25
AI Technical Summary
The existing surface defect detection technology for target pills has problems such as positional offset of target pills, difficulty in positioning, insufficient depth of field leads to blurred edges, strong light-transmitting target pills with many interference points, and traditional methods are difficult to detect tiny defects less than 10x10 pixels.
The target pill positioning circle measurement defect detection method based on the SOD-YOLOv5 model is adopted. Through the precise positioning of the microscope lens and the improved YOLOv5 model, the coarse positioning and accurate measurement of the target pill are realized, and the fine defect detection is carried out in combination with the differential method, which is suitable for various target pill detection scenarios.
It significantly improves the accuracy and reliability of surface defect detection of target pills, ensures the accuracy of measurement of diameter, roundness and radius of target pills, reduces false detection and missed detection rates, and adapts to the detection of different lighting conditions and colors.
Smart Images

Figure CN119290891B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of microscope image processing, and in particular to a target pellet positioning circle measurement defect detection method and device based on a SOD-YOLOv5 model. Background Art
[0002] With the development of industrial automation, especially in the fields of precision manufacturing, semiconductor processing and material testing, the requirements for the detection accuracy and efficiency of surface defects of objects are increasing. As an industrial component, the surface quality of the target pellet directly affects the performance of the product. However, the existing target pellet defect detection technology has the following shortcomings: 1. The target pellet is usually placed in a small grid container, but during the measurement process, the target pellet is easy to roll to the grid boundary. Due to the limitation of the field of view, the camera can only capture part of the target pellet, or its position is offset to the periphery of the field of view, affecting the accurate measurement of geometric parameters such as diameter, roundness and radius; 2. The target pellet has various colors, including white, yellow and black. Target pellets of different colors respond differently to light. In order to obtain the outer contour information of the target pellet (such as diameter, roundness, major axis and minor axis), backlighting is usually required; when performing surface defect detection (such as black spots, fibers, foreign matter and scratches), top lighting methods such as ring light or coaxial light are required, which are mostly Diversified lighting methods and color changes make it difficult to locate and identify the target pellets, especially when multiple colors of target pellets need to be detected in the same scene; 3. The target pellets usually have a certain height. Especially when shooting at high magnification, the edge area of the target pellet is prone to blur due to the narrow depth of field, and traditional positioning algorithms are difficult to focus and locate accurately; 4. The yellow and white target pellets have strong light transmittance, and it is difficult to form a clear black and white outline under backlight conditions, resulting in a large number of interference points in the image, affecting the accuracy of roundness measurement; 5. The defects on the surface of the target pellets are usually small in size. Traditional image processing methods and defect detection algorithms perform poorly in detecting tiny defects smaller than 10x10 pixels, and there are missed detections and false detections. Especially when facing complex surface structures or tiny scratches, it is difficult to achieve high-precision detection. Summary of the invention
[0003] Technical purpose: In view of the shortcomings of existing target pellet surface defect detection, the present invention discloses a target pellet positioning circle measurement defect detection method and device based on the SOD-YOLOv5 model. Through the precise positioning of the microscope lens and the improved YOLOv5 model, the accuracy and reliability of target pellet surface defect detection are improved, and comprehensive coverage from coarse positioning to precise measurement is achieved, which is suitable for various target pellet detection scenarios.
[0004] Technical solution: To achieve the above technical objectives, the present invention adopts the following technical solution:
[0005] A target pellet positioning circle measurement defect detection method based on the SOD-YOLOv5 model specifically includes the following steps:
[0006] S1, placing a plurality of target pellets in a plurality of grid holes of a target pellet box, so that each target pellet corresponds to a grid hole of the target pellet box, moving a microscope lens so that the target pellet box enters the initial field of view of the microscope lens, and moving the microscope lens to the first grid hole of the target pellet box;
[0007] S2. Use the trained SOD-YOLOv5 model to detect the target pill image in the current field of view and determine the center position of the target pill, calculate the offset between the center position of the target pill and the center position of the microscope field of view, and adjust the position of the microscope lens to reduce the offset, so that the center of the target pill is gradually aligned with the center of the field of view, and determine the circumscribed rectangle of the target pill;
[0008] S3, extracting the maximum inscribed circle of the circumscribed rectangle of the target pill, setting multiple sampling areas along the circumference of the inscribed circle, performing image edge detection on each sampling area, and fitting the circular contour of the edge points using the least squares method, calculating the roundness and diameter value of the fitting result, and determining the geometric characteristics of the target pill;
[0009] S4. Use the trained SOD-YOLOv5 model to perform defect detection on the image within the fitted circular contour of the target pellet, and then use the differential method to further detect subtle defects. Combine the detection results of the SOD-YOLOv5 model and the differential method to identify the defect type on the surface of the target pellet, draw a marking box in the defect area for positioning, and output the defect detection results;
[0010] S5. The microscope lens is positioned according to the structural specifications of the target pill box and the layout of the grid holes, moved to the next grid hole of the target pill box and steps S2 to S4 are repeated until all the target pills in the target pill box are detected.
[0011] Preferably, the specific steps of performing image edge detection on each sampling area and using the least square method to perform circular contour fitting on the edge points are as follows:
[0012] Based on the maximum inscribed circle of the circumscribed rectangle of the target pill, multiple sampling areas are selected on the circumference. Each sampling area is a rectangular detection frame with an angle pointing to the center of the circle.
[0013] Draw multiple line segments pointing to the center of the circle in each sampling area, calculate the gradient value of each line segment, record the position of the point with the maximum change in the gradient value of each line segment, and calculate the average position of the points with the maximum change in the gradient values of multiple line segments as the edge point;
[0014] Use the edge points in all sampling areas to perform the first circular contour fitting and obtain a preliminary fitting circle with a radius of Ra;
[0015] Use the preliminary fitting circle to generate two circles with radii of 0.95Ra and 1.05Ra respectively. Both circles are concentric with the preliminary fitting circle, and the two circles form an annular ROI area.
[0016] Calculate the distance D from all edge points to the center of the initial fitting circle. If 0.95Ra≤D≤1.05Ra is satisfied, then keep it in the annular ROI area, otherwise remove it.
[0017] The least square method is used again to fit the circular contour of the edge points in the retained annular ROI area to obtain a new fitting circle, and the new fitting circle is used as the fitting circular contour of the target pellet.
[0018] Preferably, the number of sampling areas is 100 and they are equally spaced on the circumference of the largest inscribed circle.
[0019] Preferably, the specific training process of the SOD-YOLOv5 precise positioning model is as follows:
[0020] Collect target pellet image samples, and use image annotation tools to annotate the center position, circumscribed rectangle, and surface defect area of the target pellet, and perform data enhancement processing on the collected target pellet image samples;
[0021] Use the pre-trained SOD-YOLOv5 model as the initial weights and integrate the attention mechanism module into its structure to enhance the ability to extract small defect features;
[0022] Set training parameters, including learning rate, batch size, and loss function, and weight features according to small target features;
[0023] In each training round, random data augmentation is performed on the input image and the loss is calculated, and the SOD-YOLOv5 model parameters are updated through the back-propagation algorithm;
[0024] Evaluate the average precision and recall rate through the validation set, and adjust the training parameters according to the validation results until the SOD-YOLOv5 model converges;
[0025] Export the trained SOD-YOLOv5 model to ONNX format to complete the training of SOD-YOLOv5.
[0026] Preferably, the data enhancement processing includes brightness adjustment, rotation, scaling and image stitching to generate image data suitable for different lighting conditions and pellet colors.
[0027] Preferably, the image samples of the target pellet include image samples of the target pellet under different lighting conditions and colors, the different lighting conditions include backlight, top ring light and coaxial light, and the colors include white, yellow and black.
[0028] Preferably, the specific steps of further detecting subtle defects using the differential method are as follows:
[0029] Grayscale the original target pellet image to obtain a grayscale image;
[0030] Perform mean filtering on the grayscale image to obtain a smoothed image;
[0031] Difference the smoothed image from the original image at pixel level to obtain a differential image;
[0032] Binarize the difference image and extract the area with obvious difference to obtain a binary image;
[0033] Perform connected domain analysis on binary images to obtain several connected regions and calculate their areas;
[0034] The connected regions are screened by area, defect regions with an area between 0 and 50 pixels are retained, and the position information of the screened defect regions is obtained to complete the detection of small defects on the target pellet surface.
[0035] Preferably, the microscope lens is positioned according to the structural specifications of the target pill box and the layout of the grid holes, and the specific steps of moving to the next grid hole of the target pill box are as follows:
[0036] According to the structural specifications of the target pill box and the layout parameters of the grid holes, the horizontal and vertical spacing between the centers of each grid hole in the target pill box is determined;
[0037] The horizontal and vertical spacings between the centers of each grid hole in the target pill box are set as the horizontal displacement and vertical displacement of the microscope lens respectively;
[0038] Controlling the motion system of the microscope lens to move the microscope lens to the position of the next grid hole according to the preset horizontal displacement and vertical displacement;
[0039] After the movement is completed, the target pellets in the new grid holes are tested, and the above steps are repeated to move to each grid hole of the target pellet box in turn until all target pellets have been tested.
[0040] Preferably, the pellet box comprises a grid of holes in 10 rows and 10 columns.
[0041] The present invention also provides a target pill positioning circle measurement defect detection device based on the SOD-YOLOv5 model, which is used to implement the above-mentioned target pill positioning circle measurement surface defect detection method based on the SOD-YOLOv5 model, comprising:
[0042] A target pellet box, used to place multiple target pellets in multiple grid holes respectively;
[0043] The microscope imaging device includes a microscope lens, an image acquisition module, an automatic focusing module and an XYZ electric moving platform. The microscope lens and the image acquisition module are used to acquire high-resolution images of the target pellet; the automatic focusing module is used to dynamically adjust the focal length according to the height of the target pellet to ensure clear imaging; the XYZ electric moving platform is used to accurately move the microscope lens so that it is aligned with each grid hole of the target pellet box one by one;
[0044] Light source system, including backlight, ring light source and coaxial light source, used to enhance the imaging quality of the target capsule outer contour and surface defects;
[0045] The data processing unit is connected to the image acquisition module and processes the collected target pellet images using the SOD-YOLOv5 model;
[0046] The control system is used to control the autofocus of the microscope imaging device and the operation of the XYZ moving platform to complete the detection of each target pellet in turn.
[0047] Beneficial effects: The target pellet positioning circle measurement defect detection method and device based on the SOD-YOLOv5 model provided by the present invention have the following beneficial effects:
[0048] The present invention adopts multiple positioning methods such as coarse positioning and fine positioning, uses the SOD-YOLOv5 model to detect the position of the target pellet multiple times, and dynamically adjusts the monitoring area of the target pellet according to the changes in the field of view of the microscope lens, so that the target pellet is always in the center of the field of view during the detection process, which significantly improves the measurement accuracy of the target pellet diameter, roundness and radius, and avoids the influence of the target pellet position offset on the measurement result.
[0049] For target pellets with high light transmittance, the present invention adopts a circular ROI approximation method to limit the measurement area of the target pellet, and uses a point set to filter interference points, and then fits the circular contour through the least squares method, so that the roundness of the target pellet can still be accurately measured under the condition of more interference, ensuring that clear edges can still be obtained on the high light transmittance target pellet, thereby obtaining accurate geometric measurements.
[0050] The present invention realizes high-precision detection of large and small defects by combining the SOD-YOLOv5 model and the differential method. For large defects, the SOD-YOLOv5 model is used for rapid identification and classification. For small defects less than 50 pixels, the differential method is used in combination with annular ROI screening for fine detection to effectively capture tiny flaws. This not only improves the detection accuracy and sensitivity, but also significantly reduces the false detection and missed detection rates, ensuring that defects of different sizes can be efficiently and accurately identified and classified in complex detection scenarios, thereby improving the overall quality control level.
[0051] The present invention significantly enhances the detection capability in complex lighting environments by adding target samples with different lighting conditions and colors during the training phase of the SOD-YOLOv5 model. Whether detecting the outer contour of the target or identifying surface defects, the present invention can adaptively adjust to different colors and lighting conditions to achieve precise positioning and detection, ensuring consistent detection effects for diversified target pellets. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art are briefly introduced below.
[0053] Figure 1 This is a flow chart of the method for detecting surface defects by measuring the target pellet positioning circle of the present invention;
[0054] Figure 2 This is the specific training process of the SOD-YOLOv5 model of the present invention;
[0055] Figure 3 A flow chart of the method for measuring the target pellet circle of the present invention;
[0056] Figure 4 It is a schematic diagram of the sampling area division in the target pill circle measurement of the present invention;
[0057] Figure 5 This is a flow chart of the method for detecting small defects on the surface of a target pellet according to the present invention;
[0058] Figure 6 A schematic diagram of the target pellet surface defect detection completed by the present invention;
[0059] Figure 7 This is a flow chart of the method for moving the microscope lens in the target pill box of the present invention. DETAILED DESCRIPTION
[0060] The present invention will be described more clearly and completely below by way of a preferred embodiment in conjunction with the accompanying drawings, but the present invention is not limited to the scope of the embodiment.
[0061] like Figure 1 As shown, the present invention provides a target pellet positioning circle measurement defect detection method based on the SOD-YOLOv5 model, which specifically includes the following steps:
[0062] S1. Place multiple target pills in multiple grid holes of a target pill box so that each target pill corresponds to a grid hole of the target pill box. First, roughly position the target pills, move the microscope lens so that the target pill box enters the initial field of view of the microscope lens, and move the microscope lens to the first grid hole of the target pill box.
[0063] In one embodiment, the diameter of the target pellet is between 100 μm and 1000 μm, the microscope lens uses a comprehensive magnification of 240X or higher, and there are 10 rows and 10 columns of grid holes on the target pellet box, and the holes are 4700 μm apart in both horizontal and vertical directions.
[0064] The accuracy of coarse positioning depends on the verticality of the XY axis of the stage, the processing angle of the fixture, whether the installation angle is consistent with the XY direction of the stage's movement, and the accuracy of the XY axis of the grid holes in the target pill box. Coarse positioning is to make the target pill appear in the field of view in preparation for fine positioning.
[0065] Since the target pellet rolls in the hole, it will roll during the movement of the platform but will not roll out of the hole. Therefore, as long as the target pellet appears in the field of view, the coarse positioning and the appropriate magnification of the microscope lens can ensure the smooth completion of this process.
[0066] S2. Use the trained SOD-YOLOv5 model to detect the target pill image in the current field of view and determine the center position of the target pill, calculate the offset between the center position of the target pill and the center position of the microscope field of view, and adjust the position of the microscope lens to reduce the offset, so that the center of the target pill and the center of the field of view are gradually aligned, and determine the circumscribed rectangle of the target pill.
[0067] The specific process of accurately positioning the target pellet is as follows: the image of the target pellet in the first grid hole is captured using a microscope lens and input into the SOD-YOLOv5 model for detection. The model identifies the center position of the target pellet;
[0068] Calculate the offsets Δx and Δy between the center position of the target pellet and the center of the field of view of the microscope lens, where the offsets represent the degree of displacement of the target pellet relative to the center position;
[0069] Through the automatic control system of the microscope lens, the position of the microscope lens is adjusted according to the offset, so that the center of the target pellet is gradually aligned with the center of the microscope field of view, and the above detection and adjustment process is repeated until the offset is less than the preset tolerance range, and the requirement of precise alignment is achieved;
[0070] After center alignment, the circumscribed rectangle of the target pill is determined for subsequent measurement of the target pill circle.
[0071] like Figure 2 As shown, in one embodiment, preferably, the specific training process of the SOD-YOLOv5 model is as follows:
[0072] S21. Collect target pellet image samples, and annotate the center position, circumscribed rectangle and surface defect area of the target pellet using an image annotation tool, and perform data enhancement processing on the collected target pellet image samples.
[0073] In one embodiment, the pellet image samples include different lighting conditions, angles, pellet colors, and surface features, wherein the different lighting conditions include backlight, top ring light, and coaxial light, the colors include white, yellow, and black, and the surface features include scratches, black spots, foreign matter, fibers, and cracks, etc.
[0074] Use professional image annotation tools to annotate the center position and circumscribed rectangular frame of the target pellet. For training data for surface defect detection, it is necessary to annotate the bounding boxes of specific defects (such as scratches, black spots, etc.).
[0075] In one embodiment, the data enhancement processing includes brightness adjustment, rotation, scaling, and image stitching to generate image data suitable for different lighting conditions and pellet colors, thereby enhancing the robustness of the model to pellet characteristics in different environments.
[0076] S22. Use the pre-trained SOD-YOLOv5 model as the initial weights and integrate the attention mechanism module into its structure to enhance the ability to extract small defect features.
[0077] The present invention adopts the SOD improved architecture of YOLOv5 and adds a layer structure specifically for small targets, such as adding a feature extraction layer with higher resolution to improve the detection capability of small targets.
[0078] The attention mechanism module is introduced into the YOLOv5 network structure to enhance the model's feature extraction of small defect areas. In one embodiment, the CA (Coordinate Attention) module can be used to optimize the attention distribution of the detection head through coordinate information to improve the accuracy of the model in detecting small targets.
[0079] Use YOLOv5 model weights pre-trained on large-scale datasets (such as the COCO dataset) to accelerate convergence and improve the accuracy of pellet localization.
[0080] S23. Set training parameters, including learning rate, batch size and loss function, and perform weight features according to small target features.
[0081] In one embodiment, a cosine annealing learning rate scheduler may be used to enable fast learning in the early stages and gradually reduce the learning rate to reduce the risk of overfitting; a suitable batch size (usually 8 or 16) is set according to the performance of the GPU to ensure a balance between memory utilization and training efficiency; a multi-task loss function of YOLOv5 is used, including bounding box regression loss, classification loss, and target confidence loss, and the weight of small targets is increased during training according to the characteristics of small targets to ensure the detection accuracy of small defects; a higher number of rounds (such as 100 to 200 rounds) is set, and early stopping monitoring is performed during training to avoid overtraining.
[0082] S24. In each training round, random data augmentation is performed on the input image and the loss is calculated, and the SOD-YOLOv5 model parameters are updated through the back propagation algorithm.
[0083] In one embodiment, random enhancement processing is performed on the image data in each training batch, including random cropping, scaling, translation and other operations, to ensure that the model can adapt to changes in different viewing angles and pellet placement positions; in each batch, after the input image passes through the SOD-YOLOv5 model, the loss between the predicted result and the true annotation is calculated, and the model parameters are updated through back propagation.
[0084] S25. Evaluate the average precision and recall rate through the validation set, and adjust the training parameters according to the validation results until the SOD-YOLOv5 model converges.
[0085] In one embodiment, at the end of each round, the validation set is used for evaluation, and the mean average precision (mAP), detection accuracy, and recall rate are recorded to observe the performance of the model in locating the target pellet and detecting defects. Based on the evaluation results of the validation set, the learning rate is adjusted or data rebalancing (such as re-adjusting the category weights) is performed to optimize the model performance.
[0086] S26. Export the trained SOD-YOLOv5 model to ONNX format to complete the training of SOD-YOLOv5.
[0087] S3. Extract the maximum inscribed circle of the circumscribed rectangle of the target pill, set multiple sampling areas along the circumference of the inscribed circle, perform image edge detection on each sampling area, and use the least squares method to fit the circular contour of the edge points, calculate the roundness and diameter values of the fitting results, and determine the geometric characteristics of the target pill.
[0088] After the target pellet is roughly and precisely positioned, the image of the target pellet is cropped, the area containing the target pellet is retained, and the interference area in the image that does not belong to the target pellet is removed, and only the effective outline of the target pellet is retained.
[0089] like Figure 3 As shown, in one embodiment, the specific steps of performing image edge detection on each sampling area and using the least square method to perform circular contour fitting on edge points are as follows:
[0090] S31, such as Figure 4 As shown, based on the maximum inscribed circle of the circumscribed rectangle of the target pellet, multiple sampling areas are selected on the circumference, and each sampling area is a rectangular detection frame with an angle pointing to the center of the circle.
[0091] In one embodiment, the number of sampling areas is 100 and they are equally spaced on the circumference of the largest inscribed circle.
[0092] S32. Draw multiple line segments pointing to the center of the circle in each sampling area, calculate the gradient value of each line segment, record the position of the point with the maximum change in the gradient value of each line segment, and calculate the average position of the points with the maximum change in the gradient values of multiple line segments as the edge point.
[0093] S33, performing a first circular contour fitting using edge points in all sampling areas to obtain a preliminary fitting circle with a radius Ra;
[0094] S34, using the preliminary fitting circle to generate two circles with radii of 0.95Ra and 1.05Ra respectively, both circles are concentric with the preliminary fitting circle, and the two circles constitute an annular ROI area;
[0095] S35, calculating the distance D from all edge points to the center of the initial fitting circle, if 0.95Ra≤D≤1.05Ra is satisfied, then they are retained in the annular ROI area, otherwise they are removed;
[0096] S36, using the least square method to fit the circular contour of the edge points in the retained annular ROI area again to obtain a new fitting circle, and using the new fitting circle as the fitting circular contour of the pellet.
[0097] Preferably, the number of sampling areas is 100 and they are equally spaced on the circumference of the largest inscribed circle.
[0098] S4. Use the trained SOD-YOLOv5 model to perform defect detection on the image within the fitted circular contour of the target pellet, and then use the differential method to further detect subtle defects. Combine the detection results of the SOD-YOLOv5 model and the differential method to identify the defect type on the surface of the target pellet, draw a marking box in the defect area for positioning, and output the defect detection results.
[0099] The Neck layer of the SOD-YOLOv5 model has one more upsampling compared to the original yoloV5 network, and the feature map has been changed from 3 layers to 4 layers: 20*20, 40*40, 80*80, 160*160. Adding one layer can handle the problem of insufficient information of small targets and enhance the network's global understanding of small targets. An attention mechanism module is added after each feature map. This module extracts features from the horizontal and vertical directions, focuses on extracting and amplifying the features of the small target area, and improves the target positioning accuracy. The prediction layer Prediction has 4 detection heads, which increases the network's capture of multi-layer feature information, thereby obtaining more and richer location information in complex scenes and improving the detection performance of small targets.
[0100] It should be noted that the SOD-YOLOv5 model in step S4 and the model in the aforementioned step S2 are two models with the same network structure, but different data used for training.
[0101] like Figure 5 As shown, in one embodiment, the specific steps of further detecting subtle defects using the differential method are as follows:
[0102] S41. Grayscale the original target pellet image to obtain a grayscale image. The purpose of grayscale is to simplify the image processing steps and avoid the interference of color differences on defect detection.
[0103] S42, performing mean filtering on the grayscale image to obtain a smoothed image.
[0104] The purpose of mean filtering is to eliminate high-frequency noise in the image and make the small defect features in the image more obvious. The mean filter can use a 3X3 or larger window for convolution operations.
[0105] S43. Perform pixel-level differentiation between the smoothed image and the original image to obtain a differential image. The differential image can highlight subtle changes on the surface of the target pellet, especially small defects in the high-frequency part. The differential image will mainly retain subtle differences on the surface, while large areas will be suppressed, making it easier to detect small defect areas.
[0106] S44, performing a binarization operation on the difference image, extracting regions with obvious differences to obtain a binary image.
[0107] S45. Perform connected domain analysis on the binary image to obtain a number of connected regions and calculate their areas.
[0108] Connected domain analysis can mark each connected region and calculate its area according to the 4-neighborhood or 8-neighborhood connection rule. By calculating the area of each connected region, the regions with too small or too large areas are filtered out, and the regions that meet the small defect conditions are retained. In one embodiment, the region with an area range of 0 to 50 pixels is set as a valid defect region.
[0109] S46, performing area screening on the connected regions, retaining defect regions with an area between 0 and 50 pixels, and obtaining position information of the screened defect regions, thereby completing the detection of small defects on the target pellet surface.
[0110] The location information of the defect area includes the center coordinates, area and boundary information of the defect, such as Figure 6 Shown is a schematic diagram of detecting surface defects of the target pellet.
[0111] S5. The microscope lens is positioned according to the structural specifications of the target pill box and the layout of the grid holes, moved to the next grid hole of the target pill box and steps S2 to S4 are repeated until all the target pills in the target pill box are detected.
[0112] like Figure 7As shown, in one embodiment, the microscope lens is positioned according to the structural specifications of the target pill box and the layout of the grid holes, and the specific steps of moving to the next grid of the target pill box are as follows:
[0113] S51, determining the horizontal and vertical spacing between the centers of each grid hole in the target pill box according to the structural specifications of the target pill box and the layout parameters of the grid holes;
[0114] S52, respectively setting the horizontal and vertical spacings between the centers of each grid hole in the target pill box as the horizontal displacement and vertical displacement of the microscope lens;
[0115] S53, controlling the motion system of the microscope lens to move the microscope lens to the position of the next grid hole according to the preset horizontal displacement and vertical displacement;
[0116] S54, after the movement is completed, the target pills in the new grid holes are tested, and the above steps are repeated to move to each grid hole of the target pill box in turn until all the target pills are tested.
[0117] The present invention also provides a target pill positioning circle measurement defect detection device based on the SOD-YOLOv5 model, which is used to implement the above-mentioned target pill positioning circle measurement surface defect detection method based on the SOD-YOLOv5 model, comprising:
[0118] A target pellet box has a plurality of grid holes, and is used to place a plurality of target pellets in the plurality of grid holes respectively;
[0119] The microscope imaging device includes a microscope lens, an image acquisition module, an automatic focusing module and an XYZ electric moving platform. The microscope lens and the image acquisition module are used to acquire high-resolution images of the target pellet; the automatic focusing module is used to dynamically adjust the focal length according to the height of the target pellet to ensure clear imaging; the XYZ electric moving platform is used to accurately move the microscope lens so that it is aligned with each grid hole of the target pellet box one by one;
[0120] Light source system, including backlight, ring light source and coaxial light source, used to enhance the imaging quality of the target capsule outer contour and surface defects;
[0121] The data processing unit is connected to the image acquisition module and processes the collected target pellet images using the SOD-YOLOv5 model, specifically including:
[0122] Detect the center position of the target pill, calculate the offset between the center of the target pill and the center of the microscope field of view, and align the center of the target pill with the center of the microscope field of view by adjusting the position of the microscope lens;
[0123] Based on the detected circumscribed rectangle, the maximum inscribed circle of the target pellet is extracted, the circular contour is fitted, and the roundness and diameter of the target pellet are calculated by the least squares method;
[0124] Use the SOD-YOLOv5 model combined with the CA module to detect large defects on the target surface, identify small defects, and mark their locations and types;
[0125] The control system is used to control the autofocus of the microscope imaging device and the operation of the XYZ moving platform to complete the detection of each target pellet in turn.
[0126] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A target pill positioning circle measurement defect detection method based on the SOD-YOLOv5 model, characterized in that: The specific steps include: S1, placing a plurality of target pellets in a plurality of grid holes of a target pellet box, so that each target pellet corresponds to a grid hole of the target pellet box, moving a microscope lens so that the target pellet box enters the initial field of view of the microscope lens, and moving the microscope lens to the first grid hole of the target pellet box; S2. Use the trained SOD-YOLOv5 model to detect the target pill image in the current field of view and determine the center position of the target pill, calculate the offset between the center position of the target pill and the center position of the microscope field of view, and adjust the position of the microscope lens to reduce the offset, so that the center of the target pill is gradually aligned with the center of the field of view, and determine the circumscribed rectangle of the target pill; S3, extracting the maximum inscribed circle of the circumscribed rectangle of the target pill, setting multiple sampling areas along the circumference of the inscribed circle, performing image edge detection on each sampling area, and fitting the circular contour of the edge points using the least squares method, calculating the roundness and diameter value of the fitting result, and determining the geometric characteristics of the target pill; S4. Use the trained SOD-YOLOv5 model to perform defect detection on the image within the fitted circular contour of the target pellet, and then use the differential method to further detect subtle defects. Combine the detection results of the SOD-YOLOv5 model and the differential method to identify the defect type on the surface of the target pellet, draw a marking box in the defect area for positioning, and output the defect detection results; S5, the microscope lens is positioned according to the structural specifications of the target pill box and the layout of the grid holes, moved to the next grid hole of the target pill box and steps S2 to S4 are repeated until all the target pills in the target pill box are detected; Among them, the specific training process of the SOD-YOLOv5 model is as follows: Collecting pellet image samples, and annotating the center position, circumscribed rectangle and surface defect area of the pellet by using an image annotation tool, and performing data enhancement processing on the collected pellet image samples; the data enhancement processing includes brightness adjustment, rotation, scaling and image stitching to generate image data suitable for different lighting conditions and pellet colors; the pellet image samples include pellet image samples under different lighting conditions and colors, the different lighting conditions include backlight, top ring light and coaxial light, and the colors include white, yellow and black; Use the pre-trained SOD-YOLOv5 model as the initial weights and integrate the attention mechanism module into its structure to enhance the ability to extract small defect features; Set training parameters, including learning rate, batch size, and loss function, and weight features according to small target features; In each training round, random data augmentation is performed on the input image and the loss is calculated, and the SOD-YOLOv5 model parameters are updated through the back-propagation algorithm; Evaluate the average precision and recall rate through the validation set, and adjust the training parameters according to the validation results until the SOD-YOLOv5 model converges; Export the trained SOD-YOLOv5 model to ONNX format to complete the training of SOD-YOLOv5; The specific steps for further detection of subtle defects using the differential method are as follows: Grayscale the original target pellet image to obtain a grayscale image; Perform mean filtering on the grayscale image to obtain a smoothed image; Difference the smoothed image from the original image at pixel level to obtain a differential image; Binarize the difference image and extract the area with obvious difference to obtain a binary image; Perform connected domain analysis on binary images to obtain several connected regions and calculate their areas; The connected regions are screened by area, defect regions with an area between 0 and 50 pixels are retained, and the position information of the screened defect regions is obtained to complete the detection of small defects on the target pellet surface.
2. According to the method for detecting defects in target pill positioning circle measurement based on SOD-YOLOv5 model in claim 1, it is characterized in that: The specific steps of performing image edge detection on each sampling area and fitting the circular contour of the edge points using the least squares method are as follows: Based on the maximum inscribed circle of the circumscribed rectangle of the target pill, multiple sampling areas are selected on the circumference. Each sampling area is a rectangular detection frame with an angle pointing to the center of the circle. Draw multiple line segments pointing to the center of the circle in each sampling area, calculate the gradient value of each line segment, record the position of the point with the maximum change in the gradient value of each line segment, and calculate the average position of the points with the maximum change in the gradient values of multiple line segments as the edge point; Use the edge points in all sampling areas to perform the first circular contour fitting and obtain a preliminary fitting circle with a radius of Ra; Use the preliminary fitting circle to generate two circles with radii of 0.95Ra and 1.05Ra respectively. Both circles are concentric with the preliminary fitting circle, and the two circles form an annular ROI area. Calculate the distance D from all edge points to the center of the initial fitting circle. If 0.95Ra≤D≤1.05Ra is satisfied, then keep it in the annular ROI area, otherwise remove it. The least square method is used again to fit the circular contour of the edge points in the retained annular ROI area to obtain a new fitting circle, and the new fitting circle is used as the fitting circular contour of the target pellet.
3. According to the method for detecting defects in target pellet positioning circle measurement based on SOD-YOLOv5 model in claim 2, it is characterized in that: There are 100 sampling areas, which are equally spaced on the circumference of the largest inscribed circle.
4. The target pill positioning circle measurement defect detection method based on the SOD-YOLOv5 model according to claim 1 is characterized in that: The microscope lens is positioned according to the structural specifications of the target pill box and the layout of the grid holes. The specific steps for moving to the next grid hole of the target pill box are as follows: According to the structural specifications of the target pill box and the layout parameters of the grid holes, the horizontal and vertical spacing between the centers of each grid hole in the target pill box is determined; The horizontal and vertical spacings between the centers of each grid hole in the target pill box are set as the horizontal displacement and vertical displacement of the microscope lens respectively; Controlling the motion system of the microscope lens to move the microscope lens to the position of the next grid hole according to the preset horizontal displacement and vertical displacement; After the movement is completed, the target pellets in the new grid holes are tested, and the above steps are repeated to move to each grid hole of the target pellet box in turn until all target pellets have been tested.
5. The target pill positioning circle measurement defect detection method based on the SOD-YOLOv5 model according to claim 4 is characterized in that: The pellet box comprises a grid of holes in 10 rows and 10 columns.
6. A target pill positioning circle measurement defect detection device based on the SOD-YOLOv5 model, used to complete the target pill positioning circle measurement defect detection method based on the SOD-YOLOv5 model according to any one of claims 1 to 5, characterized in that: include: A target pellet box, used to place multiple target pellets in multiple grid holes respectively; The microscope imaging device includes a microscope lens, an image acquisition module, an automatic focusing module and an XYZ electric moving platform. The microscope lens and the image acquisition module are used to acquire high-resolution images of the target pellet; the automatic focusing module is used to dynamically adjust the focal length according to the height of the target pellet to ensure clear imaging; the XYZ electric moving platform is used to accurately move the microscope lens so that it is aligned with each grid hole of the target pellet box one by one; Light source system, including backlight, ring light source and coaxial light source, used to enhance the imaging quality of the target capsule outer contour and surface defects; The data processing unit is connected to the image acquisition module and processes the collected target pellet images using the SOD-YOLOv5 model; The control system is used to control the autofocus of the microscope imaging device and the operation of the XYZ moving platform to complete the detection of each target pellet in turn.
Citation Information
Patent Citations
Method for detecting surface defects of ceramic valve cores based on machine vision
CN105548208A
Aluminum ceramic ball surface detect detection method
CN106600593A