Garlic planting posture collecting and processing method and device
By integrating a high-definition camera and a YOLO model into a closed-loop process on the garlic planter, automatic identification and labeling of garlic heads and tails are achieved, solving the problem of low efficiency of manual identification during garlic planting, improving the identification accuracy and consistency of the planter, and supporting the automation and standardization of garlic planting.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-17
- Publication Date
- 2026-04-03
AI Technical Summary
In the existing technology, the orientation and direction of garlic cloves during garlic planting rely on manual labor, which is inefficient, labor-intensive, and makes it difficult to ensure the consistency and accuracy of planting, thus hindering the large-scale and standardized development of garlic cultivation.
High-definition cameras are used to capture real-time seeding video streams. Python scripts are used to segment images and perform data augmentation. Combined with a pre-trained YOLO model, automatic recognition and labeling are performed to form a closed-loop process for model retraining, generating a high-quality dataset that ensures data authenticity and sample diversity.
It achieves efficient automatic identification of garlic bulbs and tails, improves the recognition accuracy and consistency of planters, reduces the cost of manual annotation, ensures the quality of the dataset and the robustness of the model, and supports the automated operation of garlic planters.
Smart Images

Figure CN121789205A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of seeder technology, and in particular to a method and apparatus for collecting and processing garlic planting posture data. Background Technology
[0002] In traditional garlic planting operations, the orientation of garlic cloves—that is, the identification and orientation of the head (bud tip) and tail (root)—is a crucial step. The garlic bud tip must be placed upwards to ensure successful rooting and sprouting, thereby achieving a good emergence rate and final yield. However, this step has long relied heavily on manual labor, which is not only inefficient and labor-intensive, but also makes it difficult to guarantee the consistency and accuracy of planting due to human fatigue and subjective judgment differences, which seriously restricts the large-scale and standardized development of garlic planting. With the deepening of the concepts of precision agriculture and intelligent agricultural equipment, the automation and intelligence of agricultural production have become an inevitable trend. Among them, real-time target detection technology based on computer vision provides a feasible technical path to solve the problem of automatic directional planting of garlic. YOLO, as an advanced and efficient real-time target detection algorithm, can quickly identify specific objects in images and is an ideal choice for developing a vision system for intelligent garlic planters. However, the detection performance of the YOLO model is highly dependent on the quality and specificity of the training dataset; Existing general object detection datasets are insufficient to meet the specific requirements of garlic head and tail recognition. Manually collecting and labeling massive amounts of garlic image samples is not only time-consuming and labor-intensive, but also prone to problems such as inconsistent labeling and data deviation, making it difficult to apply on a large scale in real agricultural scenarios. Therefore, a method and device for collecting and processing garlic planting posture data are proposed. Summary of the Invention
[0003] In view of this, the present invention provides a method and apparatus for collecting and processing garlic planting postures, so as to solve or alleviate the technical problems existing in the prior art, and at least provide a beneficial option.
[0004] The technical solution of this invention is implemented as follows: A method for collecting and processing garlic planting posture data, comprising the following steps: S1. During the operation of the garlic planter, a real-time video stream of planting is collected by a camera installed on the equipment. The video stream records the orientation and position information of the garlic cloves and transmits the video data to a computer for processing. S2. Use a Python script to perform image segmentation on the video, decompose the video into consecutive frame images, and save them in high resolution. S3. Randomly divide the frame images into a training set, a validation set, and a test set; S4. Perform online data augmentation on the training set images, including random scaling, cropping, color dithering, and mosaic enhancement operations; S5. Using a pre-trained YOLO object detection model, perform forward propagation on the frame image. The model output includes bounding box coordinate parameters, object confidence, and probabilities for both the head and root. S6. Perform decoding processing on the model output, converting the predicted tensor into actual pixel coordinates and width and height dimensions through Sigmoid and exponential function operations; S7. Perform non-maximum suppression based on the confidence threshold, remove overlapping detection boxes, and retain only the prediction results with the highest confidence. S8. Convert the retained prediction results into YOLO label format and generate the corresponding label file; S9. Based on the dataset generated in step S8, the YOLO model is retrained, and the weight parameters are updated using transfer learning to obtain the optimized recognition model. S10. The optimized model is used for automatic annotation of new video data, forming a closed-loop process of data collection-model training-automatic annotation-retraining.
[0005] More preferably, the image segmentation process in step S2 uses a frame rate control method to segment frames, ensuring that there are continuous changes in the garlic motion between adjacent frames, in order to expand the sample diversity.
[0006] More preferably, the range of data augmentation parameters in step S4 includes: Scaling ratio: 0.5–1.5; cropping ratio: no more than 20% of image area; color jitter: ±30%.
[0007] More preferably, the output tensor shape of the YOLO model in step S5 is [1, 84, 8400], where 8400 is the number of all anchor box predictions, and 84 is the parameter length of each prediction box, including bounding box coordinates, object confidence, and class probability.
[0008] More preferably, the bounding box decoding method in step S6 includes: Decoding the center coordinates of the bounding box: ; Bounding box width and height decoding: .
[0009] Further preferred, the comprehensive confidence level described in step S7 The calculation method is as follows: in Object confidence, These represent the class probabilities of the head and the root, respectively.
[0010] More preferably, the YOLO tag file in step S8 is generated using a normalized coordinate system, wherein: .
[0011] More preferably, the retraining of the model in step S9 adopts a transfer learning approach, using weights pre-trained on a dedicated dataset for initialization.
[0012] More preferably, the retraining of the model in step S9 adopts a transfer learning approach, using weights pre-trained on a dedicated dataset for initialization.
[0013] In a further preferred embodiment, the teacher model in the closed-loop process described in step S10 is used to automatically annotate the newly acquired video data, and the generated newly annotated dataset is used again to train a higher-performance model.
[0014] The present invention also provides an apparatus for collecting and processing garlic planting posture data, comprising: The video acquisition module is used to acquire video in real time from a camera installed on the garlic planter; The image framing and preprocessing module is used to segment the video and perform normalization processing; The model inference module is used to perform the forward propagation of the YOLO model; The output decoding and nonmaximum suppression module is used to reconstruct the bounding box and filter high-confidence results; The label generation module is used to convert prediction results into YOLO format label files; The model training module is used for transfer learning based on the generated dataset; The closed-loop update module is used to achieve automatic model annotation and continuous iterative updates.
[0015] The embodiments of the present invention have the following advantages due to the adoption of the above technical solutions: I. This invention achieves real-time video capture in the field by integrating a high-definition camera onto a garlic planter. The acquired image samples are entirely derived from real agricultural production environments. The dataset naturally includes diverse lighting conditions, different soil textures and backgrounds, and complex scene factors such as the posture changes and slight blurring of garlic cloves during movement. At the same time, the system can collect garlic samples of different varieties, sizes, and shapes, forming a highly representative data distribution. The data authenticity and sample diversity ensured are impossible to achieve through artificial staging or laboratory photography, and can significantly improve the generalization ability and robustness of the YOLO model in practical applications.
[0016] Second, this invention utilizes a pre-trained YOLO model for automatic recognition and classification, realizing automatic image annotation and label file generation, which greatly improves annotation efficiency. Machine annotation strictly follows algorithm rules and unified format specifications, ensuring the consistency and accuracy of bounding box coordinates and category labels, avoiding common errors and deviations in manual annotation, and fundamentally guaranteeing the quality of the dataset.
[0017] Third, this invention forms a complete closed-loop process from field data collection, automatic identification and labeling, model retraining to deployment and updates. Once the system is built, it can continuously generate new labeled data without human intervention, achieving dynamic expansion and optimization of the dataset at extremely low marginal cost. As the seeder continues to operate, the system will continuously accumulate samples and update the model, enabling the model to automatically adapt to different sowing environments and variety conditions and continuously improve accuracy.
[0018] The above overview is for illustrative purposes only and is not intended to be limiting in any way. In addition to the illustrative aspects, embodiments, and features described above, further aspects, embodiments, and features of the invention will become readily apparent from the accompanying drawings and the following detailed description. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 This is a flowchart of the steps of the present invention. Detailed Implementation
[0021] In the following description, only certain exemplary embodiments are briefly described. As those skilled in the art will recognize, the described embodiments can be modified in various ways without departing from the spirit or scope of the invention. Therefore, the drawings and description are considered to be exemplary in nature and not restrictive.
[0022] The embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0023] like Figure 1As shown, this embodiment of the invention provides a method for collecting and processing garlic planting posture data. By constructing a fully automated data preparation process from real operation video acquisition, automatic image framing, YOLO model recognition, output decoding, non-maximum suppression to automatic generation of label files, it achieves efficient and standardized generation of garlic head and tail recognition datasets, providing basic data support for improving the positive germination rate of garlic planters. This invention utilizes an embedded camera to capture raw video streams of field sowing, converts the video into frame images using a Python script, and then uses a pre-trained YOLO model for automatic recognition and annotation, automatically generating label files that meet the training requirements. Based on transfer learning, the model is retrained, ultimately forming a sustainable self-updating closed-loop system. This enables the continuous generation of high-quality labeled datasets with extremely low human cost, thereby significantly improving the model's recognition accuracy and increasing the seeding rate of seeders in the long term.
[0024] The method of the present invention includes the following steps: S1. Install a high-definition industrial camera above the working area of the garlic planter. The camera's field of view covers the garlic clove feeding channel and the planting site, and is used to capture information on the garlic's fall, posture, and head and tail orientation in real time. The camera frame rate is set to 20–30fps, the preferred resolution is 1920×1080 pixels, the output format is MP4 or AVI, and the encoding format is H.264. The video stream is transmitted to a computer or embedded processor via a data interface (USB 3.0 or GigE) to form the original video sequence V.
[0025] S2. Use a Python script to perform image segmentation on the video, decompose the video into continuous frame images, and save them in high resolution; the image segmentation process uses a frame rate control method to segment frames to ensure that there are continuous changes in garlic movement between adjacent frames, in order to expand the sample diversity.
[0026] S3. Randomly classify the frame images and create three folders: training set (train), validation set (val), and test set (test). Typically, the proportion of the training set > the validation set > the test set. In particular, the training set accounts for 70%, the validation set accounts for 20%, and the test set accounts for 10%.
[0027] The training set is used to directly update the model parameters; the validation set is used to monitor the model's generalization ability and adjust hyperparameters during training to prevent overfitting; and the test set is used to finally evaluate the model's performance.
[0028] S4. Perform online data augmentation on the training set images, including random scaling, cropping, color dithering, and mosaic enhancement operations; to facilitate subsequent model processing, the system performs image preprocessing on the video sequence V; each frame of the original image segmented from the video... (Dimensions [H, W, 3]) First, it enters the pre-processing pipeline, which specifically includes: Size scaling: Scale the frame image proportionally to the fixed size [640, 640, 3] of the model input to match the input requirements of the YOLO network; Normalization: Normalizes the pixel value range [0, 255] to the range [0, 1]. The normalization formula is: This process ensures that the input data remains stable within its numerical range, facilitating gradient propagation.
[0029] Tensor transformation: the processed image It is converted into a tensor format with shape [1, 3, 640, 640] and used as input to the YOLO model.
[0030] Preferably, the scaling ratio is 0.5 to 1.5; the cropping ratio does not exceed 20% of the image area; and the color jitter amplitude is ±30%.
[0031] S5. After preprocessing the video frame images, the frame images are input into the pre-trained YOLO model for forward propagation. The model employs a deep convolutional structure, including a backbone network, feature fusion layers, and a multi-scale detection head, to simultaneously detect garlic clove targets of different sizes. The preprocessed tensors... The input is fed into a pre-trained YOLO model, which sequentially extracts features through the backbone network and fuses multi-scale features through the neck layer. The model predicts the target location and class probability through the anchor box mechanism, and the detection head outputs the prediction tensor P. The output P is a three-dimensional tensor of shape [1, 84, 8400], where: 1 represents the batch size; 8400 represents the total number of predicted anchor boxes at different scales; 84 represents the parameter length of each predicted box, which is structured as follows: ; in, For bounding box regression parameters, For object confidence, These are the class probabilities of the head and the root, respectively, satisfying a binary classification relation: This output provides the basic data for subsequent decoding, nonmaximum suppression, and detection.
[0032] S6: Output Decoding and Bounding Box Reconstruction After the forward propagation in step S5, the original tensor P output by the YOLO model is not a directly usable pixel coordinate result. It needs to be converted into real bounding box parameters through a decoding process. To this end, this invention sets up a decoding algorithm module on the system side to convert the parameters in the predicted tensor P into actual bounding box parameters. This is converted into the actual location and class probability of the target in the image. The specific processing steps are as follows: 1. Bounding box center coordinate decoding: For the i-th predicted bounding box, the coordinates of the top-left corner of its grid cell are... ; Model predictions After processing with the Sigmoid function, the coordinates are added to the grid coordinates to obtain the center coordinates relative to the feature map size. The calculation formula is: in, The Sigmoid activation function has an output range of (0, 1). In the formula YOLO employs a coordinate expansion strategy to broaden the prediction range of the center point, ensuring that the center point is not limited to the current grid cell, thereby improving the model's detection accuracy when the target is close to the grid boundary. 2. Bounding box width and height decoding: model prediction With predefined anchor frame size Combined, the final width and height are calculated using an exponential function: This formula ensures that the predicted width and height are always positive, and the scale is proportionally scaled based on the anchor frame size, thus maintaining the reasonableness of the detection frame size.
[0033] 3. Confidence Score and Class Score Calculation: The object confidence score output by the model. Similarly, normalized using the Sigmoid function: For binary classification scenarios (top of garlic bulb and root), the class probabilities are calculated using the Softmax function: in For object confidence, These represent the class probabilities of the head and the root, respectively.
[0034] Through the above decoding process, the center coordinates of each prediction box can be obtained. Width and height The target confidence score and category probability are used to determine the final category, whichever has the higher score.
[0035] S7: Feature Map Post-processing and Bounding Box Selection Non-maximum suppression is performed based on the confidence threshold to remove overlapping detection boxes and retain only the prediction results with the highest confidence. After obtaining the decoded detection boxes, the system directly removes candidate boxes with a confidence level lower than the set threshold (e.g., 0.25) and retains only the potentially valid detection results. Overall confidence level of each detection box Calculate using the following formula: After comprehensive scoring, the nonmaximum suppression process is initiated.
[0036] S71: Non-maximum suppression (NMS) processing To eliminate duplicate detection boxes for the same target, this invention employs the NMS algorithm and performs the following steps: Press the candidate box Sort from highest to lowest; Select the box with the highest score as the baseline, and calculate its intersection-union ratio with the other boxes: like If the value is greater than the 0.5 threshold, the overlapping box is deleted. Repeat the process until all boxes have been processed, and retain the prediction result with the highest confidence.
[0037] Non-maximum suppression is performed based on the confidence threshold to remove overlapping detection boxes and retain only the prediction results with the highest confidence. After NMS filtering, only a few high-quality detection results are retained in each image, and their location and classification information are accurate and reliable.
[0038] S8. After non-maximum suppression (NMS) processing, each frame of the image retains only a few high-quality prediction boxes. The system performs coordinate normalization and file output operations on these detection results, and automatically generates label files that meet the training requirements of the YOLO model. (1) Coordinate normalization: For each retained prediction box, its center coordinates and width and height dimensions are... Normalize the image based on the original image dimensions [W, H], using the following formula: in, The coordinates of the center of the prediction box. The predicted bounding box width and height are defined by W and H, respectively, representing the width and height of the input image. This normalization process ensures that the generated labels have a consistent proportion across images of different resolutions, facilitating unified learning by the model. (2) Label file generation rules: Each prediction box generates a corresponding label row, and the file content follows the YOLO standard format:<class_id><x_center><y_center> <width> <height>; in<class_id> This indicates the category number, where 0 represents the garlic head (top) and 1 represents the garlic root (root). For example, a predicted bounding box identified as "top" corresponds to the label 00.50.50.20.3. The system saves the generated tag file as a .txt file with the same filename as the original image and stores it in the same path as the image file to achieve automatic matching.
[0039] (3) File structure and storage method: Each sample image corresponds to a label file. The system automatically updates or creates three folders: training set (train), validation set (val), and test set (test). Usually, the proportion of training set > validation set > test set. In particular, the training set accounts for 70%, the validation set accounts for 20%, and the test set accounts for 10%.
[0040] Each tag file is stored according to the division of the image set, forming a structured YOLO dataset; This automated process enables the conversion from predicted output to labeled files without human intervention, significantly improving labeling efficiency and standardization.
[0041] (4) Dataset consistency check: To prevent labeling anomalies, the system will automatically verify the label format after generation, including class value range check (whether it contains only 0 or 1) and normalization boundary detection (0≤coordinate≤1). If an abnormal format file is detected, the system will automatically record and regenerate it to ensure the quality and consistency of the entire dataset.
[0042] Through this step S8, the system achieves fully automated generation from detection results to standardized label files, ensuring the uniformity of the training dataset structure and the correctness of the format.
[0043] S9. Retrain the YOLO model using the labeled dataset generated in step S8. Use transfer learning to load the pre-trained weights to accelerate the convergence speed and improve detection performance. Training uses the CIoU loss function with an initial learning rate of 0.001. An adaptive decay strategy is used to prevent overfitting. The validation set is used to monitor changes in the mAP (mean accuracy) metric. Finally, the optimal weights are selected as the optimized model. The retrained model shows a significant improvement in head and tail recognition accuracy. S10. Once the performance of the retrained and optimized YOLO model meets the requirements, it is deployed into the embedded system of the garlic planter as the planter's visual recognition module. During operation, the model receives video frames captured by the camera in real time, identifies the head and tail of each garlic clove, and transmits the recognition results to the control unit, enabling the planter to automatically adjust the garlic clove posture to ensure the sprout tip faces upwards. As the seeder continues to run, the deployed models also act as "teacher models," automatically labeling newly acquired video data and generating new YOLO format label files. The system periodically uses this new data to retrain the model, obtaining a more accurate version, and automatically replaces the old model.
[0044] An apparatus for collecting and processing garlic planting posture data, comprising: The video acquisition module is used to acquire video in real time from a camera installed on the garlic planter; The image framing and preprocessing module is used to segment the video and perform normalization processing; The model inference module is used to perform the forward propagation of the YOLO model; The output decoding and nonmaximum suppression module is used to reconstruct the bounding box and filter high-confidence results; The label generation module is used to convert prediction results into YOLO format label files; The model training module is used for transfer learning based on the generated dataset; The closed-loop update module is used to achieve automatic model annotation and continuous iterative updates.
[0045] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various variations or substitutions within the technical scope disclosed in the present invention, and these should all be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.< / height> < / width>
Claims
1. A method for collecting and processing garlic planting posture data, characterized in that, Includes the following steps: S1. During the operation of the garlic planter, a real-time video stream of planting is collected by a camera installed on the equipment. The video stream records the orientation and position information of the garlic cloves and transmits the video data to a computer for processing. S2. Use a Python script to perform image segmentation on the video, decompose the video into consecutive frame images, and save them in high resolution. S3. Randomly divide the frame images into a training set, a validation set, and a test set; S4. Perform online data augmentation on the training set images, including random scaling, cropping, color dithering, and mosaic enhancement operations; S5. Using a pre-trained YOLO object detection model, perform forward propagation on the frame image. The model output includes bounding box coordinate parameters, object confidence, and probabilities for both the head and root. S6. Perform decoding processing on the model output, converting the predicted tensor into actual pixel coordinates and width and height dimensions through Sigmoid and exponential function operations; S7. Perform non-maximum suppression based on the confidence threshold, remove overlapping detection boxes, and retain only the prediction results with the highest confidence. S8. Convert the retained prediction results into YOLO label format and generate the corresponding label files; update the training set, validation set, and test set. S9. Based on the dataset generated in step S8, the YOLO model is retrained, and the weight parameters are updated using transfer learning to obtain the optimized recognition model. S10. The optimized model is used for automatic annotation of new video data, forming a closed-loop process of data collection-model training-automatic annotation-retraining.
2. The method for collecting and processing garlic planting posture according to claim 1, characterized in that: The image segmentation process in step S2 uses a frame rate control method to divide the frames, ensuring that there are continuous changes in the garlic motion between adjacent frames, in order to expand the sample diversity.
3. The method for collecting and processing garlic planting posture according to claim 1, characterized in that: The range of parameters for data augmentation described in step S4 includes: Scaling ratio: 0.5–1.5; cropping ratio: no more than 20% of image area; color jitter: ±30%.
4. The method for collecting and processing garlic planting posture according to claim 1, characterized in that: The output tensor shape of the YOLO model in step S5 is [1, 84, 8400], where 8400 is the number of all anchor box predictions and 84 is the parameter length of each prediction box, including bounding box coordinates, object confidence and class probability.
5. The method for collecting and processing garlic planting posture according to claim 1, characterized in that: The bounding box decoding method described in step S6 includes: Decoding the center coordinates of the bounding box: ; Bounding box width and height decoding: 。 6. The method for collecting and processing garlic planting posture according to claim 1, characterized in that: The comprehensive confidence level mentioned in step S7 The calculation method is as follows: in For object confidence, and These represent the class probabilities for the head and the root, respectively.
7. The method for collecting and processing garlic planting posture according to claim 1, characterized in that: The YOLO tag file mentioned in step S8 is generated using a normalized coordinate system, wherein: 。 8. The method for collecting and processing garlic planting posture according to claim 1, characterized in that: The retraining of the model in step S9 adopts the transfer learning approach, which uses weights pre-trained on a dedicated dataset for initialization.
9. The method for collecting and processing garlic planting posture according to claim 1, characterized in that: In step S10, the teacher model in the closed-loop process is used to automatically label the newly acquired video data, and the generated new labeled dataset is used again to train a higher-performance model.
10. The apparatus for collecting and processing garlic planting posture data according to any one of claims 1-9, characterized in that, include: The video acquisition module is used to acquire video in real time from a camera installed on the garlic planter; The image framing and preprocessing module is used to segment the video and perform normalization processing; The model inference module is used to perform the forward propagation of the YOLO model; The output decoding and nonmaximum suppression module is used to reconstruct the bounding box and filter high-confidence results; The label generation module is used to convert prediction results into YOLO format label files; The model training module is used for transfer learning based on the generated dataset; The closed-loop update module is used to achieve automatic model annotation and continuous iterative updates.