A method for detecting the interface size of special-shaped shafts
Through the YOLOv8 and SGDRegressor algorithms, the size and angle of special-shaped parts are estimated directly from the image, solving the problem of detecting the size and angle of special-shaped parts in the existing technology, achieving fast and accurate detection on the industrial assembly line, and simplifying the camera calibration process. .
Patent Information
- Application Number
- CN202311545370.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-20
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2043-11-20
AI Technical Summary
It is difficult to quickly and accurately detect the size and angle of special-shaped parts with existing technology. Especially in industrial assembly lines, there is a lack of flexible and efficient detection methods, and traditional methods require a cumbersome camera calibration process.
The YOLOv8 target detection algorithm combined with the gradient descent algorithm SGDRegressor is used to directly estimate the size and angle of the part from the uncorrected image through camera parameter estimation and error compensation model, simplifying the camera calibration process and converting two-dimensional measurements into three-dimensional measurements.
It achieves fast and accurate part size and angle detection, is suitable for industrial assembly lines, reduces camera calibration steps, and improves the robustness and efficiency of detection.
Smart Images

Figure CN117589065B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of target detection methods, and in particular to a detection method for the size of a special-shaped shaft interface. Background Art
[0002] Visual dimension measurement is a common requirement in industrial inspection. However, monocular vision measurement has low accuracy and large field of view (FOV), while multi-vision measurement involves multi-source information fusion and incurs a lot of computational overhead. Therefore, we propose an optimization method for measuring plane dimension measurement with height difference to reduce error. Traditional measurement usually requires manual operation using calipers, screw micrometers and other tools. However, with the advancement of computer and image processing technology, visual measurement has become one of the most promising measurement methods in engineering applications. It can be mainly divided into two categories: multi-vision measurement methods and monocular vision measurement methods. Multi-vision measurement uses triangulation to obtain the plane coordinates of image feature points from several different views. Due to its large field of view (FOV) and high accuracy, it is used in many fields. For example, Genovese et al. proposed a method using a plane reflector and a phase target, but the calibration process was too cumbersome and not conducive to engineering applications.
[0003] Multi-vision methods involve the processing and correlation of data from multiple cameras, requiring camera time synchronization and spatial calibration to ensure the consistency of visual information. Disparity calculation is a key step in multi-vision methods, involving pixel-level matching and searching, with high computational complexity. Although the measurement accuracy of multi-vision methods is high, it requires a tedious calibration process in the initial stage of measurement and needs to be recalibrated whenever the camera position changes. This makes the monocular method advantageous in terms of convenience and flexibility.
[0004] In monocular measurement, the conversion parameters from the world coordinate system to the image coordinate system are derived through simple calibration. Monocular measurement has the characteristics of simple structure and high efficiency, and is suitable for industrial equipment with limited resources. The existing technology detects the size and angle of special-shaped parts, generally using random sampling for direct measurement, or converting the entire irregular part into a regular rectangle and measuring the length and width of the rectangle to approximately estimate the length and width of the part. However, it is impossible to detect the scale and angle of a certain part of the special-shaped part, and the above two methods are suitable for detection in the laboratory, which is not conducive to the fast and complex size detection on the assembly line. In order to solve the above problems, the present invention proposes a method for detecting the size and angle of special-shaped parts. Summary of the invention
[0005] The purpose of the present invention is to provide a detection method for the size of special-shaped shaft interfaces to improve the robustness of detection means and parts detection, without the need for cumbersome camera calibration process, making it more conducive to engineering applications; the calibration process estimates the camera's orientation, focal length, object distance and other information from the original YOLOv8; the input image does not need to be corrected by the camera.
[0006] In order to achieve the above object, the present invention adopts the following technical solutions:
[0007] The present invention uses the YOLOv8 target detection algorithm to identify the smooth straight line and adjacent inclined straight line of the part in the picture, namely target frame 1 and target frame 2, and then estimates the scale and angle of the outer contour length, width and height of the target frame of the specified part of the acquired part. The scale and angle estimation mainly include: geometric calibration is achieved by estimating the absolute size, including restoring the camera's orientation (horizontal plane in the image), field of view, absolute height of the camera and the ground, and other information. Finally, with this information, the two-dimensional measurement in the image can be converted into a three-dimensional measurement in real space. The gradient descent algorithm SGDRegressor and the true value are used to fit the contour length and angle through the mathematical relationship between the two types of target frames and the standard value, and the specific content is as follows.
[0008] A method for detecting the size of a special-shaped shaft interface includes the following contents:
[0009] S1. Use a CMOS camera to collect images of special-shaped parts on the experimental table to produce a data set, and use annotation software to annotate the data set; expand the data set, and divide the data set into a training set and a validation set;
[0010] S2, process the data set obtained in S1, and after the processing is completed, input it into YOLOv8 for training to obtain the modelv8.pt file;
[0011] S3, using the camera parameter estimation model to detect the pixel size and rotation angle of target boxes 1 and 2;
[0012] S4. Select the gradient descent algorithm SGDRegressor as the error compensation model. Use the error compensation model to approximate the angle and size of the target box in the two-dimensional image to the size of the part to be detected, and indirectly represent the angle of the measured part of the two-dimensional image; estimate the error between the angle and size of the two-dimensional space and the size and angle of the three-dimensional space, train the error compensation model, and obtain the regression_model.pt file;
[0013] S4. Add conversion and correction modules to YOLOv8, combine the camera parameter estimation model and the error compensation model to build a camera parameter estimation-error compensation detection model based on the YOLOv8-SGDRegressor algorithm, train the model, and then input the modelv8.pt file and regression_model.pt file to perform size conversion and correction on the predicted value to obtain the actual size and angle.
[0014] Preferably, the S1 specifically includes the following contents:
[0015] A CMOS camera is used to capture images of special-shaped parts on the laboratory table to produce an image dataset of special-shaped shaft interface parts. The obtained dataset is amplified and divided into a training set and a validation set in a ratio of 8:2. The area and category information of the two adjacent parts of the detection parts in all images are marked.
[0016] Preferably, S2 specifically includes the following contents:
[0017] S2.1, determining a bilateral threshold according to the histogram features of the grayscale image;
[0018] S2.2, respectively determine the thresholds for the intervals where the part pixel value is less than 20 and the intervals where the part pixel value is greater than 240: for the interval where the part pixel value is less than 20, the average of the maximum pixel value and the minimum pixel value is used as the minimum threshold; for the interval where the part pixel value is greater than 240, the median threshold of the number of pixels with a pixel value greater than 240 is calculated as the maximum threshold;
[0019] S2.3, performing Gaussian filtering on the interval between the maximum threshold and the minimum threshold in S2.2;
[0020] S2.4, use Sobel operator to extract the edge of the image;
[0021] S2.5. Label the image after edge extraction in S2.4 and train it in YOLOv8 to obtain the modelv8.pt file.
[0022] Preferably, the camera parameter estimation-error compensation detection model based on the YOLOv8-SGDRegressor algorithm is trained in S4, specifically including the following contents: setting training parameters, adopting the number of training iterations as 500 times, training in the first 50 times using the freezing method, and the learning rate is 0.001; the learning rate for the next 250 iterations is 0.0001; the training process adopts the annealing cosine algorithm and the label smoothing algorithm.
[0023] Preferably, the camera parameter estimation-error compensation detection model based on the YOLOv8-SGDRegressor algorithm described in S4 includes a Kalman filter module, and the Kalman filter module is provided with yolov8n_cbam.yaml of the CBAM attention mechanism, and yolov8n_small_object.yaml is additionally provided to enhance the detection effect of small targets.
[0024] Preferably, the camera parameter estimation-error compensation detection model based on the YOLOv8-SGDRegressor algorithm in S4 further includes a loss function module, and the loss function module is specifically a classification loss: lcls_loss and a frame regression loss: box_loss+dfl_loss.
[0025] Compared with the prior art, the present invention provides a Raw domain image and video de-moiré method based on channel modulation and spatial modulation, which has the following beneficial effects:
[0026] (1) The present invention can quickly and accurately detect the size and angle of parts in the picture;
[0027] (2) By using the part size and angle detection method proposed by the present invention, the size and angle of a part can be estimated by directly inputting an uncorrected picture without the need for camera calibration and correction;
[0028] (3) Compared with the traditional method of detecting part size, the present invention is more suitable for detecting part size and angle on industrial assembly lines. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 is the histogram of the grayscale image of the part mentioned in Embodiment 1 of the present invention;
[0030] Figure 2 The histogram of the pixel value of the part mentioned in Embodiment 1 of the present invention is less than 20;
[0031] Figure 3 The histogram of the pixel value of the part mentioned in Embodiment 1 of the present invention being greater than 240;
[0032] Figure 4 This is a flow chart of the size and angle detection of special-shaped parts mentioned in Example 2 of the present invention;
[0033] Figure 5 This is the part size and angle detection identification diagram mentioned in Example 2 of the present invention. DETAILED DESCRIPTION
[0034] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments.
[0035] This study uses the most advanced real-time monitoring algorithm YOLOv8 target detection algorithm as the basis, combines it with the improved EfficientNet convolutional neural network, and improves the combined network. The acquired conveyor belt wear picture is preprocessed. The preprocessing technology uses the Retinex image enhancement algorithm to enhance the image brightness, protect details, protect colors, restore naturalness, denoise the image, extract details, etc., to improve the clarity of the belt wear picture. Finally, the improved algorithm is deployed to the conveyor real-time detection equipment to detect the conveyor belt, which can accurately determine the worn parts of the conveyor belt and the degree of wear of each part. The detection method for the interface size of the special-shaped shaft proposed in the present invention is described in combination with specific examples. The specific content is as follows.
[0036] Embodiment 1:
[0037] The present invention proposes a method for detecting the size of a special-shaped shaft interface, which includes the following contents:
[0038] S1. Use a CMOS camera to collect images of special-shaped parts on the experimental table to produce a data set, and use annotation software to annotate the data set; expand the data set and divide the data set into a training set and a validation set, which specifically includes the following contents:
[0039] The images of special-shaped parts on the experimental table are collected by CMOS camera to produce the image dataset of special-shaped shaft interface parts. The obtained dataset is expanded and divided into training set and validation set in the ratio of 8:2. The area and category information of the two adjacent parts of the detection parts in all images are marked.
[0040] S2. Process the data set obtained in S1 and input it into YOLOv8 for training to obtain the modelv8.pt file, which specifically includes the following contents:
[0041] S2.1. Please refer to Figure 1 , determine the bilateral threshold according to the histogram characteristics of the grayscale image;
[0042] S2.2, determine the thresholds for the intervals where the pixel value of the part is less than 20 and the pixel value of the part is greater than 240: see Figure 2-3 For the interval where the pixel value of the part is less than 20, the average of the maximum pixel value and the minimum pixel value is used as the minimum threshold; for the interval where the pixel value of the part is greater than 240, the number of pixels with a pixel value greater than 240 is calculated and taken as the median threshold as the maximum threshold;
[0043] S2.3, performing Gaussian filtering on the interval between the maximum threshold and the minimum threshold in S2.2;
[0044] S2.4, use Sobel operator to extract the edge of the image;
[0045] S2.5, label the image after edge extraction in S2.4, and train it in YOLOv8 to obtain the modelv8.pt file;
[0046] S3, using the camera parameter estimation model to detect the pixel size and rotation angle of target boxes 1 and 2;
[0047] S4. Select the gradient descent algorithm SGDRegressor as the error compensation model. Use the error compensation model to approximate the angle and size of the target box in the two-dimensional image to the size of the part to be detected, and indirectly represent the angle of the measured part of the two-dimensional image; estimate the error between the angle and size of the two-dimensional space and the size and angle of the three-dimensional space, train the error compensation model, and obtain the regression_model.pt file;
[0048] S4. Add conversion and correction modules to YOLOv8, combine the camera parameter estimation model and the error compensation model to build a camera parameter estimation-error compensation detection model based on the YOLOv8-SGDRegressor algorithm, train the model, and then input the modelv8.pt file and regression_model.pt file to perform size conversion and correction on the predicted value to obtain the actual size and angle;
[0049] The model training specifically includes the following contents: setting training parameters, taking the number of training iterations as 500 times, using the freezing method for the first 50 times of training, and the learning rate as 0.001; the learning rate for the next 250 iterations is 0.0001; the training process uses the annealing cosine algorithm and the label smoothing algorithm;
[0050] The camera parameter estimation-error compensation detection model based on the YOLOv8-SGDRegressor algorithm further includes a Kalman filter module and a loss function module, wherein the Kalman filter module is provided with yolov8n_cbam.yaml of the CBAM attention mechanism, and yolov8n_small_object.yaml is added to enhance the detection effect of small targets; the loss function module is specifically the classification loss: lcls_loss and the bounding box regression loss: box_loss+dfl_loss.
[0051]
[0052] Based on Example 1, but different in that,
[0053] See also Figure 4 This embodiment proposes a method for detecting the size of a special-shaped shaft interface, including the following contents:
[0054] Step 1: Prepare at least 800 photos as a dataset;
[0055] Step 2: Data preprocessing: Preprocess the training and test data sets by graying, Gaussian filtering, binarization, and Sobel edge extraction. Select appropriate part images, mark the size and angle to be detected, and use them as training and test data sets in a ratio of 8:2.
[0056] Step 3: Build and train the model: Use YOLOv8 to use 2D images to predict the length, width, height and angle of the part to be measured of the special-shaped part in the picture to obtain the coordinates of the object, and complete the detection of target frame 1 and target frame 2, that is, identify target frame 1 and target frame 2;
[0057] Step 4: Perform a stochastic gradient descent algorithm SGDRegressor on the size and angle of the part to be measured to regress the predicted value and the true value; the result is as follows Figure 5 As shown:
[0058] Get the length l1 and width w1 of target frame 1, and the length l2 of target frame 2. The bounding box definition method of YOLOv8 is [x_c, y_c, longside, shortside,]. The modified angle information is stored in. [x_c, y_c, longside, shortside] can be regarded as a horizontal target bounding box. Output the angle of target frame 1 and the angle of target frame 2, then the angle of the desired special-shaped part;
[0059] Step 5: Model testing: Use the test data set to test the trained YOLOv8+SGDRegressor model, detect the part size and angle, and obtain the detection results.
[0060] The above description is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can make equivalent replacements or changes according to the technical scheme and inventive concept of the present invention within the technical scope disclosed by the present invention, which should be covered by the protection scope of the present invention.
Claims
1. A method for detecting the size of a special-shaped shaft interface, characterized in that: It includes the following: S1. Use a CMOS camera to collect images of special-shaped parts on the experimental table to produce a data set, and use annotation software to annotate the data set; expand the data set, and divide the data set into a training set and a validation set; S2. Process the data set obtained in S1, and after the processing is completed, input it into YOLOv8 for training to obtain the modelv8.pt file; specifically, it includes the following contents: S2.1, determining a bilateral threshold according to the histogram features of the grayscale image; S2.2, respectively determine the thresholds for the intervals where the part pixel value is less than 20 and the intervals where the part pixel value is greater than 240: for the interval where the part pixel value is less than 20, take the average of the maximum pixel value and the minimum pixel value as the minimum threshold; For the interval where the pixel value of the part is greater than 240, the number of pixels with a pixel value greater than 240 is calculated and the median threshold is taken as the maximum threshold; S2.3, performing Gaussian filtering on the interval between the maximum threshold and the minimum threshold in S2.2; S2.4, use Sobel operator to extract the edge of the image; S2.5, label the image after edge extraction in S2.4, and train it in YOLOv8 to obtain the modelv8.pt file; S3, using the camera parameter estimation model to detect the pixel size and rotation angle of target boxes 1 and 2; S4. Select the gradient descent algorithm SGDRegressor as the error compensation model. Use the error compensation model to approximate the size and angle of the target box in the two-dimensional image to the size of the part to be detected, and indirectly represent the angle of the measured part of the two-dimensional image; estimate the error between the size and angle of the two-dimensional space and the size and angle of the three-dimensional space, train the error compensation model, and obtain the regression_model.pt file; S5. Add conversion and correction modules to YOLOv8, combine the camera parameter estimation model and the error compensation model to build a camera parameter estimation-error compensation detection model based on the YOLOv8-SGDRegressor algorithm, and train the model, specifically including the following contents: set training parameters, adopt the training iteration number as 500 times, use the freezing method for the first 50 times, and the learning rate is 0.001; the learning rate for the next 250 iterations is 0.0001; the training process uses the annealing cosine algorithm and the label smoothing algorithm; Then input the modelv8.pt file and regression_ model.pt file, perform size conversion and correction on the predicted values to obtain the real size and angle; The camera parameter estimation-error compensation detection model based on the YOLOv8-SGDRegressor algorithm includes a Kalman filter module and a loss function module. The Kalman filter module is provided with a CBAM attention mechanism, and the loss function module is specifically a classification loss and a frame regression loss.
2. A method for detecting the size of a special-shaped shaft interface according to claim 1, characterized in that: The S1 specifically includes the following contents: A CMOS camera is used to capture images of special-shaped parts on the laboratory table to produce an image dataset of special-shaped shaft interface parts. The obtained dataset is amplified and divided into a training set and a validation set in a ratio of 8:
2. The area and category information of the two adjacent parts of the detection parts in all images are marked.
