Tubular object thickness intelligent detection and identification method based on yov8
Through the intelligent detection and recognition method of tubular object thickness based on YOLOv8, the thickness of tubular objects such as bamboo tubes is automatically identified and calculated, which solves the problems of low efficiency and high cost of traditional manual measurement and achieves efficient and accurate thickness detection.
Patent Information
- Application Number
- CN202411157659.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-22
- Publication Date
- 2025-01-24
Smart Images

Figure CN119354068A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of bamboo product identification, and in particular to a method for intelligently detecting and identifying the thickness of a tubular object based on YOLOv8. Background Art
[0002] In the process of bamboo tube processing and utilization, the thickness of bamboo tube plays a vital role. Through accurate measurement of thickness, we can use bamboo tube resources more efficiently, maximize their utilization, and further improve the added value and economic benefits of bamboo products. As one of the key parameters, the thickness of bamboo tube directly affects the quality, strength of split bamboo, and the aesthetics and practicality of the final product. However, the current detection and identification of bamboo tube thickness mainly relies on traditional manual measurement methods. This method is not only inefficient and difficult to quickly and accurately measure the thickness of a large number of bamboo tubes, but also has high costs and is difficult to meet the needs of large-scale production.
[0003] In recent years, the rapid progress of deep learning technology has injected new vitality into the fields of image processing and computer vision. Among them, YOLOv8, as an outstanding object detection algorithm, has attracted widespread attention in this field due to its high efficiency and accuracy. The uniqueness of YOLOv8 lies in that it cleverly transforms the object detection task into a direct regression problem, thereby achieving instant prediction on the input image without tedious pre-processing or post-processing. The core of the algorithm is to use a carefully designed neural network (especially convolutional neural network) to deeply explore the key features in the image and generate a detailed feature map. Subsequently, this feature map is used by the algorithm to predict multiple bounding boxes and their corresponding class probabilities, so as to accurately identify and locate the target objects in the image. In order to further ensure the accuracy of the detection results, YOLOv8 also uses advanced technologies such as non-maximum suppression (NMS) to effectively eliminate redundant and overlapping bounding boxes, thereby greatly improving the efficiency and accuracy of detection. However, although YOLOv8 performs well in many aspects, its complex algorithm flow and limitations for irregular shapes are still the direction of future improvement and optimization. Summary of the invention
[0004] The present invention aims to solve at least one of the technical problems raised in the above-mentioned background technology, and provide a method for intelligent detection and identification of tubular thickness based on YOLOv8, which can improve the detection accuracy and efficiency of tubular thickness.
[0005] In order to achieve the above object, the technical solution adopted by the present invention is:
[0006] A method for intelligent detection and identification of tubular thickness based on YOLOv8, comprising the following steps:
[0007] S1, collecting data to create a data set: collecting image data of the tubular object in the shooting area, and then marking the outer circle and inner circle contours of the cross section of the tubular object in the collected image to create a data set;
[0008] S2, build a data set and train a model: select the single-stage target detection model YOLOv8 of the YOLO series as the tubular target detection algorithm model, use the data collected in step S1 to build a COCO data set, and use the COCO data set to train the tubular target detection algorithm model to obtain a tubular target detection algorithm model that can identify and locate the contour of the tubular object;
[0009] S3, model reasoning: connect the tubular object detection algorithm model to the real-time video stream for real-time reasoning to determine whether there is a tubular object in the shooting area. If the tubular object detection algorithm model does not detect the existence of a tubular object in the image of the shooting area or detects the existence of one or more circles in the image, continue to reason on the next frame stream image obtained by shooting; if it is detected that there is a tubular object and two circles in the image of the shooting area, the detection data is used as the reasoning result and the detection is completed;
[0010] S4, result analysis: performing data analysis on the inference result in step S3 to obtain spatial coordinate information of two points, and determining whether the spatial coordinate information of the two points respectively belongs to the inner circle and the outer circle in the cross section of the tubular object;
[0011] S5, if it is recognized in step S4 that the spatial coordinate information of the two points respectively belongs to the inner circle and the outer circle of the tubular object, the dimensional data of the thickness of the tubular object is calculated through the spatial coordinate information of the two points of the tubular object, and the dimensional data of the tubular object is displayed in real time on the screen of the electronic device; if it is not recognized in step S4 that the spatial coordinate information of the two points respectively belongs to the inner circle and the outer circle of the tubular object, the image of this frame is not processed, the dimensional data of the tubular object is not displayed, and the program jumps back to step S3.
[0012] Furthermore, in step S1, the image data of the tubular object in the photographing area is derived from the image data obtained by photographing the cross-sectional profile of the tubular object.
[0013] Furthermore, the step S1 also includes amplifying the collected image data by a data enhancement method of sample transformation, specifically including individual data transformation, multi-instance data synthesis, and adaptive data enhancement.
[0014] Furthermore, step S2 specifically includes the following steps:
[0015] S21, data preparation: split the data set collected in step S1 into the COCO data set, and mark the position coordinate information of the tubular objects in each image;
[0016] S22, model configuration: modify the source code of the YOLOv8 single-stage object detection model and edit the model configuration file to specify the parameters of the model to ensure that the model can show the best performance in the tubular object detection task;
[0017] S23, training model: When training the tubular object detection algorithm model, the learning rate, optimizer parameters and loss function settings are continuously adjusted to achieve the optimal model performance.
[0018] Furthermore, the specific steps of step S3 are:
[0019] S31: Connect the camera to the captured video stream to obtain a number of frame stream image data;
[0020] S32: inputting the one-frame stream image data obtained in step S31 into the tubular object detection algorithm model trained in step S2 to perform tubular object detection, and determining whether a tubular object is detected in the shooting area;
[0021] S33: if a tubular object is detected, go to step S34; if no tubular object is detected, return to step S32 to continue reading the next frame stream image data until all frame stream image data in the video stream are detected;
[0022] S34: If the tubular object detection algorithm model detects one or more circles, it goes to step S32; if two circles are detected, the detection data is used as the inference result and the detection is completed.
[0023] Furthermore, in step S5, the diameter and radius of the tubular object are calculated using the two spatial coordinate information of the tubular object.
[0024] Furthermore, the C2f module is introduced into the backbone network of YOLOv8. The loss function adopts the DFL and Anchor-Free strategies, combining the classification loss BCE Loss and the regression loss CIoU Loss and DFL Loss to ensure the high accuracy of the model in classification and positioning. In order to more accurately match positive and negative samples, YOLOv8 adopts the Task-Aligned Assigner mechanism, and in the later stages of training, YOLOv8 chooses to turn off the Mosaic operation.
[0025] Furthermore, in step S2, in order to improve the detection accuracy of the model, the GSConv module is introduced into the convolutional layer of YOLOv8, and the Slim Neck structure is introduced into the Neck module of YOLOv8.
[0026] Furthermore, the formula used in the training process of the tubular object detection algorithm model is as follows:
[0027] Precision: Precision = TP / (TP+FP);
[0028] Recall: Recall = TP / (TP+FN);
[0029] F1 value: F1=2*(Precision*Recall) / (Precision+Recall);
[0030] Accuracy: Accuracy = (TP + TN) / (TP + TN + FP + FN);
[0031] Class average precision AP: AP = Precision;
[0032] Among them, TP represents true positive samples, FP represents false positive samples; FN represents false negative samples; TN represents true negative samples;
[0033] The formula for average precision mAP is as follows:
[0034]
[0035] Where C represents the total number of categories, AP i represents the AP value of the i-th category;
[0036] The formula of regression loss function CIoU Loss is L IOU :
[0037] In the formula, IOU is the intersection-union ratio, A∩B represents the intersection area of the real box and the predicted box, and A∪B represents the union area of the real box and the predicted box.
[0038] When the bounding boxes do not overlap, L IOU The derivative of the overlapping area Wi is equal to 0, that is:
[0039] H i is the weight value;
[0040] Classification loss function L cls Using cross entropy loss, also known as logarithmic loss:
[0041]
[0042] Where C is the total number of categories, y iis the one-hot encoding of the true label, indicating the true value of the i-th category; P i is the probability of the i-th category predicted by the model;
[0043] Positioning loss function L iou Used to measure the overlap between the predicted box and the true box:
[0044]
[0045] Among them, area(intersection) represents the overlapping area of the predicted box and the real box, and area(union) represents the minimum enclosing rectangular area of the predicted box and the real box;
[0046] The regression function DFL Loss formula is mainly the following two formulas:
[0047] QDL(σ)=-|y-σ| β ((1-y)log(1-σ)+ylog(σ));
[0048] Where y is the formula L IOU The value of; σ represents a distance position; β represents the coefficient;
[0049] DFL(S i ,S i+1 )=-((y i +1-y)log(S i )+(yy i )log(S i +1));
[0050] Among them, S i and S i+1 Represent the model parameters when the i-th and i+1-th data points are observed, respectively, and y is the predicted value estimated based on the observations before the i-th data point; y i and i+1 are the i-th and i+1-th observations respectively; the - sign in the formula indicates that DFL is a loss function or cost function, and the smaller its value is, the more accurate the model prediction is; S i and S i+1 It is the natural logarithm of the model parameters. This form is commonly used in various statistical and machine learning algorithms to smooth parameter updates or assign different weights.
[0051] The classification function BCE Loss formula is LOSS:
[0052] LOSS=-(ylog(p(x)+(1-y)log(1-p(x))
[0053] Where p(x) is the model output and y is the true label;
[0054] The total loss function is used to calculate the total loss of a model, which is used to guide the training and optimization of the model:
[0055] L total =λ cls L cls +λ loc L iou +λ obj L Obj +L dot
[0056] L total : represents the total loss, which is the goal to be optimized. When training the model, try to make L total Minimize the value of
[0057] L cls is the classification loss function;
[0058] L iou is the regression loss function;
[0059] λ cls ,λ loc ,λ obj is the weight coefficient;
[0060] L Obj is the target confidence loss function;
[0061] L dot Represents other loss terms, namely, the classification loss function BCE Loss and the regression loss functions CIoULoss and DFLLoss.
[0062] Furthermore, the thickness of the tubular object is calculated using the following method:
[0063] First, the spatial coordinate information of the two points automatically identified by the YOLOV8 algorithm is substituted into the following formulas to calculate the radius R of the inner circle and the outer circle of the tubular object respectively: b :
[0064]
[0065] Among them, l 0 It is the coordinate position information of the point automatically identified by the YOLOV8 algorithm, and λ is a pixel distance coefficient;
[0066] Finally, the calculated radii of the inner circle and the outer circle of the tubular object are substituted into the following formula to obtain the thickness of the tubular object:
[0067] TH=(Rr)λ j
[0068] Where R is the radius of the outer circle, r is the radius of the inner circle, and λ j is a realistic distance coefficient.
[0069] Due to the adoption of the above technical solution, the present invention has the following beneficial effects:
[0070] The YOLOv8-based intelligent detection and identification method for tubular object thickness of the present invention automatically identifies tubular objects such as bamboo tubes through a tubular object target detection algorithm model, determines the position of the tubular object to obtain the coordinate information of the tubular object, and calculates the dimensional data of the thickness of the tubular object through the coordinate information of the tubular object. Compared with the traditional manual measurement method, the present invention can automatically measure the thickness of the tubular object, which is beneficial to improving the efficiency of tubular object thickness detection.
[0071] Compared with the prior art, the YOLOv8-based intelligent detection and recognition method for tubular thickness of the present invention adopts the advanced YOLOv8 as the basic target detection model, and introduces the GSConv module in the convolution layer of YOLOv8 to enhance the lightweight characteristics and efficiency of the model, and introduces the Slim Neck structure in the Neck module of YOLOv8 to optimize the feature fusion process, thereby improving the accuracy and recall rate. The present invention significantly improves the accuracy and robustness of the model in the tubular detection task, effectively reduces the false detection rate, enables the model to more accurately identify the tubular in the shooting area, and greatly improves the performance of the tubular target detection model in specific scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0072] Figure 1 The present invention is a flowchart of a method for intelligently detecting and identifying thickness of tubular objects based on YOLOv8 according to a preferred embodiment of the present invention. DETAILED DESCRIPTION
[0073] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0074] It should be noted that when a component is referred to as being "fixed to" another component, it may be directly on the other component or there may be a component centered therein. When a component is considered to be "connected to" another component, it may be directly connected to the other component or there may be a component centered therein. When a component is considered to be "set on" another component, it may be directly set on the other component or there may be a component centered therein. The terms "vertical", "horizontal", "left", "right" and similar expressions used herein are for illustrative purposes only.
[0075] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used herein in the specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The term "and / or" used herein includes any and all combinations of one or more related listed items.
[0076] See also Figure 1 A preferred embodiment of the present invention provides a method for intelligent detection and identification of tubular thickness based on YOLOv8, comprising the following steps:
[0077] S1, collecting data to create a data set: collecting image data of the tubular object in the shooting area, and then marking the outer circle and inner circle contours of the cross section of the tubular object in the collected image to create a data set.
[0078] In the present embodiment, the tubular object is a bamboo tube. For example, a data collection method can be used to shoot the bamboo tube using a professional camera to ensure that clear and diverse images of the tubular object are obtained. Alternatively, a data set publicly available on the Internet can be used. Although there are fewer data sets specifically for bamboo tubes, you can try to search for public data sets related to bamboo tubes and bamboo products on the Internet, and filter out pictures containing bamboo tubes. If the public data set is insufficient, you can consider making your own data set. You can create your own bamboo tube data set by purchasing or collecting photos of bamboo tubes of different styles and colors, and adjusting different lighting and angles. In the present embodiment, in step S1, the image data of the tubular object in the shooting area is derived from the image data obtained by shooting the cross-sectional profile of the tubular object; tangent squares can be used to standardize the outer circle and inner circle of the cross-sectional area of the tubular object.
[0079] After obtaining the image data, it is necessary to perform fine image annotation, including accurately marking the location (through a bounding box) and category (such as tubular objects of different materials and uses) of the tubular objects in the image. In addition, in order to increase the diversity of the data set and the robustness of the model, the image data can be appropriately enhanced, such as rotation, scaling, cropping, color conversion, etc. In addition, the step S1 also includes amplifying the image data by a data enhancement method of sample transformation, specifically including individual data transformation, multi-instance data synthesis, and data enhancement of adaptive data enhancement.
[0080] S2, build a data set and train a model: select the single-stage target detection model YOLOv8 of the YOLO series as the tubular target detection algorithm model, use the data collected in step S1 to build a COCO data set, and use the COCO data set to train the tubular target detection algorithm model to obtain a tubular target detection algorithm model that can identify and locate the contour of the tubular.
[0081] In step S2, the production of the COCO dataset refers to dividing the images obtained in step S1 into a training set, a test set, and a validation set.
[0082] In this embodiment, in order to improve the accuracy of the tubular object detection algorithm model, YOLOv8 is used as the basic model for target detection. As the latest version released by Ultralytics, YOLOv8 is based on the previous successful YOLO version and introduces new features and improvements, such as a new backbone network, Ancher-Free detection head and a new loss function, so that it has higher performance and flexibility. The pre-trained model of YOLOv8 includes five different sizes of n, s, m, l and x, which can be selected according to specific needs, and the backbone network part of YOLOv8 introduces the C2f module to improve the operation efficiency of the model; the loss function adopts the DFL and Anchor-Free strategies, combined with the classification loss BCE Loss and the regression loss CIoU Loss, DFLLoss, to ensure the high accuracy of the model in classification and positioning; in order to more accurately match positive and negative samples, YOLOv8 adopts the Task-Aligned Assigner mechanism, and in the later stage of training, YOLOv8 chooses to turn off the Mosaic operation. This strategy helps the model converge better and improves the overall performance.
[0083] In order to improve the detection accuracy of the model, the embodiment of the present invention also improves the single-stage target detection model YOLOv8 of the selected yolo series. Specifically, the embodiment of the present invention introduces the GSConv module in the convolution layer of YOLOV8 and introduces the Slim Neck structure in the Neck module of YOLOv8 to optimize the training process and improve the detection performance. GSConv, as an advanced lightweight convolution technology, combines the advantages of standard convolution (SC) and depth separable convolution (DSC), and realizes the effective fusion of channel information through shuffle operation. Compared with standard convolution, the computational complexity of GSConv is significantly reduced, which is about 50% of standard convolution, thereby effectively reducing the computational cost of the model, and can more effectively extract feature information in the image, especially those details that are crucial to the positioning of the bounding box, which helps YOLOv8 to more accurately locate the target bounding box during the detection process, reduce false detection and missed detection, and significantly improve the accuracy of detection. The Neck module is a key part for feature fusion in YOLOv8. It usually adopts structures such as FPN (feature pyramid network) and PAN (path aggregation network) to achieve effective fusion of features of different scales. The embodiment of the present invention introduces the Slim Neck structure in the Neck module of YOLOv8. As a lightweight feature fusion network, Slim Neck adopts a new feature fusion strategy to greatly reduce the calculation amount and parameter amount of the model while ensuring the accuracy of the model.
[0084] The formula used in the training process of the tubular object detection algorithm model is as follows:
[0085] Precision: Precision = TP / (TP+FP);
[0086] Recall: Recall = TP / (TP+FN);
[0087] F1 value (F1-Score): F1=2*(Precision*Recall) / (Precision+Recall);
[0088] Accuracy: Accuracy = (TP + TN) / (TP + TN + FP + FN);
[0089] Class average precision AP: AP = Precision;
[0090] Among them, TP represents true positive samples, FP represents false positive samples, FN represents false negative samples, and TN represents true negative samples.
[0091] The formula for average precision mAP is as follows:
[0092]
[0093] Where C represents the total number of categories, AP i Represents the AP value of the i-th class.
[0094] The formula of regression loss function CIoU Loss is L IOU :
[0095] In the formula, IOU is one of the loss functions, A∩B represents the intersection area of the real box and the predicted box, and A∪B represents the union area of the real box and the predicted box;
[0096] When the bounding boxes do not overlap, L IOU The derivative of the overlapping area Wi is equal to 0, that is:
[0097] H i is the weight value.
[0098] Classification loss function L cls Cross-Entropy Loss, also known as Logarithmic Loss, is used. The classification loss function is usually used to calculate the difference between the target category probability distribution predicted by the model and the true category label, and guide the model parameter optimization through the back propagation algorithm to reduce this difference:
[0099]
[0100] Where C is the total number of categories, y i is the one-hot encoding of the true label, indicating the true value (0 or 1) of the i-th category; P i is the probability of the i-th category predicted by the model.
[0101] The cross entropy loss function evaluates the performance of the model on the classification task by comparing the difference between the probability distribution predicted by the model and the probability distribution of the true label. When the model prediction is accurate (that is, the predicted probability distribution is close to the true label), the loss value is small; conversely, when the prediction is inaccurate, the loss value is large. By continuously optimizing this loss function during the training process (that is, minimizing the loss value), we can gradually improve the accuracy of the model on the classification task.
[0102] Positioning loss function L iou Used to measure the overlap between the predicted box and the true box:
[0103]
[0104] Among them, area(intersection) represents the overlapping area of the predicted box and the real box, and area(union) represents the minimum enclosing rectangular area of the predicted box and the real box.
[0105] The positioning loss function is a key component used to measure the difference between the bounding box position predicted by the model and the actual bounding box position. It is usually calculated using Mean Squared Error (MSE) or its variants (such as square root error loss) to evaluate the accuracy of the model in target positioning by comparing the differences between the center coordinates, width and height of the predicted box and the corresponding values of the real box.
[0106] The regression function DFL Loss formula is mainly the following two formulas:
[0107] QDL(σ)=-|y-σ| β ((1-y)log(1-σ)+ylog(σ));
[0108] Where y is the formula L IOU The value of; σ represents a distance position; β represents the coefficient;
[0109] DFL(S i ,S i+1 )=-((y i +1-y)log(S i )+(yy i )log(S i +1));
[0110] Where S i and S i+1 Represent the model parameters when the i-th and i+1-th data points are observed, respectively, and y is the predicted value estimated based on the observations before the i-th data point; y i and i+1 are the i-th and i+1-th observations respectively; the - sign in the formula indicates that DFL is a loss function or cost function, and the smaller its value is, the more accurate the model prediction is; S i and S i+1 It is the natural logarithm of the model parameters. This form is commonly used in various statistical and machine learning algorithms to smooth parameter updates or assign different weights.
[0111] The classification function BCE Loss formula is LOSS:
[0112] LOSS=-(ylog(p(x)+(1-y)log(1-p(x))
[0113] Where p(x) is the model output and y is the true label.
[0114] The total loss function is used to calculate the total loss of a model, which is used to guide the training and optimization of the model.
[0115] L total =λ cls L cls +λ loc L iou +λ obj L Obj +L dot ;
[0116] L total : represents the total loss, which is the goal to be optimized. When training the model, try to make L total Minimize the value of
[0117] L cls is the classification loss function;
[0118] L iou is the regression loss function;
[0119] λ cls ,λ loc ,λ obj is the weight coefficient used to balance the importance of different loss terms;
[0120] L Obj The target confidence loss function is a key indicator for measuring the accuracy of the model's prediction of whether the target exists or not. This function is usually implemented by calculating the difference between the target existence probability predicted by the model and the true label. The commonly used method is binary cross-entropy loss. Specifically, for each predicted box in the image, the model calculates the probability of it containing the target and compares it with the true label (i.e., whether the target actually exists at this location). By minimizing this difference, the model parameters are optimized, thereby improving the model's ability to distinguish between real targets and background areas in target detection tasks.
[0121] L dot Represents other loss terms, namely, the classification loss function BCE Loss and the regression loss functions CIoULoss and DFLLoss.
[0122] Therefore, the meaning of the whole formula is: a weighted sum of a loss term related to IoU and a regularization loss term, which is adjusted by cls ,λ loc ,λ obj The value of is used to control the balance between the optimization of these three different loss terms.
[0123] When building and training the model, you can also consider the following adjustments to optimize the model structure. For example, according to the characteristics of the tube, you can fine-tune the YOLOv8 backbone network or detection head to better capture the characteristics of the tube. Data enhancement strategy. During the training process, use appropriate data enhancement strategies to simulate changes in actual scenes, such as lighting changes, occlusion, etc., to improve the generalization ability of the model. Hyperparameter adjustment. According to the characteristics of the dataset and the performance of the model, adjust the hyperparameters such as learning rate, batch size, and number of training rounds to obtain better training results. Verify and evaluate the obtained model. Use an independent validation set to regularly evaluate the model to capture the performance changes of the model and adjust the training strategy. If necessary, you can also collect some test data in actual scenes to evaluate the practicality of the model. Through the above steps, we can build and train an efficient and accurate detection model for tubes, which provides strong support for subsequent tube detection tasks.
[0124] In this embodiment, the training steps of the tubular object detection algorithm model are:
[0125] S21, data preparation: split the data set collected in step S1 into the COCO data set, and mark the position coordinate information of the tubular objects in each image;
[0126] S22, model configuration: modify the source code of the YOLOv8 single-stage object detection model, edit the model configuration file to specify the various parameters of the model, including network structure, training strategy, loss function settings, etc., to ensure that the model can show the best performance in the tubular object detection task;
[0127] S23, training model: When training the tubular object detection algorithm model, the learning rate, optimizer parameters and loss function settings are continuously adjusted to achieve the optimal model performance.
[0128] S3, model reasoning: connect the tubular object detection algorithm model to the real-time video stream for real-time reasoning to determine whether there is a tubular object in the shooting area. If the tubular object detection algorithm model does not detect the existence of a tubular object in the image of the shooting area or detects the existence of one or more circles in the image, continue to reason on the next frame stream image obtained by shooting; if it is detected that there is a tubular object and two circles in the image of the shooting area, use the detection data as the reasoning result and the detection is completed.
[0129] In this embodiment, the specific steps of step S3 are:
[0130] S31: Connect the camera to the captured video stream to obtain a number of frame stream image data;
[0131] S32: inputting the one-frame stream image data obtained in step S31 into the tubular object detection algorithm model trained in step S2 to perform tubular object detection, and determining whether a tubular object is detected in the shooting area;
[0132] S33: if a tubular object is detected, go to step S34; if no tubular object is detected, go back to S32 to continue reading the next frame stream image data until all frame stream image data in the video stream are detected;
[0133] S34: If the tubular object detection algorithm model detects one or more circles, it goes to step S32; if two circles are detected, the detection data is used as the inference result and the detection is completed.
[0134] S4, result analysis: perform data analysis on the inference result in step S3 to obtain the spatial coordinate information of the two points, and determine whether the spatial coordinate information of the two points respectively belongs to the inner circle and the outer circle in the cross section of the tubular object.
[0135] S5, if it is recognized in step S4 that the spatial coordinate information of the two points respectively belongs to the inner circle and the outer circle of the tubular object, the dimensional data of the thickness of the tubular object is calculated through the spatial coordinate information of the two points of the tubular object, and the dimensional data of the tubular object is displayed in real time on the screen of an electronic device such as a computer; if it is not recognized in step S4 that the spatial coordinate information of the two points respectively belongs to the inner circle and the outer circle of the tubular object, the image of this frame is not processed, the dimensional data of the tubular object is not displayed, and the program jumps back to the step S3, specifically, the program jumps back to the step S32.
[0136] In this embodiment, in step S5, if the inner circle and outer circle of the tubular object are identified in step S4, the diameter and radius of the tubular object are calculated according to the coordinate information of the tubular object, and the dimension data of the diameter and radius of the tubular object are displayed.
[0137] The thickness of the tubular object is calculated using the following method:
[0138] First, the spatial coordinate information of the two points automatically identified by the YOLOV8 algorithm is substituted into the following formulas to calculate the radius R of the inner circle and the outer circle of the tubular object respectively: b :
[0139]
[0140] Among them, l 0 It is the coordinate position information of the point automatically identified by the YOLOV8 algorithm, and λ is a pixel distance coefficient;
[0141] Finally, the calculated radii of the inner circle and the outer circle of the tubular object are substituted into the following formula to obtain the thickness of the tubular object:
[0142] TH=(Rr)λ j
[0143] Where R is the radius of the outer circle, r is the radius of the inner circle, and λ j is a realistic distance coefficient.
[0144] In order to comprehensively evaluate the effects of Slim Neck and GSConv after improvement in the tubular object detection task, the present invention conducts an ablation experiment, and compares the unimproved YOLOV8 model, the YOLOV8 tubular object target detection algorithm model improved by the YOLOV8 model and GSConv, Slim Neck of this embodiment, and the YOLOv8 model improved by EIoU, SIoU, AlphaIoU, FocalEIoU, and Wise-IOU as loss functions, and the results are shown in Table 1. The experimental results show that the YOLOv8 tubular object detection algorithm model of this embodiment has significant advantages in the tubular object detection task, and can effectively improve the accuracy and positioning accuracy of the model.
[0145] Table 1 Ablation experiment results
[0146]
[0147] It can be understood that the tubular object is not limited to a bamboo tube, and it can also be a water pipe, an oil pipe or other tubular object.
[0148] The above description is a detailed description of the preferred feasible embodiments of the present invention, but the embodiments are not intended to limit the scope of the patent application of the present invention. All equivalent changes or modified changes completed under the technical spirit suggested by the present invention should fall within the patent scope covered by the present invention.
Claims
1. A method for intelligent detection and identification of tubular thickness based on YOLOv8, characterized in that: The following steps are involved: S1, collecting data to create a data set: collecting image data of the tubular object in the shooting area, and then marking the outer circle and inner circle contours of the cross section of the tubular object in the collected image to create a data set; S2, build a data set and train a model: select the single-stage target detection model YOLOv8 of the YOLO series as the tubular target detection algorithm model, use the data collected in step S1 to build a COCO data set, and use the COCO data set to train the tubular target detection algorithm model to obtain a tubular target detection algorithm model that can identify and locate the contour of the tubular object; S3, model reasoning: connect the tubular object detection algorithm model to the real-time video stream for real-time reasoning to determine whether there is a tubular object in the shooting area. If the tubular object detection algorithm model does not detect the existence of a tubular object in the image of the shooting area or detects the existence of one or more circles in the image, continue to reason on the next frame stream image obtained by shooting; if it is detected that there is a tubular object and two circles in the image of the shooting area, the detection data is used as the reasoning result and the detection is completed; S4, result analysis: performing data analysis on the inference result in step S3 to obtain spatial coordinate information of two points, and determining whether the spatial coordinate information of the two points respectively belongs to the inner circle and the outer circle in the cross section of the tubular object; S5, if the spatial coordinate information of the two points identified in step S4 respectively belongs to the inner circle and the outer circle of the tubular object, the dimension data of the thickness of the tubular object is calculated according to the spatial coordinate information of the two points of the tubular object, and the dimension data of the tubular object is displayed in real time on the screen of the electronic device; If the spatial coordinate information of the two points is not identified as belonging to the inner circle and the outer circle of the tubular object in step S4, the image of this frame is not processed, the tubular object size data is not displayed, and the program jumps back to step S3.
2. The method for intelligent detection and identification of tubular thickness based on YOLOv8 according to claim 1, characterized in that: In step S1, the image data of the tubular object in the photographing area is derived from the image data obtained by photographing the cross-sectional profile of the tubular object.
3. The method for intelligent detection and identification of tubular object thickness based on YOLOv8 as claimed in claim 1, characterized in that: The step S1 also includes amplifying the collected image data by a data enhancement method of sample transformation, specifically including individual data transformation, multi-instance data synthesis, and adaptive data enhancement.
4. The tubular intelligent thickness detection and identification method based on YOLOv8 as claimed in claim 1, characterized in that: Step S2 specifically includes the following steps: S21, data preparation: split the data set collected in step S1 into the COCO data set, and mark the position coordinate information of the tubular objects in each image; S22, model configuration: modify the source code of the YOLOv8 single-stage object detection model and edit the model configuration file to specify the parameters of the model to ensure that the model can show the best performance in the tubular object detection task; S23, training model: When training the tubular object detection algorithm model, the learning rate, optimizer parameters and loss function settings are continuously adjusted to achieve the optimal model performance.
5. The method for intelligent detection and identification of tubular thickness based on YOLOv8 as claimed in claim 1, characterized in that: The specific steps of step S3 are: S31: Connect the camera to the captured video stream to obtain a number of frame stream image data; S32: inputting the one-frame stream image data obtained in step S31 into the tubular object detection algorithm model trained in step S2 to perform tubular object detection, and determining whether a tubular object is detected in the shooting area; S33: if a tubular object is detected, go to step S34; if no tubular object is detected, return to step S32 to continue reading the next frame stream image data until all frame stream image data in the video stream are detected; S34: If the tubular object target detection algorithm model detects one or more circles, it goes to step S32; if two circles are detected, the detection data is used as the inference result and the detection is completed.
6. The method for intelligent detection and identification of tubular object thickness based on YOLOv8 as claimed in claim 1, characterized in that: In step S5, the diameter and radius of the tubular object are calculated using the two spatial coordinate information of the tubular object.
7. The method for intelligent detection and identification of tubular thickness based on YOLOv8 according to claim 1, characterized in that: The backbone network of YOLOv8 introduces the C2f module. The loss function adopts the DFL and Anchor-Free strategies, combining the classification loss BCE Loss and the regression loss CIoU Loss and DFL Loss to ensure the high accuracy of the model in classification and positioning. In order to more accurately match positive and negative samples, YOLOv8 adopts the Task-Aligned Assigner mechanism, and in the later stages of training, YOLOv8 chooses to turn off the Mosaic operation.
8. The method for intelligent detection and identification of tubular object thickness based on YOLOv8 as claimed in claim 1, characterized in that: In step S2, in order to improve the detection accuracy of the model, the GSConv module is introduced into the convolutional layer of YOLOv8, and the Slim Neck structure is introduced into the Neck module of YOLOv8.
9. The method for intelligent detection and identification of tubular thickness based on YOLOv8 according to claim 1, characterized in that: The formula used in the training process of the tubular object detection algorithm model is as follows: Precision: Precision = TP / (TP+FP); Recall: Recall = TP / (TP+FN); F1 value: F1=2*(Precision*Recall) / (Precision+Recall); Accuracy: Accuracy = (TP + TN) / (TP + TN + FP + FN); Class average precision AP: AP = Precision; Among them, TP represents true positive samples, FP represents false positive samples; FN represents false negative samples; TN represents true negative samples; The formula for average precision mAP is as follows: Where C represents the total number of categories, AP i represents the AP value of the i-th category; The formula of regression loss function CIoU Loss is L IOU : Where IOU is the intersection-over-union ratio, A∩B represents the intersection area of the real box and the predicted box, and A∪B represents the union area of the real box and the predicted box; When the bounding boxes do not overlap, L IOU The derivative of the overlapping area Wi is equal to 0, that is: H i is the weight value; Classification loss function L cls Using cross entropy loss, also known as logarithmic loss: Where C is the total number of categories, y i is the one-hot encoding of the true label, indicating the true value of the i-th category; P i is the probability of the i-th category predicted by the model; Positioning loss function L iou Used to measure the overlap between the predicted box and the true box: Among them, area(intersection) represents the overlapping area of the predicted box and the real box, and area(union) represents the minimum enclosing rectangular area of the predicted box and the real box; The regression function DFL Loss formula is mainly the following two formulas: QDL(σ)=-|y-σ| β ((1-y)log(1-σ)+ylog(σ)); Where y is the formula L IOU The value of; σ represents a distance position; β represents the coefficient; DFL(S i ,S i+1 )=-((y i +1-y)log(S i )+(y-y i )log(S i +1)); Among them, S i and S i+1 Represent the model parameters when the i-th and i+1-th data points are observed, respectively, and y is the predicted value estimated based on the observations before the i-th data point; y i and i+1 are the i-th and i+1-th observations respectively; the - sign in the formula indicates that DFL is a loss function or cost function, and the smaller its value is, the more accurate the model prediction is; S i and S i+1 It is the natural logarithm of the model parameters. This form is commonly used in various statistical and machine learning algorithms to smooth parameter updates or assign different weights. The classification function BCE Loss formula is LOSS: LOSS=-(ylog(p(x)+(1-y)log(1-p(x)) Where p(x) is the model output and y is the true label; The total loss function is used to calculate the total loss of a model, which is used to guide the training and optimization of the model: L total =λ cls L cls +λ loc L iou +λ obj L Obj +L dot ; L total : represents the total loss, which is the goal to be optimized. When training the model, try to make L total Minimize the value of L cls is the classification loss function; L iou is the regression loss function; λ cls ,λ loc ,λ obj is the weight coefficient; L Obj is the target confidence loss function; L dot Represents other loss terms, namely, the classification loss function BCE Loss and the regression loss functions CIoU Loss and DFLLoss.
10. The YOLOv8-based intelligent detection and identification method for tubular object thickness according to claim 1, characterized in that: The thickness of the tubular object is calculated using the following method: First, the spatial coordinate information of the two points automatically identified by the YOLOV8 algorithm is substituted into the following formulas to calculate the radius R of the inner circle and the outer circle of the tubular object respectively: b : Among them, l0 is the coordinate position information of the point automatically identified by the YOLOV8 algorithm, and λ is a pixel distance coefficient; Finally, the calculated radii of the inner circle and the outer circle of the tubular object are substituted into the following formula to obtain the thickness of the tubular object: TH=(Rr)λ j Where R is the radius of the outer circle, r is the radius of the inner circle, and λ j is a realistic distance coefficient.
Citation Information
Patent Citations
Deep learning-based threaded steel tag welding robot 3D visual counting and positioning method
CN115319338A
Fan blade automatic identification method and device based on 3D vision
CN115601669A