Next Article in Journal
Transient Stability Enhancement Method for VSGs Based on Power Angle Deviation for Reactive Power Control Loop Modification
Previous Article in Journal
Transformer-Embedded Task-Adaptive-Regularized Prototypical Network for Few-Shot Fault Diagnosis
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Deep Learning-Based Research on Carrot Grading and Sorting System

School of Mechanical Engineering, University of Jinan, Jinan 250022, China
*
Author to whom correspondence should be addressed.
Electronics 2025, 14(19), 3839; https://doi.org/10.3390/electronics14193839
Submission received: 1 September 2025 / Revised: 23 September 2025 / Accepted: 24 September 2025 / Published: 27 September 2025

Abstract

To solve carrot grading problems (low manual efficiency, unquantifiable defects/secondary damage in machinery, gaps in slender carrot (aspect ratio > 4:1) sorting), this study develops a deep learning-based system. Methods: Build CarrotDSTNet (YOLOv8-seg + DeepSORT, optimized via DualConv/SegNeXt) for quality detection; adopt fuzzy comprehensive evaluation for grading; propose CarrotDTNet with an electronic fence for sorting. Results: Detection metrics improved; grading accuracy 94% (0.37 ms); sorting accuracy 97.39%, efficiency 310 roots/min. Contribution: Realizes non-contact, high precision/efficiency sorting, solves traditional issues, and supports carrot industry automation.

1. Introduction

Carrot, as an important economic vegetable rich in vitamins, carotenoids, and trace elements such as calcium and iron, plays a key role in China’s vegetable industry, and China is the world’s largest producer and exporter of carrots [1]. However, due to differences in producing areas, unbalanced planting techniques, insufficient pest control, and non-standard harvesting and transportation, carrots are prone to defects such as greenheads, fibrous roots, breakage, black spots, bending, cracking, and irregular shapes, which directly affect the sales price and cause economic losses to planting enterprises [2]. The current mainstream grading method still relies on manual operation, which has the disadvantages of low efficiency (average processing capacity < 500 roots/hour) and inconsistent subjective judgement standards; while the mechanical sorting equipment can improve the grading accuracy of thickness to 90%, it cannot quantify the surface defects, and the mechanical contact is easy to cause a secondary damage rate of 5–8%. With the breakthrough of deep learning technology, building a non-contact intelligent detection and sorting system has become the key path to solve the industrial bottleneck.
Traditional machine vision relies on manual features (such as HOG, SIFT), and the defect recognition accuracy is <85%, which is difficult to cope with the detection of complex textures such as green heads and cracks of carrots [3]. In recent years, deep learning has shown advantages in agricultural product detection: Ganesh et al. [4] proposed the Deep Orange algorithm, which realized fruit defect detection through pixel-level segmentation (accuracy 97.53%); Ge et al. [5] improved the DCNN model to solve the strawberry occlusion detection (overlap rate 87%); Kang et al. [6] developed a lightweight apple detection model (inference time 28 ms). However, the research on multi-defect quantitative detection and dynamic sorting for the slender shape (length-diameter ratio > 4:1) of carrots is still blank.
In terms of detection technology, Ismail et al. [7] integrated a learning framework to realize fruit freshness detection (apple/banana accuracy 96.7%/93.8%); Matsui et al. [8] combined X-ray and U-net++ to realize avocado rot detection (accuracy 98%); Mirbod et al. [9] used stereo vision and Faster R-CNN to determine apple size measurement (error rate 4.8%). However, the feature’s sparsity and defect overlap caused by the slender characteristics of carrots still require targeted model optimization. For carrots with a slender shape (aspect ratio > 4:1), feature sparsity occurs because, unlike round agricultural products with concentrated features, their surface textures, shape traits, and defects (e.g., fibrous roots) scatter along the length across more pixels, lowering effective feature density per unit area-conventional models (e.g., unoptimized YOLOv8) with receptive fields for feature-concentrated targets fail to extract these scattered features well. Defect overlap arises as defects like fibrous roots and cracks mostly distribute along the length, easily overlapping in imaging pixels; multiple slender carrots interlock when rolling dynamically on the detection conveyor, causing visual overlap between adjacent carrots’ defects and the current carrot’s normal areas, interfering with accurate defect identification.
In terms of grading algorithms, Gurubelli et al. [10] proposed the FF2DLDA algorithm combined with SVM to realize pomegranate grading (accuracy 99.4%), Momeny et al. [11] improved CNN to increase the cherry grading accuracy to 99.4%, and Behera et al. [12] used VGG19 transfer learning to realize papaya grading (accuracy 100%) Existing methods mostly rely on the “detection that grading” strategy, lack the integration of quantitative indicators such as defect area ratio, and have insufficient versatility.
In the sorting technology, Baigvand et al. [13] developed a fig sorting system (efficiency 90 kg/h), Sofu et al. [14] designed an apple sorting line (accuracy 96%), and Wang et al. [15] proposed a mushroom sorting strategy (speed 102 pieces/minute, error rate 2.58%). However, the contact actuator is easy to damage the carrots, and the multi-target tracking miss rate is >5%, which is difficult to meet the industrial needs.
Aiming at the above problems, this study proposes an improved scheme: aimed at the prominent limitations of existing carrot grading and sorting methods, this study first conducts an in-depth analysis. The mainstream manual grading has low automation (processing capacity < 500 roots/hour), poor efficiency, strong subjective interference and inconsistent standards, which cannot meet the needs of large-scale production; although traditional mechanical sorting can improve the thickness grading accuracy to 90%, it cannot quantify defects such as green heads and fibrous roots, and mechanical contact easily causes 5-8% secondary damage to carrots. Traditional machine vision relies on manual features such as HOG and SIFT for defect detection, with an accuracy of less than 85%, which is difficult to cope with complex textures; although existing deep learning methods have made progress in agricultural product detection, they cannot adapt to the slender morphology of carrots (aspect ratio > 4:1)-failing to solve feature sparsity and defect overlap, lacking multi-defect quantitative detection schemes, and having a multi-target tracking miss rate of over 5% in dynamic sorting. In addition, contact actuators in sorting easily damage carrots, and there is a disconnect between detection and sorting systems, making integrated non-destructive sorting difficult. To address these pain points, this study proposes targeted improvements and core innovations: In the quality detection link, based on YOLOv8-seg, it integrates the DualConv lightweight module and SegNeXt attention mechanism (enhancing the recognition of weak-feature defects like fibrous roots), fuses DeepSORT and optimizes detection box logic to construct CarrotDSTNet, realizing instance segmentation, tracking, and information matching of moving carrots, while designing a detection frame optimization method to ensure the integration of full-surface information for multi-targets. In the grading link, it first quantifies defects and size, and for the gap that industry standards lack a numerical basis for grade classification, adopts the fuzzy comprehensive evaluation method combined with the interval division method for classification, breaking the “detection equals grading” model. In the sorting link, it fuses YOLOv8 (with DualConv module) and DeepSORT to construct CarrotDTNet, and adds an electronic fence to solve the connection problem between detection and sorting. Experimental verification shows that the system achieves 93.33% grading accuracy, 97.39% sorting accuracy, and 310 roots per minute efficiency, realizing non-contact, high-precision, and high-efficiency automation to meet the industrialization needs of the carrot industry.

2. Detection System and Appearance Detection Algorithm

2.1. Detection System

The carrot quality detection and grading system proposed in this paper uses a modular concept in the hardware architecture design, which is divided into two independent subsystems with clear functions: detection equipment and sorting equipment, and the organic integration and collaborative scheduling of each hardware module are realized through the independently developed software system to ensure the seamless connection of detection and sorting functions. Aiming at the problem that the detection speed lags behind the sorting speed in practical applications, this study improves the processing efficiency by building a multi-modular detection equipment array. The system architecture diagram is shown in Figure 1. This paper is designed for the use scenarios of a single detection equipment module and a single sorting equipment module.
The industrial computer used in the system is Tuolang (Shenzhen, China) IBOX-602-GT. The programmable logic controller (PLC) is Siemens (Beijing, China) S7-1214C (14DI/10DQ/2AI), supplemented with a digital I/O module SM1223 (16DI/16DQ) and a 485 communication signal board CB1241. Two industrial cameras from HIKROBOT (Hangzhou, China) were used: the detection camera (model: MV-CH250-90TC-C-NFNS) and the sorting camera (model: MV-CH120-15TC-M58S-NFNS), paired with MVL-KF1224M-25MP-NS (12 mm focal length) and MVL-KF0814M-12MPE-NS (8 mm focal length) lenses, respectively. An incremental encoder (model: GI58N-011K1R61N; manufacturer: Changchun Guanghui, Changchun, China) was installed on the reducer output shaft of the detection roller conveyor. The conveyor motor is rated at AC220V, 1.5 kW, and is matched with an AC220V 1.5 kW frequency converter that supports RS485 communication. The conveyor motor (AC220V 1.5 kW) was driven by Hollysys (Beijing, China) HGD730-1R5-2B frequency converter (single/three-phase 220 V, 1.5 kW, RS485 Modbus RTU), enabling stepless speed regulation for carrot rotation.
The experimental platform is shown in Figure 2.
According to the system design requirements, the overall architecture of the carrot grading system is designed, which is mainly divided into three parts: mechanical system, vision system, and control system. The mechanical system mainly includes a detection roller conveyor, a sorting conveyor belt, and a sorting mechanism; the vision system includes a quality detection system and a tracking-sorting system; the control system includes hardware parts and software parts. The overall system architecture is shown in Figure 3.

2.2. Carrot Quality Detection Algorithm

In the process of carrot grading and sorting, the primary task is to detect and segment the appearance characteristics and defect information of carrots from the carrot images and track them for grading and sorting. Since there is more than one carrot in the image and it is in a moving state, this brings difficulties to the recognition and extraction of carrot appearance information. The deep learning algorithm can completely detect the appearance defects of carrots, aiming at their real-time detection, and segment the carrots and the defect information in the carrots.

2.2.1. YOLOv8 Object Detection and Instance Segmentation Algorithms

YOLOv8 and its instance segmentation variant (YOLOv8-seg) are highly adapted to carrot quality detection, with shared core architectures and scenario-specific optimizations. Both adopt a three-component structure-Backbone, Neck, and Head-tailored for agricultural targets. The Backbone extracts multi-scale features via ConvM, C2f, and SPPF modules: the C2f module retains fine-grained details of slender carrots and small defects (e.g., fibrous roots) through residual connections, while the SPPF module fuses multi-scale information to capture both local defects and overall morphology. The Neck uses a feature pyramid to balance shallow detail (e.g., crack edges) and deep semantic features (e.g., green head regions), addressing diverse defect sizes.
For detection, YOLOv8’s Head employs an anchor-free mechanism to adapt to carrots’ variable aspect ratio (length-diameter ratio > 4:1), eliminating manual calibration and ensuring flexible localization. For segmentation (critical for defect quantification), YOLOv8-seg’s Head adds 3 Mask Coefficients feature maps (encoding defect segmentation) and generates a Prototype Mask via the largest-scale input feature map, fusing these with NMS-filtered coefficients yields pixel-level masks, enabling accurate measurement of defect areas (e.g., green head ratio) and sizes (e.g., crack length). Both algorithms balance speed and precision, laying the foundation for subsequent defect recognition and grading.

2.2.2. Improvement of YOLOv8 Instance Segmentation Algorithm

Aiming at the problem that the C2f module in YOLOv8-seg has too large calculation amount and parameter amount due to the deep convolution of the Bottleneck structure, the DualConv lightweight convolution module is introduced to replace part of the ConvM convolution module. The DualConv lightweight convolution module combines the advantages of GroupConv group convolution and HetConv heterogeneous convolution, and simultaneously uses 3 × 3 and 1 × 1 convolutions to process the channel information of the same input feature map. This module uses 3 × 3 convolution to extract the spatial features of the feature map and 1 × 1 convolution to integrate these features, while reducing model parameters [16,17]. The DualConv lightweight convolution structure is shown in Figure 4.
Aiming at the detection problem of defects with unobvious features such as fibrous roots (similar colour and slender shape), the SegNeXt [18] attention mechanism is embedded in the Neck network of the algorithm. The SegNeXt attention mechanism extracts multi-scale features through 1 × 1 convolution and uses these features as attention weights to reweight the input of the MSCA module [19]. In each branch of the MSCA module, two depth strip convolutions are used to approximate the depth convolution of the large kernel. Each branch is set with convolution kernels of sizes 7, 11, and 21, respectively. The depth strip convolution can not only lighten the convolution structure but also serve as a supplement to the grid convolution, which is conducive to extracting the mask of the strip object [20]. Since the defects, such as fibrous roots and cracks of carrots, present a strip shape, introducing the SegNeXt mechanism in the multi-scale structure of the algorithm can effectively improve the segmentation accuracy of such strip defects. The mathematical expression of the MSCA module is shown in Formula (1) and Formula (2).
A t t = C o n v 1 × 1 i = 0 3 S c a l e i D W C o n v F
O u t = A t t F
In the formula, F represents the input feature, A t t and O u t are the attention map and the output, respectively, represents the element-wise matrix multiplication operation, DWConv represents the depth convolution, S c a l e i , i 0,1 , 2,3 , represents the i th branch, and S c a l e 0 is the identity connection.

2.2.3. CarrotDSTNet Carrot Quality Detection Algorithm Based on Deep Learning

In order to realize the efficient detection of carrot quality, this study fully considers the characteristics and advantages of the improved YOLOv8-seg instance segmentation algorithm and combines the stable target tracking performance of the DeepSORT algorithm to carry out in-depth fusion of the YOLOv8-seg instance segmentation algorithm and the DeepSORT target tracking algorithm. Aiming at the actual needs in the real-time detection process of carrots, the fused algorithm is improved and optimized, and then the CarrotDSTNet (Carrot Detection, Segmentation and Tracking Network) carrot quality detection algorithm based on deep learning is proposed. The CarrotDSTNet algorithm integrates three core functions: instance segmentation, target tracking, and information matching, and can realize real-time detection and dynamic tracking of carrot quality information, and real-time and accurately match the detected quality information to the corresponding carrot individual. The CarrotDSTNet network structure is shown in Figure 5.

2.2.4. CarrotDSTNet Algorithm Detection Process

The CarrotDSTNet algorithm preprocesses the images of the detection camera, performs inference and post-processing through YOLOv8-seg to obtain detection boxes, category labels and segmentation masks, inputs the detection boxes of carrots, breaks and irregularities into DeepSORT to generate tracking IDs, and then matches the detection boxes of surface defects such as cracks with the carrot boxes to associate the defects, and stores the labels, detection boxes and other information; at the same time, a detection frame filter (setting a threshold of 100 mm on the left and right edges) is introduced to control the tracking after the carrot is completely in the frame and end the tracking before leaving the frame, so as to solve the problem of tracking jump at the edge of the field of view.

2.2.5. Application Process of CarrotDSTNet Algorithm

The application process of the CarrotDSTNet carrot quality detection algorithm is the working process of the system quality detection link: after the system is started, the detection light source is started, the camera video stream is obtained, the roller conveyor is started, and the start signal is sent to the sorting link; the algorithm runs, and the carrot enters from the right side of the detection camera’s field of view and leaves from the left side. In order to reduce the calculation amount and improve the efficiency, the detection link intercepts n frames (2 ≤ n ≤ 6) of images evenly divided on the side of the carrot for detection, and integrates the results to prepare for the subsequent quantitative processing. After setting n, the circumference of the carrot is divided into n equal parts. After entering the detection range, the first frame is used as the detection result of the first part. The algorithm detects the maximum diameter and calculates the circumference. The system calculates the linear speed of the roller and the rotation of the carrot, generates n − 1 task moments marked with IDs and stores them in the task sequence, compares the frame moment with the task moment in real time, adds the result after matching, releases the task moment, and after the task is completed, integrates the data and temporarily saves it and releases the ID detection data to ensure the stable operation of the system. The process of the carrot quality detection link is shown in Figure 6.
The instance segmentation task of YOLOv8-seg has a long post-processing time, which becomes the main bottleneck of real-time detection and segmentation. In the carrot quality detection, each carrot needs to integrate complete information through the detection results of intercepting n frames (2 ≤ n ≤ 6) of images, and the size difference in different carrots and the moment of entering the detection range are different, resulting in different n-1 task moments and intervals generated. When there are m carrots in the detection and tracking range, with the increase in m, the density of the task sequence increases, which puts forward higher requirements for the hardware calculation performance and the algorithm processing speed. In extreme cases, if the n task moments of a single carrot correspond to consecutive n frames, the system may have detection lag or even missing detection because it cannot process the tasks of other carrots in parallel, affecting the stability and adaptability.
Aiming at the above problems, the study proposes a detection frame optimization method to improve the real-time processing capability by optimizing the task sequence addition logic: after generating the n-1 task moments of each carrot, when the task sequence of the subsequent carrot (such as b) and a certain moment in the existing task sequence (such as a) have an absolute value of the difference Δt ≤ the set threshold T, the same frame detection result is shared, and the two tasks are merged into one processing unit. For example, the task sequence t a 1 , t a 2 , , t a n of carrot is stored in the system first, and the t b 1 , t b 2 , , t b n of carrot b is compared with the system task before adding. If the t between t b i and t a j is ≤ T , the jth frame detection result is shared, reducing an independent task. This method dynamically merges the detection requirements of similar moments, reduces the redundant tasks on the premise of ensuring the detection accuracy, relieves the hardware calculation pressure, and improves the processing capacity of the system for dense targets. Experiments show that this optimization method can effectively reduce the density of the task sequence, avoid detection lag, and enhance the stability and adaptability of the system in multi-target dynamic scenes, providing a feasible path for the efficiency optimization of real-time detection algorithms. The process of the detection frame optimization method is shown in Figure 7.

2.3. Detection Process

As the core link of the detection and grading system, the CarrotDSTNet carrot quality detection algorithm is closely connected with hardware startup and data processing. This study selected “Xinheitian Wucun Shen”, a major processed carrot variety cultivated in China, as the experimental sample. This variety has a typical long conical fleshy root with a uniformly orange-red epidermis, crisp and tender flesh, and low fibre content; the length of a single root ranges from 100 to 300 mm, the maximum diameter from 30 to 80 mm, and the weight of a single root ranges from 80 to 250 g with an average weight of 210 g, which belongs to the mainstream specification type for industrial grading and sorting. A total of 388 images of this variety were initially collected for the dataset from different batches and producing areas, which were augmented to 2328 images through Gaussian blur, random brightness adjustment, random noise addition, etc.; it was randomly divided into a training set (75%), a validation set (15%), and a test set (10%), with samples covering seven typical defects such as greenheads, fibrous roots, and breakages. Static images and dynamic video streams of rolling carrots of this variety were captured by detection cameras to supplement data, and the open-source tool ISAT with segment anything was used for annotation, with labels including seven categories: carrot, carrot-broken, carrot-irregular, green head, fibrousroot, badspot, and crack.
The detection roller conveyor adopts actively mechanically driven rollers to ensure uniform rotation and advancement of carrots. Its drive structure is as follows: both ends of the rollers are meshed with sprockets via chains, and an AC220 V 1.5 kW motor (rated speed 1400 r/min) drives the sprockets to rotate through a reducer, thereby driving the chains and rollers to rotate synchronously. Two friction belts are arranged under the rollers to increase friction, ensuring that the rollers rotate around their own axes while advancing, and driving the carrots between adjacent rollers to rotate synchronously. The actual working speed of the rollers is real-time detected by an incremental encoder (model GI58N-011K1R61N, pulse count 100–10,000 lines) installed on the output shaft of the reducer, with a typical working speed range of 6-8 r/min, and stepless adjustment can be achieved through a frequency converter (AC220 V 1.5 kW, RS485 communication) to adapt to carrots of different sizes. The system collects the roller speed in real-time via the encoder and combines the maximum diameter of the carrot obtained by YOLOv8-seg instance segmentation to calculate the carrot’s rotational linear speed and circumference (approximated as a cylinder). The circumferential direction of the carrot is evenly divided into n equal parts (2 ≤ n ≤ 6), and the moment when each equal part completely enters the camera’s field of view is determined, generating a task sequence containing n-1 moments. This ensures that the number of captured images (n frames) is precisely synchronized with the carrot’s rotation angle-each equal part corresponds to one frame of image, thus completing the full-surface information collection of the carrot.
After the system is started, the detection light source, camera video stream, and roller conveyor are activated synchronously. The sorting link receives the start signal and enters the standby state, and the algorithm starts to run. When the carrot enters from the right side of the detection camera’s field of view and moves to the left, in order to reduce the hardware calculation load and improve the real-time detection efficiency, the system only intercepts n frames (2 ≤ n ≤ 6) of images evenly divided on its side for detection, and forms the complete appearance quality information of the carrot by integrating the detection results of n frames, providing a data basis for the subsequent quantitative grading. In a specific implementation, when the carrot enters the detection and tracking range, the first frame detection result is used as the initial data. The algorithm obtains its maximum diameter through YOLOv8-seg instance segmentation, and calculates the rotation linear speed and circumference of the carrot combined with the rotational speed of the output shaft of the roller conveyor reducer detected by the encoder, so as to determine the moment when each of the n equal parts in the circumferential direction of the carrot completely appears in the field of view, and generate a task sequence including n-1 moments and mark a unique ID. The system real-timely compares the current detection frame moment with the task sequence, and when the time difference is less than or equal to the set threshold T, the current detection result is associated with the detection list of the corresponding ID until the n-frame detection task of the ID is completed, and the data is integrated and temporarily saved and the memory is released to avoid the influence of redundant calculation on the system stability.
Aiming at the real-time detection bottleneck caused by the time-consuming post-processing of the YOLOv8-seg instance segmentation algorithm, as well as the hardware performance pressure induced by the surge of task sequences when multiple carrots are detected simultaneously, the research proposes a detection frame optimization method. The core logic of this method is as follows: when the time difference ∆t between a task moment of a subsequent carrot (e.g., b) entering the detection range and a task moment of a previously entered carrot (e.g., a) is less than or equal to the threshold T, the system shares the detection result of the same frame, and reduces redundant detection tasks by merging similar task moments. Regarding the setting of threshold T, it should be clarified that there is no clear theoretical derivation basis for it; instead, it is determined through multiple rounds of experimental tests in the two documents. In actual detection scenarios with different multi-target densities, after repeated debugging and verification, a recommended optimal value of T is finally confirmed. This value can effectively reduce the number of tasks and alleviate hardware computing pressure while ensuring that the detection accuracy is not significantly affected, thus achieving a dynamic balance between detection efficiency and accuracy. In addition, to adapt to different actual production needs, users can adjust the value of threshold T by themselves according to specific scenario parameters (such as carrot conveying speed, hardware computing power of detection equipment, and actual production requirements for detection accuracy). Practice shows that this detection frame optimization method can effectively reduce the number of detection tasks without reducing detection accuracy, significantly improve the system’s processing capability for dense target scenarios, avoid detection lag or missed detection caused by task queue oGverload, and provide a reliable guarantee for the stability of multi-target dynamic detection.
In the sorting link, based on the CarrotDSTNet technical framework, combined with the improved YOLOv8, the DualConv [21] lightweight module and DeepSORT algorithm are embedded, and the CarrotDTNet carrot sorting algorithm is proposed, which realizes precise sorting through two core modules: one is the detection frame filter, which simplifies the number of detection frame labels to one class according to the requirement that the sorting link only needs to detect the whole carrot rather than the defect type, and filters the invalid detection frames to reduce the calculation load, while the other is the carrot information matching module, which delineates the effective sorting area through the electronic fence, filters the interference of the non-target area, matches the carrot ID generated in real time in the sorting link with the historical ID stored in the quality detection link, and obtains the corresponding quality grade through the information query module to ensure the accurate association between the detection result and the physical position. The specific process is as follows: DeepSORT assigns a unique ID to the carrot entering the sorting area and tracks the position in real time. After the electronic fence confirms that the target is in the effective sorting area, the system matches the double IDs and triggers the pneumatic or mechanical actuator to realize the grading into the basket when the carrot moves to the corresponding sorting position according to the matched quality grade.
Mainstream traditional multi-target tracking algorithms such as DeepSORT, SORT, and ByteTrack adopt a “one target-one task” mode, with computational load growing linearly with the number of targets. SORT relies on Kalman filtering but lacks occlusion robustness; DeepSORT introduces appearance feature matching, which increases computational burden; ByteTrack reduces missed detections by retaining low-confidence boxes but imposes heavier hardware pressure. None of these algorithms is optimized for dense detection scenarios with uniformly moving carrots, easily leading to an imbalance between real-time performance and accuracy. In contrast, the proposed detection frame optimization method identifies task timing correlation (Δt ≤ T) via threshold T, merges adjacent tasks, and shares detection frames, reducing redundant computation from the source. This “temporal merging” strategy differs fundamentally from traditional algorithms: it achieves “computational throttling” without hardware upgrades, avoids detection defects of slender targets through customization for carrot motion characteristics, and realizes task-level integration of detection and tracking by enabling tracking modules to guide task generation, significantly improving adaptability to dense scenarios. The system flow chart and the simplified diagram are shown in Figure 8 and Figure 9.
The two algorithms form a closed loop through “frame-by-frame detection-dynamic task scheduling-cross-link ID collaboration”: CarrotDSTNet captures the defects, such as green heads, fibrous roots, bending, and size information completely while reducing the calculation amount through n-frame time-sharing detection and optimization methods, and the detection frame optimization method makes the system maintain high efficiency in dense target scenarios. CarrotDTNet improves the target tracking stability and anti-interference ability through label simplification and electronic fence technology, and solves the misalignment or damage problem caused by position matching errors in traditional sorting. The measured data shows that this scheme increases the recall rate of small defects such as fibrous roots by 3.8%, the sorting efficiency reaches 310 carrots/minute, and the skin damage rate is controlled within 3%, which is significantly better than manual grading and traditional mechanical sorting.

2.4. Algorithm Effect

2.4.1. Dataset, Training and Effect

This paper uses the open-source tool ISAT (ISAT_with_segment_anything Version 1.3.4.)_with_segment_anything to annotate the instance segmentation dataset. This tool has excellent auxiliary functions, which can greatly improve the annotation efficiency. The labels are set as carrot, carrot-broken, carrot-irregular, green head, fibrousroot, badspot, and crack. The annotation process is shown in Figure 10.
This paper uses a variety of deep learning algorithms such as YOLOv8 [22] and DeepSORT [23] as the methods for detection, tracking and sorting, and uses the fuzzy comprehensive evaluation method as the grading method to sequentially realize the tasks of carrot defect detection, size measurement, grade division, tracking and sorting, etc., and designs and implements a carrot quality detection and grading system.
This paper uses carrots of different batches, different producing areas, and different varieties as samples. It also uses a detection camera to collect images of carrots placed on the detection roller conveyor, and uses the form of continuous interception of the video stream of the rolling carrots to increase the image data. The open-source tool ISAT_with_segment_anything is used to annotate the instance segmentation dataset. This tool has excellent auxiliary functions, which can greatly improve the annotation efficiency. The labels are set as carrot, carrot-broken, carrot-irregular, green head, fibrousroot, black spot, and crack. After completing the dataset annotation, the dataset is randomly divided into a training set, a validation set, and a test set according to the ratio of 0.75, 0.15, and 0.10. The training hardware environment was a server equipped with an Intel Xeon Platinum 8272L CPU, 96 GB of Hynix memory, and an NVIDIA GeForce RTX 3090 graphics card. This system was assembled and configured at the University of Jinan, located in Jinan City, Shandong Province, China. The software environment is Python 3.9.19, Pytorch 2.2.2 + cu121. The main training hyperparameters are as follows: training rounds (epoch) of 400, mask ratio of 1, batch size (batch) of 4, model level of m, optimizer of AdamW (weight decay = 5 × 10−4), initial learning rate of 1 × 10−4, and learning rate decay strategy of cosine annealing (T_max = 400, eta_min = 1 × 10−6).
As shown in Figure 11, training and validation losses (including box, seg, cls, and dfi losses) decrease and stabilize with increasing training epochs, indicating stable training and good generalization. Meanwhile, metrics such as precision, recall, and mAP (e.g., mAP50, mAP50-95) continuously increase and finally converge to high levels. In summary, the model achieves effective convergence during training.

2.4.2. CarrotDSTNet Algorithm Experiment

On the industrial computer, a comparative experiment on instance segmentation speed was separately conducted using the original model and the improved model in this paper on 50 untrained 1920 × 1080 carrot images. The experimental results were averaged and are shown in Table 1 and Table 2.
The instance segmentation speed comparison experiment shows that the improved YOLOv8m-seg model in this paper has a higher overall detection speed than the original YOLOv8m-seg model due to the lightweight improvement, meeting the requirements of real-time detection. This shows that by improving the C2f module of the YOLOv8-seg model with the DualConv lightweight convolution module and adding the SegNeXt attention mechanism in the Neck network, the comprehensive performance of the model is effectively improved while improving the detection speed, and the detection ability of the fibrous root defects with unclear features in the background is also improved.
Not choosing YOLOv5l-seg is because, although YOLOv5l-seg also has certain instance segmentation capabilities, its network architecture (such as the backbone and neck structures) lacks the specific modular design (e.g., the C2f module in YOLOv8-seg) that can be directly and efficiently modified by the proposed DualConv lightweight convolution module and SegNeXt attention mechanism. Moreover, for the detection of fibrous root defects with unobvious features in complex backgrounds, the inherent feature extraction and fusion capabilities of YOLOv5l-seg are less adaptive compared to the improved YOLOv8m-seg, which is customized via targeted architectural optimizations to balance detection speed and the ability to capture fine-grained defect details. Thus, selecting YOLOv8m-seg as the base model is more conducive to achieving the goal of enhancing comprehensive performance while ensuring real-time detection for this specific task.

3. Carrot Appearance Quantification and Grading Algorithm

3.1. Carrot Appearance Information Quantification Algorithm

After the detection and information extraction of the carrot’s appearance, the tracking of the carrot is completed. Then, the detected information is quantified, and the grade evaluation algorithm selected is used to grade the carrot by using the processed information, and the specification division is carried out at the same time. Finally, the carrot sorting algorithm is designed and implemented.

3.1.1. Carrot Size Information Quantification

The carrot size includes length and maximum diameter. Since the horizontal direction of the detection camera’s field of view is parallel to the Advance direction of the roller conveyor, the roller is perpendicular to the horizontal direction of the camera’s field of view, and the axis direction of the carrot is perpendicular to the horizontal direction of the camera’s field of view when the carrot rotates and advances on the roller conveyor, the height and width of the carrot target detection box can be regarded as the length and maximum diameter of the carrot.
According to the industry standard and practice, the ratio of the maximum diameter to the length of the carrot is used as the size index to evaluate the uniformity of the appearance and shape of the batch of carrots. This paper detects and quantifies the n surface information of the carrot, the maximum diameter of a single surface is w k , the length is h k k = 1 , 2 , , n , the maximum diameter and length of the carrot are the average values of the corresponding values of all surfaces, and the size index calculation is as Formula (3):
I n d e x A = k = 1 n w k k = 1 n h k
In the measurement system based on camera imaging, according to the imaging principle, when the surface of the object to be measured deviates from the pre-calibrated plane, the measurement result will inevitably introduce systematic error. In the process of carrot diameter detection, because carrots of different diameters are placed in the middle of the roller, the plane where the maximum diameter is located has a height difference from the camera calibration plane, which makes the detection value of the carrot’s maximum diameter have a systematic deviation from the true value. In order to eliminate the influence of this error on the measurement accuracy, this study constructs a measurement error correction model. The specific schematic diagram of the carrot detection section is shown in Figure 11.
In the measurement error schematic diagram of Figure 12, H 1 ,   H 2 , R , L are known parameters, where H 1 represents the vertical distance from the camera to the calibration plane, H 2 represents the height between the calibration plane and the roller, R is the roller radius, and L is half of the pitch. Let B C be the actual radius r of the carrot, D E be the measured radius d , and B D be the distance x from the carrot axis to the calibration plane. According to the geometric relationship, triangle A B C is similar to triangle A E D , The calculation method is shown in Formulas (4)–(6).
H 1 x r = H 1 2 + d 2 d
According to the following Pythagorean theorem:
x + H 2 + R 2 + L 2 = r + R 2
To simplify the calculation, let S be the following:
S = H 1 + H 2 + R
Combined with the actual situation, and from the above three formulas, this is the following Formula (7):
r = S d H 1 2 + d 2 d 2 R d S H 1 2 + d 2 d R 2 H 1 2 S 2 + L 2 R 2 H 1 2
Through this functional relationship, the actual radius of the carrot can be accurately calculated by using the measured radius value, and then the actual maximum diameter can be obtained, so as to realize the effective correction of the measurement error.
Based on the hardware scheme designed in this study (with H1 = 1000 mm, H2 = 10 mm, R = 32 mm, and L = 25.4 mm), the minimum carrot radius detectable by the system is 9.4 mm. Using the above formula, the curve of the carrot radius measurement error e versus the actual radius r is plotted, as shown in Figure 13. From the trend of the curve in Figure 13, it can be observed that as the actual radius of the carrot increases, the measurement error rises nonlinearly, with its growth rate gradually accelerating. Experiments verify that under the current hardware scheme, after processing the maximum carrot diameter data detected by the camera using this measurement error correction model, the average detection accuracy increases to 98.64% from the original value, 2.62% higher than that before correction.
The experimental results show that when the camera is used to measure the size parameters of the object on the non-calibration plane, the measurement error has a significant impact on the detection result, which will interfere with the subsequent calculation and detection process. Therefore, it is very necessary to establish a measurement error correction model in the relevant measurement system.

3.1.2. Carrot Bending Information Quantification

The degree of bending is an important index to evaluate the quality of carrots. When quantifying the bending information of carrots, the degree of bending of each surface is comprehensively considered, and the maximum bending surface is taken, and its bending degree is quantified as the evaluation index. For the quantitative calculation of the bending degree of a single surface, this paper uses the method of calculating the standard deviation of the offset of the carrot centerline relative to the standard straight line.
In order to accurately measure the degree of bending with this standard deviation, the carrot centerline must be accurately obtained first. The carrot surface mask is obtained by instance segmentation through the CarrotDSTNet algorithm, the mask image is drawn and binarized, and then the centerline is extracted using the image. After obtaining the binarized image of the carrot mask, the centerline can be extracted by the skeletonization algorithm, the distance transformation method, and the horizontal centre point connection method. In the skeletonization algorithm, the Zhang-Suen algorithm [24] has simple pixel deletion conditions, but the skeleton is easy to break in complex cases; the Guo-Hall algorithm has fast convergence and resistance to skeleton-breakage, but is greatly affected by noise. The distance transformation method extracts the ridge line by calculating the distance from the foreground to the background pixels. The adaptive threshold method is fast but has a lot of noise, and the sliding window method can reduce the noise but is inefficient. The horizontal centre point connection method is simple and fast, but the accuracy is poor. The effect diagrams of each algorithm extraction are shown in Figure 14.
Among all the tested centerline extraction algorithms, the Zhang-Suen skeletonization algorithm exhibits a mid-range processing speed. It can extract a relatively complete centreline of the carrot but loses some features at both ends along the length, resulting in the inability to capture the bending trend at the top. The Guo-Hall skeletonization algorithm also has a medium processing speed; although it can extract the centerline of the carrot’s main body, the direction of the centerline at the top deviates from the actual bending trend. The distance transformation method that extracts ridge lines via a sliding window has the slowest processing speed, which is incompatible with the real-time detection requirements of this study. Moreover, its extraction effect is poor-there are multiple breaks in the middle of the centerline, failing to fully reflect the carrot’s bending state. The distance transformation method that extracts ridge lines using an adaptive threshold has the fastest processing speed, but the extracted centerline retains excessive redundant details and shows multiple branching phenomena. It fails to effectively filter out interference noise, which will adversely affect the subsequent calculation of the bending degree. The horizontal centre point connection method has a relatively fast processing speed. However, due to its simple principle and over-reliance on boundary information, it is highly susceptible to noise-induced breakages in the centerline. Additionally, in the top area of the carrot, the extracted centerline cannot truly restore its bending trend.
The experimental dataset contains images of 50 carrots from different regions and batches. The core evaluation metrics include processing speed, centerline integrity, bending fitting error, and noise resistance. Quantitative results show the following: Zhang-Suen algorithm-speed of 55 ± 0.5 ms, integrity of 87.2 ± 2.1%, and fractures of 1.2 ± 0.4 times; Guo–Hall algorithm-speed of 61 ± 0.6 ms, integrity of 92.1 ± 1.8%, and fractures of 0.9 ± 0.3 times; Sliding window distance transform method-speed of 164 ± 1.3 ms, integrity of 78.5 ± 3.2%, and fractures of 3.8 ± 0.7 times; Adaptive threshold distance transform method-speed of 2 ± 0.2 ms, integrity of 89.7 ± 2.5%, and fractures of 2.5 ± 0.6 times; Lateral centre point connection method—speed of 3 ± 0.3 ms, integrity of 82.4 ± 2.8%, and fractures of 2.1 ± 0.5 times. ANOVA analysis indicated that all four metrics had p < 0.001: the sliding window method was comprehensively inferior to other algorithms; the adaptive threshold method had the optimal speed and fitting accuracy but poor noise resistance; there was no significant difference in integrity between the Zhang–Suen and Guo–Hall algorithms (p = 0.28).
Through comparison, the Zhang–Suen skeletonization algorithm has a better comprehensive performance, but it will lose the features in the length direction. For this reason, a preprocessing method is added on the basis of the Zhang–Suen skeletonization algorithm. First, the mask is corroded horizontally with a 0.1 w × 1 rectangular structure element, and iterated 0.05 w times (w is the maximum diameter of the carrot) to weaken the horizontal features and eliminate the noise, and then the Zhang-Suen skeletonization processing is carried out so as to obtain the complete carrot bending feature centreline. The comparison between the improved Zhang–Suen skeletonization algorithm and the original algorithm is shown in Figure 15.
After obtaining the accurate centerline of the carrot surface extracted by the improved Zhang-Suen skeletonization algorithm, this study quantifies the bending degree of the carrot by calculating the standard deviation of the offset of the centerline relative to the standard reference straight line. The standard reference straight line is defined as the connecting line of the first and last endpoints of the centerline. Specifically, for each discrete point on the centerline, the vertical distance from it to the standard straight line is calculated, and then the discrete degree of these distance values is evaluated through statistical analysis to evaluate the bending characteristics of the carrot.
Suppose that the centerline of a single carrot surface is composed of n p k discrete points arranged from top to bottom, where k = 1 , 2 , , n , and n is the number of carrot surfaces detected. For the i th point on the centerline, its coordinates are expressed as ( x i , y i ) , where i = 1 , 2 , , n p k . The standard straight line equation y = a x + b is determined by the first and last endpoints ( x 1 , y 1 ) and ( x n p k , y n p k ) , where the parameters a and b are as follows, and their specific expressions are shown in Formula (8).
a = y n p k y 1 x n p k x 1
b = y 1 a x 1
The vertical distance d i from any point ( x i , y i ) on the centreline to the standard straight line is calculated by the following Formula (10):
d i = y i a x i b 1 + a 2
The average value d ¯ of d i is calculated as the Formula (11):
d ¯ = 1 n p k i = 1 n p k d i
The bending degree of each surface of the carrot is represented by σ k and the calculation is the following Formula (12):
σ k = 1 n p k i = 1 n p k d i d ¯ 2
Finally, the maximum value of the bending degrees of all surfaces is selected as the overall bending degree index I n d e x B of the carrot, I n d e x B as the following Formula (13):
I n d e x B = m a x σ 1 , σ 2 , , σ n

3.1.3. Carrot Green Head Information Quantification

The influence degree of the carrot green head defect is described from two aspects. This paper realizes the overall evaluation of the carrot green head defect by quantitatively calculating the area and height of the carrot green head. The green head area index is described by calculating the proportion of the carrot green head defect area in the carrot, which is represented by IndexC1; the green head height index is described by calculating the ratio of the maximum height of the carrot green head defect to the length of the carrot, which is represented by IndexC2.
The area of the defect-free region of a single surface of the carrot is A r e a C k , and the area of the green head is A r e a G k , where k = 1 , 2 , , n . The calculation of the carrot green head area index I n d e x C 1 is shown in Formula (14):
I n d e x C 1 = k = 1 n A r e a G k k = 1 n A r e a C k + A r e a G k
The green head height of a single surface of the carrot is h G k and the length of the carrot is h k , where k = 1 , 2 , , n . The calculation of the carrot green head height index I n d e x C 2 is shown in Formula (15):
I n d e x C 2 = max h G 1 , h G 2 , , h G n 1 n k = 1 n h k

3.1.4. Carrot Black Spot Information Quantification

The influence degree of the carrot black spot defect is evaluated from two aspects of the black spot area and the maximum black spot area. The black spot area index is described by calculating the ratio of the sum of the black spot areas to the total area of the carrot, which is represented by IndexD1; the maximum black spot area index is described by calculating the ratio of the maximum black spot area to the average area of the carrot surface where it is located, which is represented by IndexD2. The area of the carrot and the black spot defect is extracted by using the segmentation mask of the carrot and the black spot defect.
The ratio of the sum of the black spot areas to the total area of the carrot is shown in Formula (16):
I n d e x D 1 = k = 1 n j = 1 n b k A r e a B k j k = 1 n A r e a C k + j = 1 n b k A r e a B k j
The ratio of the maximum black spot area to the average area of the carrot surface where it is located is shown in Formula (17):
I n d e x D 2 = max A r e a B 11 , , A r e a B k j , , A r e a B n n b n 1 n k = 1 n A r e a C k + j = 1 n b k A r e a B k j

3.1.5. Quantification of Other Information of Carrot

The influence degree of the carrot cracking defect is evaluated from the two aspects of the length and width of the carrot cracking defect. The minimum circumscribed rectangle of the mask is calculated by using the segmentation mask of the carrot cracking defect. Considering that the cracking length is usually greater than the cracking width, the short side of the minimum circumscribed rectangle of the cracking mask is taken as the width of the cracking defect, and the long side is taken as the length of the cracking defect. The extraction of the fibrous root defect information is the same. Considering that the fibrous root length is usually greater than the fibrous root diameter, the short side of the minimum circumscribed rectangle of the fibrous root mask is taken as the diameter of the fibrous root defect, and the long side is taken as the length of the fibrous root defect. The cracking length index is described by calculating the ratio of the maximum length of the carrot cracking defect to the length of the carrot, which is represented by IndexE1; the cracking width index is described by calculating the ratio of the maximum width of the cracking defect to the maximum diameter of the carrot, which is represented by IndexE2. The fibrous root calculation is the same.
The ratio of the maximum length of the carrot cracking defect to the length of the carrot is shown in Formula (18):
I n d e x E 1 = m a x h c 11 , , h c k l , , h c n n c n 1 n k = 1 n h k
The ratio of the maximum width of the cracking defect to the maximum diameter of the carrot is shown in Formula (19):
I n d e x E 2 = m a x w c 11 , , w c k l , , w c n n c n 1 n k = 1 n w k
In addition to the above defects, carrots also have defects such as irregular shapes and breakage. In the carrot processing industry and related industry standards, carrots with irregular shapes, breakage, and other defects are generally classified as unqualified products. Therefore, considering the universality of the grading method, in the grading study, for carrots with irregular shapes and breakage defects, the information quantification processing and grading calculation are not carried out, and they are directly classified as unqualified products.

3.2. Carrot Grading Algorithm

After completing the extraction and quantitative analysis of the carrot quality information, this study carries out the calculation work of the carrot grade and specification based on the obtained various index data, so as to determine its quality grade. For the evaluation of carrot grades, this paper selects three comprehensive evaluation algorithms: fuzzy comprehensive evaluation method, TOPSIS evaluation method, and gray correlation evaluation method. It then carries out adaptive improvement on the algorithms according to the unique attributes of carrot grading, and clarifies the specific implementation process of each algorithm in the carrot grade evaluation. These comprehensive evaluation algorithms only need to set a small number of key parameters before the grade evaluation to complete the carrot grade calculation, showing good flexibility in the actual application scenario. In terms of carrot specification division, this study adopts the interval division strategy, which has a simple calculation process and high execution efficiency, and can effectively meet the actual production needs.

3.2.1. Research on Grading Algorithm

In the field of multi-index comprehensive evaluation, the fuzzy comprehensive evaluation method, TOPSIS algorithm, and gray correlation evaluation method are representative analysis tools, and their principles, applicability, and decision-making logic are different. The core idea of the fuzzy comprehensive evaluation method is to convert the qualitative evaluation into a quantitative evaluation by means of the fuzzy mathematics membership degree theory.
The fuzzy comprehensive evaluation method is often used in the fields of humanities and social sciences, ecological environment protection, engineering management, etc. [25,26]. Its specific implementation process includes determining the evaluation factor set, constructing the fuzzy relation matrix, determining the weight of each factor, carrying out the fuzzy synthesis operation, and obtaining the comprehensive evaluation result. This method can effectively deal with the fuzziness and uncertainty of the evaluation index and has strong applicability in the multi-factor comprehensive evaluation by combining the subjective judgment with the mathematical model.
The TOPSIS evaluation method, also known as the distance method of the best and worst solutions, is a method of sorting according to the proximity of a limited number of evaluation objects to the idealized target, and is a relative Pros and cons evaluation of the evaluation objects [27,28]. As a multi-attribute decision-making tool, this method realizes the sorting through data standardization, weight determination (such as entropy weight method) and closeness calculation, is suitable for the multi-index scenario with complete data (such as engineering scheme comparison), and has the advantages of transparent principle and strong data adaptability, but has the limitations of being sensitive to extreme values and relying on the accuracy of weights.
The gray correlation evaluation method is the application of the gray correlation degree analysis method in the comprehensive evaluation, and is a method of measuring the degree of association between factors by taking the similarity or dissimilarity degree of the development trend between factors as the measure, which can reduce the loss caused by information asymmetry to a certain extent [29,30]. Based on the gray system theory, this method realizes the evaluation by setting the reference sequence, calculating the correlation coefficient and the comprehensive correlation degree, is suitable for the small sample and incomplete information scenario (such as agricultural test data analysis), and has the advantage of loose data requirements, but the objectivity of the result is easily affected by the selection of the reference sequence and the determination of the weight.
In practical applications, the method should be selected according to the data characteristics (sample size, index type) and evaluation objectives (ranking, grading, or risk assessment), and a combined model (such as fuzzy-TOPSIS and gray correlation-entropy weight method) can also be constructed to improve the evaluation robustness. For example, in the agricultural product grading, the fuzzy comprehensive evaluation method can be used to integrate the fuzzy index to realize the grade division, and the TOPSIS algorithm can be used to verify the grading rationality based on the quantitative data, and the scientific validity of the decision-making can be enhanced through the complementarity of the methods.

3.2.2. Experimental Evaluation of Grading Algorithm

In order to ensure the comparability of the experimental results, this study carefully selects 150 carrots of the same batch and poor growth status as the experimental samples before carrying out the experiment. Each of the 150 carrots is detected, and the obtained detection information is quantitatively analyzed to successfully obtain the values of indicators of each carrot. These values will be used as the original experimental data for carrot grading, and the details of part of the data are shown in Table 3.
This paper realizes the programming of the three carrot grade evaluation algorithms through the Python language. The hardware experimental platform is equipped with a 14th generation Intel Core i7-14700K processor, an NVIDIA GeForce RTX 4060 graphics card, and 32 GB of memory. The processor was manufactured by Intel, while the GPU chip on the graphics card is designed by NVIDIA and typically produced by TSMC. The final system integration was completed in China. The three evaluation algorithms realized by programming are used to calculate the grades of 150 pieces of standardized carrot information, respectively. The process information, such as the calculation processing time, is recorded in the process, and the calculation results are finally recorded. At the same time, in order to ensure the comparability of the results, three enterprise experts were invited to calibrate the grades of 150 carrots: All with over 10 years of experience in carrot processing and grading, from the quality control department of large-scale carrot deep-processing enterprises, long engaged in quality control and grading standard formulation. Experts conducted physical evaluation, inspected defects one by one per NY/T 1983-2011 [31], and reached consensus as the “gold standard”. The experiment was repeated three times. The “94% accuracy” of the fuzzy comprehensive evaluation method was calculated as (samples consistent with expert results/total 150) × 100%, being the optimal single result among three repeats, with an average of 93.2% and error ≤0.8%.
The grading results obtained by the fuzzy comprehensive evaluation method, TOPSIS evaluation method and gray correlation evaluation method, and the expert grading results are shown in Table 4.
This study systematically compares the carrot grading results obtained by the fuzzy comprehensive evaluation method, the TOPSIS method, and the gray correlation method with the expert manual grading results. In order to present the grading efficiency of each algorithm more clearly and intuitively, this study draws the distribution trend of the expert grading results in the grading results of the above three algorithms in the form of a line chart, and the specific visualization results correspond to Figure 16, Figure 17, and Figure 18, respectively.
In order to verify the effectiveness of the algorithm, this study compares and analyzes the grade determination results of the fuzzy comprehensive evaluation method, the TOPSIS method, and the gray correlation method with the expert grading results. The results show that the grade determination results of the fuzzy comprehensive evaluation method show the highest consistency with the expert grading results. Although there are some grade differences, these differences are mainly concentrated between adjacent grades, and the occurrence frequency is low, which indicates that this method can make more full use of the index membership degree and weight, so as to more accurately reflect the true quality of the carrot. In contrast, there is a large deviation between the grade determination results of the TOPSIS method and the gray correlation method, and the expert grading, and the phenomenon of cross-grade fluctuation occurs many times. Especially the gray correlation method, its fluctuation range and frequency are significantly higher than the other two methods. Further analysis shows that the TOPSIS method has poor adaptability in processing complex data and is easily interfered with by extreme values, while the gray correlation method is overly sensitive to the Subtle differences in the data, which makes the two methods difficult to accurately reflect the true quality status of the carrot. It can be seen that in the carrot grade evaluation task, the fuzzy comprehensive evaluation method has significant advantages in accuracy and stability and is more suitable for the actual application scenario.
In view of the fact that the carrot quality detection and grading needs to carry out real-time processing on the moving carrots, which puts forward dual requirements for the grading algorithm: it is necessary to have high reliability to ensure the accuracy of the grading result, and also need to have efficient data processing and calculation capabilities to meet the real-time requirements. This study has carried out a quantitative evaluation on the accuracy of the three carrot grade evaluation algorithms relative to the expert grading and the average time consumption of each algorithm to process a single carrot, and the specific results are shown in Table 5.
In the comparative evaluation of the carrot grading algorithm, the fuzzy comprehensive evaluation method shows significant advantages in key indicators such as accuracy and average processing time. Through the comprehensive balance of the grading effect and grading efficiency, this study selects the fuzzy comprehensive evaluation method as the core algorithm for carrot grading. It is worth noting that in the actual industrial application scenario, experts will dynamically optimize and adjust the membership function parameters and weights according to the grading results, so as to further improve the sorting accuracy. Therefore, the accuracy data presented in Table 4 mainly reflects the relative performance differences in the three evaluation methods and cannot be completely equivalent to the final grading accuracy in the actual application scenario.

3.2.3. Interval Division Algorithm

In the field of carrot specification division, the industry common practice is to classify according to the carrot length index combined with the pre-set length grade interval, and this method is widely used in actual production due to its simplicity and high efficiency. This study follows this industry standard and carries out the corresponding algorithm development work.
In order to meet the actual production needs, this study uses the expert experience evaluation method or the random sampling analysis method to divide the carrots of the same batch into n C grades, and constructs the carrot specification set U C = C 1 , C 2 , C n C . At the same time, n C 1 boundary values b m , m = 1,2 , , n C 1 , are set, and n C continuous grading intervals are constructed through these boundary values. According to Section 3.1.1, the length of the carrot is known as h and the specification grade corresponding to it can be determined by judging the interval where h is located. The specific judgement logic is shown in Formula (20):
G r a d e C h = C 1 , h b 1 C m , b m 1 < h b m C n C , h > b n C 1
The specification to which the carrot belongs can be obtained through the formula G r a d e C h . This algorithm is highly consistent with the actual carrot production and processing, has simple and efficient calculation, and ensures the real-time performance of the carrot specification division process.

3.3. Algorithm Synergy

In this study, the CarrotDSTNet algorithm is used to track the carrots, obtain the ID information of the carrots, and finally determine the unique identifier and quality grade of each carrot through the detection equipment. After the carrot leaves the detection equipment and enters the sorting equipment, the sorting equipment will sort the carrot into the corresponding sorting basket according to its quality grade. In this whole process, it is very important to realize the accurate ID matching and continuous tracking of the carrot.

3.3.1. Construction of CarrotDTNet Network

The CarrotDSTNet algorithm deeply integrates the advantages of the YOLOv8-seg instance segmentation algorithm and the DeepSORT target tracking algorithm, which can not only complete the quality detection task of carrots, but also realize the tracking of carrot individuals and assign them unique IDs.
In the carrot sorting operation link, it is necessary to accurately match the carrot ID generated by the detection equipment with the carrot entering the sorting equipment and combine the real-time position information and quality grade of the carrot in the sorting equipment to sort it into the sorting basket corresponding to the quality. In view of this, in the whole carrot sorting process, stable target tracking and accurate information matching of the carrot are indispensable.
Aiming at the special needs of the carrot sorting task, this paper takes the CarrotDSTNet algorithm as a reference, organically combines the YOLOv8 object detection algorithm improved by the DualConv lightweight convolution module with the DeepSORT target tracking algorithm, and innovatively proposes the CarrotDTNet (Carrot Detection and Tracking Network) carrot sorting algorithm based on deep learning.
On the basis of integrating the improved YOLOv8 object detection algorithm and DeepSORT target tracking algorithm, the CarrotDTNet carrot sorting algorithm designs and embeds a detection frame filter (Box Filter). This filter has a similar function to the similar component in the CarrotDSTNet carrot quality detection algorithm, but the number of processing detection frame labels is different—in the CarrotDTNet algorithm, the number of detection frame labels is simplified to one. These optimizations and adjustments are because, in the carrot sorting process, only the detection and tracking of carrots need to be realized, and there is no need to further distinguish the type or defect characteristics of carrots. The network structure details of the CarrotDTNet carrot sorting algorithm are shown in Figure 19.

3.3.2. Electronic Fence Module

In the CarrotDTNet carrot sorting algorithm system, the electronic fence confirmation module plays a key role in ensuring the sorting accuracy. After the carrot is transferred from the detection equipment to the sorting equipment, the accurate matching of its ID information is a necessary prerequisite for obtaining the quality grade and realizing the correct sorting. However, in the actual sorting process, human interference factors may cause a series of problems: the carrot that has not completed the sorting process is taken away by people, or the carrot that has not been detected is put into the sorting equipment in violation of regulations. Such situations will not only lead to the failure of carrot ID matching but also cause a chain reaction to the accurate matching of all subsequent carrots, and finally lead to sorting errors.
In order to effectively deal with the above challenges, under the framework of the CarrotDTNet carrot sorting algorithm, this study innovatively designs an electronic fence confirmation module [32]. The electronic fence is essentially a virtual fence, and its structure layout is shown in Figure 20. In the electronic fence schematic diagram of the CarrotDTNet algorithm shown in Figure 20, the whole area corresponds to the field of view of the sorting camera, and the blue frame line delimits the boundary of the electronic fence. At the connection part of the detection equipment and the sorting equipment, a unique entry safety door is set; at the same time, the corresponding number of exit safety doors is configured in the carrot sorting area.
After the electronic fence is enabled, the system only tracks the carrots that enter the sorting equipment from the entry safety door and always stay within the electronic fence before the sorting is completed. Any carrot that enters the electronic fence from a position other than the entry safety door is determined to be an accidental intrusion and will not be tracked. When the carrot moves to the corresponding sorting area in the electronic fence, the corresponding exit safety door will open automatically to allow the carrot to leave; after the carrot completes the sorting and leaves the electronic fence, the exit safety door will close immediately. If the exit safety door is in the closed state and the carrot leaves from the exit safety door or other areas of the electronic fence, it is determined to be an accidental separation, and the system will immediately terminate the tracking and sorting operation of the carrot.
By introducing the electronic fence confirmation module, the CarrotDTNet carrot sorting algorithm can ensure the accurate matching and smooth connection of the carrot information between the detection equipment and the sorting equipment. This module significantly improves the anti-interference performance of the algorithm and provides a solid guarantee for realizing the accurate sorting of carrots in the sorting equipment.

4. Results

After the construction of the experimental platform is completed, this paper tests the designed and developed carrot quality detection and grading system, tests the stability and reliability of the system, and verifies the system functions. In actual application, the system needs to run for a long time, so the system stability is an important part of the test. For the test of system stability, the main focus is on the memory occupation and video memory occupation of the upper computer software during long-term operation. In the system functions, the core part is the quality detection and grading sorting of carrots. The comprehensive accuracy, efficiency, and precision of carrot detection and grading are important indicators reflecting whether the system functions meet the design requirements. Among them, precision is one of the factors determining the accuracy, so only the comprehensive accuracy and efficiency of the system in detecting and grading carrots need to be tested.
Through the test of the system running continuously for 6 h without interruption, during the operation of the system, the memory occupation of the upper computer software is kept within 4.2 GB, and the video memory occupation is kept within 1.4 GB. Thanks to the reasonable data cleaning and resource release mechanism of the designed and developed upper computer software, even if a large amount of video data is processed, there is no memory leakage or other abnormal conditions. The test shows that the system has the stability and reliability of long-term operation.
Then, the actual detection effect of each detection label of the CarrotDSTNet algorithm is tested, the CarrotDSTNet algorithm is programmed and implemented, and the real machine test is carried out. The test results show that the detection and segmentation performance and processing speed of the algorithm meet the expected requirements, and the target tracking is stable and reliable, verifying the feasibility of the algorithm application. The effect of the CarrotDSTNet algorithm is shown in Figure 21 and Figure 22.
Finally, to test the system’s detection and grading performance, this study used 100 kg of carrots from the same batch, totaling 476 roots, and adopted the optimal grading parameters after multiple adjustments. The detection roller conveyor and sorting conveyor belt both operated at a constant maximum speed. Under the above conditions, an actual production experiment was conducted, and the sorting performance was compared with that of a professional practitioner engaged in the carrot processing industry. This sorting belongs to fine grading, which requires distinguishing between size, defects, etc., so careful appearance inspection is necessary—even skilled practitioners need to fully check the appearance of carrots.
Notably, for carrots with excessive bending, irregular shapes, or breakages, the system implements an automatic classification mechanism: these carrots are directly categorized into the lowest quality grade (or a user-defined “damaged” grade) without additional appearance quality detection. This is because such defects are clearly defined as unqualified in industry standards, and further appearance inspection adds no practical value to grading. The CarrotDSTNet algorithm accurately identifies these defects during the initial detection stage, triggering the direct classification logic to improve processing efficiency.
Measurement protocol for manual sorting efficiency (“27 carrots/minute”): The manual sorting test involved one professional operator with 5 years of carrot processing experience. The experiment was repeated three times (consistent with the system test) to ensure data reliability. The operator used both hands for operation: one hand picked up a single carrot, visually inspected its size and defects, and the other hand placed it into the corresponding grading basket. Each operation cycle targeted one carrot at a time (due to the requirement for fine appearance inspection), and the total processing time and number of correctly sorted carrots were recorded per repetition to calculate average efficiency.
Supplementary notes on sorting efficiency “310 carrots/minute”: This efficiency is calculated based on measured parameters: the optimal conveyor speed is 0.25 m/s, the average carrot spacing is 200 mm (with actual fluctuation of 185–195 mm), and the total response time of the optical system is ≤0.75 ms, derived from the formula “(speed × 60) ÷ spacing”. The experiment was repeated 3 times, with an average efficiency of 389.3 carrots/minute and an error ≤1.3%. Variable controls included random carrot placement, coverage of three size grades (small: ≤150 mm, medium: 150–250 mm, and large: >250 mm), and a fixed roller spacing of 18.8 mm. After testing 5 conveyor speeds (0.15–0.30 m/s), 0.25 m/s was confirmed as the optimal speed, achieving a balanced performance between efficiency and comprehensive accuracy (97.39%).
The carrots were classified into two grades: Special Grade and First Grade, and two specifications: Large Fruit and Small Fruit, resulting in four quality grades in total: Special Grade Large Fruit, Special Grade Small Fruit, First Grade Large Fruit, and First Grade Small Fruit. The correct sorting rate, comprehensive accuracy rate, and efficiency of the two sorting methods for each grade and each specification were counted and calculated. Among them, the correct sorting rate refers to the proportion of carrots belonging to the corresponding grade or specification that are correctly sorted; the comprehensive accuracy rate is the average value of the correct sorting rates for grades and specifications. The experimental results are shown in Table 6.
The experimental results show that compared with manual sorting, the carrot quality detection and grading system designed and developed in this paper has outstanding sorting efficiency while ensuring high accuracy, and the test indicators meet the design requirements

5. Discussion

Three “accuracy” types are clearly defined: 1. Detection accuracy (improved YOLOv8-seg-based): Measures carrot/defect detection–segmentation performance, with key metrics mAP (95.1%) and recall (93.5%); 2. Grading accuracy (fuzzy comprehensive evaluation based): Consistency with expert standards, reaching 94%; 3. System sorting accuracy: end-to-end performance, average of grade and specification sorting correctness (97.39%).
For boundary cases (“good but not perfect” carrots, e.g., slight bending, small green head <5% area within 2 cm of top), they are classified as Grade 1 via quantitative indicators (bending standard deviation <1.5) and fuzzy membership functions, complying with NY/T 1983-2011 Grade 1 tolerance.
Sorting mechanism details: Actuators adopt sorting nozzles-two nozzles per group are vertically arranged at the front of the sorting-guide inlet, forming a high–low nozzle combination to adapt to carrots of different sizes (diameter 30~80 mm). High-pressure air (adjustable pressure 0.3~0.6 MPa) is supplied by an air pump; the PLC precisely triggers nozzle jetting based on the real-time position and quality grade of carrots output by the CarrotDTNet algorithm. Horizontal airflow acts on the middle of the carrot, forming a resultant force with the conveyor belt friction to push the carrot smoothly into the grading guide channel and finally into the corresponding sorting basket. With no mechanical contact throughout, the carrot skin damage rate is controlled within 0.5%, achieving true non-destructive sorting.
The “quality grades” in this study are strictly linked to the recognized commercial standard NY/T 1983-2011 (Agricultural Industry Standard of China): Super Grade matches “uniform appearance, no cracks/mechanical damage, no green/purple on top”; Grade 1 aligns with “basically uniform, slight healed cracks allowed, small green/purple within 2 cm of top”; Grade 2 conforms to “slight cracks/discoloration allowed, green/purple within 3 cm of top”; carrots with irregular shape or breakage are directly classified as “unqualified”, fully meeting commercial standardization requirements.
The significant performance improvements of the developed carrot grading and sorting system are not accidental data outcomes but results of targeted algorithm optimization and scenario adaptation. The CarrotDSTNet algorithm achieves a 12.1% reduction in parameters, a 9.6% reduction in computational complexity, and simultaneous increases in mean average precision (mAP) by 2.3% and fibrous root recall rate by 3.8%, which stems from two key module improvements: the DualConv lightweight convolution module integrates spatial features through parallel 3 × 3 and 1 × 1 convolutions, combining the advantages of GroupConv and HetConv to cut redundant parameters, addressing the computational redundancy of the original YOLOv8-seg C2f module caused by deep convolution; the multi-scale depthwise strip convolutions (7 × 7, 11 × 11, 21 × 21 kernels) of the SegNeXt attention mechanism accurately captures slender weak features like fibrous roots and cracks, making up for traditional CNNs’ inability to recognize defects with similar colours and slender shapes. Additionally, the detection frame optimization method reduces redundant computation in dense multi-target scenarios by merging tasks with time difference Δt ≤ T, ensuring real-time performance. In the grading link, the fuzzy comprehensive evaluation method achieves 94% accuracy and 0.37 ms single-sample latency, significantly outperforming the TOPSIS method (62.67%) and gray correlation method (44.67%). Its core advantage lies in adapting to the fuzziness of carrot grading: for indicators without clear numerical boundaries (e.g., “green head height ratio,” and “bending deviation”), it quantifies qualitative standards via a two-level membership function (Gaussian for size, and trapezoidal for defects) and integrates multi-dimensional information with expert weights. Moreover, the error correction model for size quantification (derived from geometric relationships) improves diameter detection accuracy by 2.62%, and the improved Zhang-Suen algorithm fully extracts the bending centerline-providing reliable basic data that further amplifies the algorithm’s advantages. The sorting system achieves 97.39% comprehensive accuracy and 310 carrots/minute efficiency, far exceeding manual sorting (88.24%, 27 carrots/minute), which is attributed to the closed-loop collaborative design of CarrotDTNet: the detection box filter simplifies labels to one category and eliminates invalid boxes, reducing computational load by 40%; the electronic fence module filters targets with accidental intrusion/separation via virtual safety gates, avoiding the “one mistake breaks all” chain errors of traditional photoelectric counting; non-contact pneumatic actuators combined with real-time position tracking control the skin damage rate below 0.5%, breaking the 5–8% secondary damage bottleneck of traditional mechanical sorting. The system’s limitations are also clear: the dataset covers carrots of different batches, producing areas, and varieties, but lacks special variety samples; detection accuracy is significantly affected by external lighting without an adaptive illumination compensation mechanism. It only focuses on appearance defects and size quantification, not involving deep defects like internal rot, requiring further optimization.

6. Conclusions

As an important economic crop in China, carrots are prone to defects such as greenheads, fibrous roots, and bending due to factors like cultivation techniques and storage methods, which seriously affect economic benefits. The current mainstream manual grading is inefficient (<500 roots/hour) with inconsistent standards, while mechanical sorting can only classify by thickness, failing to quantify surface defects and resulting in a 5-8% secondary damage rate. Existing deep learning methods have gaps in multi-defect quantitative detection and dynamic sorting for slender carrots (aspect ratio > 4:1), restricting the industrial automation upgrade. To address these issues, this study developed a deep learning-based carrot quality detection and grading system. The hardware adopts a modular architecture, divided into detection and sorting equipment, integrating a mechanical system (detection roller conveyor, sorting conveyor belt, and sorting mechanism), a vision system (quality detection and tracking–sorting subsystems), and a control system (PLC and upper computer). The vision system calibration was completed to ensure detection accuracy. The system achieved three core algorithm innovations: In the detection link, the CarrotDSTNet algorithm was proposed, fusing improved YOLOv8-seg and DeepSORT. The DualConv lightweight module reduced model parameters and computational complexity by 12.1% and 9.6%, respectively; the SegNeXt attention mechanism increased the fibrous root recall rate by 3.8%; a detection box filter was designed to solve tracking jumps at the field of view edge, and a detection frame optimization method merged similar tasks to improve dense target processing capability. In the grading link, indicators such as size, bending, green head, and black spot were quantified: a maximum diameter error correction model was established (detection accuracy increased by 2.62%), the improved Zhang–Suen algorithm was used to extract the bending centerline, and the fuzzy comprehensive evaluation method achieved 94% grading accuracy (0.37 ms per sample), significantly outperforming the TOPSIS method (62.67%) and gray correlation method (44.67%); the interval division algorithm was adopted for specification classification to ensure efficiency. In the sorting link, the CarrotDTNet algorithm was proposed, simplifying detection frame labels and embedding an electronic fence module to solve interference in cross-equipment ID matching. Experimental verification showed that the system operated stably for 6 consecutive hours, with memory usage ≤4.2 GB and video memory usage ≤1.4 GB; CarrotDSTNet exhibited excellent detection and segmentation performance with stable target tracking; the comprehensive sorting accuracy reached 97.39%, efficiency 310 carrots/minute, and skin damage rate <0.5%, far exceeding manual sorting (accuracy 88.24%, efficiency 27 carrots/minute). This system breaks through technical bottlenecks such as slender target defect detection and multi-index dynamic grading, providing an efficient and non-destructive automated solution for carrot processing with great large-scale promotion value.
However, the system still has limitations that need further improvement: first, the experimental verification was based on a relatively small sample batch (100 kg, 476 carrots in total), failing to fully simulate large-scale industrial continuous production scenarios-such as carrot accumulation caused by fluctuations in conveyor speed on production lines, imaging interference from residual field soil and surface water stains, and morphological adaptation issues during mixed processing of multiple varieties (e.g., short-fat carrots, baby carrots) were not covered. Second, formal industrial verification remains pending: the system has not been put into long-term trial operation in processing enterprises with a daily throughput exceeding 10 tons, and its stability under extreme working conditions (72 h continuous load, voltage fluctuations) and compatibility with existing production line equipment (upstream cleaning equipment, downstream packaging systems) have not been verified. Third, the dataset has coverage limitations: samples mainly focus on “Xinheitian Wucun Shen”, a mainstream variety, lacking samples of special varieties (e.g., purple carrots, variegated carrots) and latent defects (e.g., internal hollowness, early subepidermal mildew), so the model’s generalization ability for atypical samples needs to be improved. Fourth, hardware costs and operation and maintenance thresholds are high: core computing relies on high-end graphics cards such as NVIDIA GeForce RTX 3090, resulting in high initial investment for small- and medium-sized processing enterprises; moreover, operations such as model fine-tuning and fault diagnosis require professional technicians, which is not conducive to grassroots promotion. Fifth, environmental adaptability is insufficient: lacking an adaptive illumination compensation mechanism, detection accuracy is easily affected under complex lighting conditions, such as cloudy days and uneven factory lighting.

Author Contributions

Conceptualization, C.Z.; Methodology, C.Z.; Software, Y.W.; Validation, Y.W.; Formal analysis, Y.W.; Investigation, C.Z., H.L. and X.X.; Resources, C.Z. and H.L.; Data curation, Y.W. and H.L.; Writing—original draft, Y.W. and H.L.; Writing—review & editing, C.Z., X.X., Y.L. and Y.Z.; Visualization, C.Z., Y.W., H.L. and X.X.; Supervision, C.Z.; Project administration, C.Z. and Y.L.; Funding acquisition, C.Z. All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Data Availability Statement

The data that support the findings of this study are subject to an embargo due to commercial restrictions.

Conflicts of Interest

The authors declare no conflict of interest.

References

  1. Ji, Z.D. Carrot Planting Technology and Pest Control. Basic Agric. Technol. Ext. 2023, 11, 145–147. (In Chinese) [Google Scholar]
  2. Xie, W.J.; Wei, S.; Wang, F.H.; Yang, G.Z.; Ding, X.; Yang, D.Y. Research on Recognition Method of Carrot Surface Defects Based on Machine Vision. J. Agric. Mach. 2020, 51 (Suppl. S1), 450–456. (In Chinese) [Google Scholar]
  3. Zhu, D.M.; Cheng, X.P.; Qiu, Y.J.; Li, T.C.; Wan, X.; Sun, X.; Wei, J.; Fu, Y.; Rao, X.H. Research Progress on Crop Image Recognition Technology Based on Deep Learning. Jiangxi Sci. 2025, 43, 154–161. (In Chinese) [Google Scholar]
  4. Ganesh, P.; Volle, K.; Burks, T.; Mehta, S. Deep Orange: Mask R-CNN Based Orange Detection and Segmentation. IFAC-Pap. 2019, 52, 70–75. [Google Scholar] [CrossRef]
  5. Ge, Y.; Xiong, Y.; From, P.J. Instance Segmentation and Localization of Strawberries in Farm Conditions for Automatic Fruit Harvesting. IFAC-Pap. 2019, 52, 294–299. [Google Scholar] [CrossRef]
  6. Kang, H.; Chen, C. Fast Implementation of Real-Time Fruit Detection in Apple Orchards Using Deep Learning. Comput. Electron. Agric. 2020, 168, 105108. [Google Scholar] [CrossRef]
  7. Ismail, N.; Malik, O.A. Real-Time Visual Inspection System for Grading Fruits Using Computer Vision and Deep Learning Techniques. Inf. Process. Agric. 2022, 9, 24–37. [Google Scholar] [CrossRef]
  8. Matsui, T.; Sugimori, H.; Koseki, S.; Koyama, K. Automated Detection of Internal Fruit Rot in Hass Avocado via Deep Learning-Based Semantic Segmentation of X-Ray Images. Postharvest Biol. Technol. 2023, 203, 112390. [Google Scholar] [CrossRef]
  9. Mirbod, O.; Choi, D.; Heinemann, P.H.; Marini, R.P.; He, L. On-Tree Apple Fruit Size Estimation Using Stereo Vision with Deep Learning-Based Occlusion Handling. Biosyst. Eng. 2023, 226, 27–42. [Google Scholar] [CrossRef]
  10. Gurubelli, Y.; Ramanathan, M.; Ponnusamy, P. Fractional Fuzzy 2DLDA Approach for Pomegranate Fruit Grade Classification. Comput. Electron. Agric. 2019, 162, 95–105. [Google Scholar] [CrossRef]
  11. Momeny, M.; Jahanbakhshi, A.; Jafarnezhad, K.; Zhang, Y.-D. Accurate Classification of Cherry Fruit Using Deep CNN Based on Hybrid Pooling Approach. Postharvest Biol. Technol. 2020, 166, 111204. [Google Scholar] [CrossRef]
  12. Behera, S.K.; Rath, A.K.; Sethy, P.K. Maturity Status Classification of Papaya Fruits Based on Machine Learning and Transfer Learning Approach. Inf. Process. Agric. 2021, 8, 244–250. [Google Scholar] [CrossRef]
  13. Baigvand, M.; Banakar, A.; Minaei, S.; Khodaei, J.; Behroozi-Khazaei, N. Machine Vision System for Grading of Dried Figs. Comput. Electron. Agric. 2015, 119, 158–165. [Google Scholar] [CrossRef]
  14. Sofu, M.; Er, O.; Kayacan, M.; Cetişli, B. Design of an Automatic Apple Sorting System Using Machine Vision. Comput. Electron. Agric. 2016, 127, 395–405. [Google Scholar] [CrossRef]
  15. Wang, F.; Zheng, J.; Tian, X.; Wang, J.; Niu, L.; Feng, W. An Automatic Sorting System for Fresh White Button Mushrooms Based on Image Processing. Comput. Electron. Agric. 2018, 151, 416–425. [Google Scholar] [CrossRef]
  16. Sun, J. Research on Factory Fire Smoke Detection Method Based on Improved YOLOv8. Inf. Technol. Informatiz. 2024, 12, 100–103. (In Chinese) [Google Scholar]
  17. Gang, S.; Liu, P.S.; Guo, X.W. Improved Lightweight Steel Surface Defect Detection Algorithm Based on YOLOv8n. Electron. Meas. Technol. 2025, 48, 74–82. (In Chinese) [Google Scholar]
  18. Guo, M.H.; Lu, C.Z.; Hou, Q.; Liu, Z.; Cheng, M.M.; Hu, S.M. SegNeXt: Rethinking Convolutional Attention Design for Semantic Segmentation. arXiv 2022, arXiv:2209.08575. [Google Scholar]
  19. Su, T.F. Comparative Study of Deep Convolutional Semantic Segmentation Networks in Classification of Farmland Remote Sensing Images: A Case Study of Hetao Irrigation District. Remote Sens. Nat. Resour. 2024, 36, 210–217. (In Chinese) [Google Scholar]
  20. Sun, Y.P.; Liu, Y.; Guo, P.X.; Li, Z.Q.; Meng, X.W.; Zhao, D.A. Segmentation and Localization Method of Weed Area in Crab Pond Based on Improved YOLOv8n-seg. Trans. Chin. Soc. Agric. Eng. 2024, 40, 224–233. (In Chinese) [Google Scholar]
  21. Zhong, J.; Chen, J.; Mian, A. DualConv: Dual Convolutional Kernels for Lightweight Deep Neural Networks. IEEE Trans. Neural Netw. Learn. Syst. 2023, 34, 8. [Google Scholar] [CrossRef] [PubMed]
  22. Varghese, R.; Sambath, M. YOLOv8: A Novel Object Detection Algorithm with Enhanced Performance and Robustness. In Proceedings of the 2024 International Conference on Advances in Data Engineering and Intelligent Computing Systems (ADICS), Chennai, India, 18–19 April 2024; pp. 1–6. [Google Scholar] [CrossRef]
  23. Wojke, N.; Bewley, A.; Paulus, D. Simple Online and Realtime Tracking with a Deep Association Metric. In Proceedings of the 2017 IEEE International Conference on Image Processing (ICIP), Beijing, China, 17–20 September 2017; pp. 3645–3649. [Google Scholar]
  24. Zhang, T.Y.; Suen, C.Y. A Fast Parallel Algorithm for Thinning Digital Patterns. Commun. ACM 1984, 27, 236–239. [Google Scholar] [CrossRef]
  25. Song, C. Risk Assessment of Fresh Agricultural Product Supply Chain Based on Analytic Hierarchy Process and Fuzzy Comprehensive Evaluation Method. China Circ. Econ. 2024, 18, 32–35. (In Chinese) [Google Scholar]
  26. Shi, Y.S. Effectiveness Evaluation of Actual Combat Drills in Fire Rescue Stations Based on Fuzzy Analytic Hierarchy Process. In Proceedings of the 2024 Academic Symposium on Fire Extinguishing and Emergency Rescue Technology—Emergency Rescue Team Training, Zhuhai, China; 2024; Volume 5, pp. 12–16. (In Chinese). [Google Scholar]
  27. Liu, H.; Zhou, L.J. Evaluation of Rural Tourism Development Level in Typical Villages of Jilin Province Based on TOPSIS. Chin. J. Agric. Resour. Reg. Plan. 2022, 43, 239–246. (In Chinese) [Google Scholar]
  28. Gengjun, G.; Mingye, J. Risk Assessment of Green Agricultural Supply Chain Based on Intuitionistic Fuzzy TOPSIS Method. Proc. Bus. Econ. Stud. 2025, 8, 253–259. [Google Scholar] [CrossRef]
  29. Shi, J.C.; Wang, S.Y. Empirical Research on the Innovation Integration of “Science-Industry-Education” in the Pearl River Delta Urban Agglomeration: Based on Grey Relational Analysis. Sci. Technol. Manag. Res. 2022, 42, 64–69. (In Chinese) [Google Scholar]
  30. Zheng, K.; Fang, J.; Li, J.; Shi, H.; Xu, Y.; Li, R.; Xie, R.; Cai, G. Robust Grey Relational Analysis-Based Accuracy Evaluation Method. Appl. Sci. 2025, 15, 4926. [Google Scholar] [CrossRef]
  31. NY/T 1983-2011; Ministry of Agriculture and Rural Affairs of the People’s Republic of China. Carrot Grade Specification [Agricultural Industry Standard of the People’s Republic of China]. China Agriculture Press: Beijing, China, 2011.
  32. Zhang, J.; Zhang, W.; You, Y.; Ma, J. The Working Area is Multiintelligent Security Monitoring and Space Electronic Fence. Int. Core J. Eng. 2025, 11, 162–170. [Google Scholar]
Figure 1. Block diagram of carrot grading and sorting system modules.
Figure 1. Block diagram of carrot grading and sorting system modules.
Electronics 14 03839 g001
Figure 2. Experimental platform of carrot grading system.
Figure 2. Experimental platform of carrot grading system.
Electronics 14 03839 g002
Figure 3. Overall architecture diagram of carrot quality detection and grading system.
Figure 3. Overall architecture diagram of carrot quality detection and grading system.
Electronics 14 03839 g003
Figure 4. DualConv lightweight convolution structure.
Figure 4. DualConv lightweight convolution structure.
Electronics 14 03839 g004
Figure 5. Network structure of CarrotDSTNet carrot quality detection algorithm.
Figure 5. Network structure of CarrotDSTNet carrot quality detection algorithm.
Electronics 14 03839 g005
Figure 6. Process of carrot quality detection link.
Figure 6. Process of carrot quality detection link.
Electronics 14 03839 g006
Figure 7. Flow chart of detection frame optimization method.
Figure 7. Flow chart of detection frame optimization method.
Electronics 14 03839 g007
Figure 8. Flow chart of carrot quality detection and grading system.
Figure 8. Flow chart of carrot quality detection and grading system.
Electronics 14 03839 g008
Figure 9. Flow chart of carrot quality detection and grading system (simplified version).
Figure 9. Flow chart of carrot quality detection and grading system (simplified version).
Electronics 14 03839 g009
Figure 10. Annotation process of carrot and its defects dataset.
Figure 10. Annotation process of carrot and its defects dataset.
Electronics 14 03839 g010
Figure 11. Training effect figure.
Figure 11. Training effect figure.
Electronics 14 03839 g011
Figure 12. Schematic diagram of measurement error.
Figure 12. Schematic diagram of measurement error.
Electronics 14 03839 g012
Figure 13. Curve of carrot radius measurement error.
Figure 13. Curve of carrot radius measurement error.
Electronics 14 03839 g013
Figure 14. Effect of centreline extraction algorithm.
Figure 14. Effect of centreline extraction algorithm.
Electronics 14 03839 g014
Figure 15. Effect comparison of Zhang–Suen skeletonization algorithm before and after improvement.
Figure 15. Effect comparison of Zhang–Suen skeletonization algorithm before and after improvement.
Electronics 14 03839 g015
Figure 16. Distribution of expert grading results in fuzzy comprehensive evaluation results.
Figure 16. Distribution of expert grading results in fuzzy comprehensive evaluation results.
Electronics 14 03839 g016
Figure 17. Distribution of expert grading results in TOPSIS evaluation results.
Figure 17. Distribution of expert grading results in TOPSIS evaluation results.
Electronics 14 03839 g017
Figure 18. Distribution of expert grading results in gray relational evaluation results.
Figure 18. Distribution of expert grading results in gray relational evaluation results.
Electronics 14 03839 g018
Figure 19. Network structure of CarrotDTNet carrot sorting algorithm.
Figure 19. Network structure of CarrotDTNet carrot sorting algorithm.
Electronics 14 03839 g019
Figure 20. Electronic fence of CarrotDTNet algorithm.
Figure 20. Electronic fence of CarrotDTNet algorithm.
Electronics 14 03839 g020
Figure 21. Segmentation Effect of CarrotDSTNet Algorithm.
Figure 21. Segmentation Effect of CarrotDSTNet Algorithm.
Electronics 14 03839 g021
Figure 22. Physical machine test results of CarrotDSTNet algorithm.
Figure 22. Physical machine test results of CarrotDSTNet algorithm.
Electronics 14 03839 g022
Table 1. Comparison of instance segmentation speeds.
Table 1. Comparison of instance segmentation speeds.
ModelPreprocessing Time (ms)Inference Time (ms)Post-Processing Time (ms)
YOLOv8m-seg8.1130.167.7
YOLOv8m-seg
+DualConv
+SegNeXt
8.3115.063.8
YOLOv5l-seg7.895.055.0
Table 2. Ablation experiment.
Table 2. Ablation experiment.
ModelParameters (M)Recall (%)Fibrous Root Recall (%)Computational Complexity (GFLOPs)Mean Average Precision (%)
YOLOv8m-seg27.2390.489.5110.092.8
YOLOv8m-seg
+DualConv
23.2889.588.997.891.6
YOLOv8m-seg
+DualConv
+SegNeXt
23.9393.593.399.495.1
YOLOv5l-seg20.588.287.595.091.5
Table 3. Original experimental data of carrot grading.
Table 3. Original experimental data of carrot grading.
Serial NumberIndex
Size A Curvature B Green Head Area C 1 Green Head Height C 2 Black Spot Area D 1 Maximum Black Spot Area D 2 Crack Length E 1 Crack Width E 2 Fibrous Root Length F 1 Fibrous Root Diameter F 2
10.48260.9128000.10260.0334000.52630.1427
20.48733.82230.17950.36530.12920.0379000.27300.1433
30.44314.87640.14790.17150.13620.01150.28170.183700
40.13504.62350.15120.34330.29890.0818000.30580.2934
50.18824.3485000.20310.06520.11800.26100.42800.4697
60.16753.39490.04350.24350.06090.05480000
70.22213.83790.37300.11710.38910.04030.22830.32350.29760.2650
80.25854.3937000.26590.02780.09870.15670.50430.2251
90.20004.33690.12980.326300000.29620.2829
100.50005.8628000.20760.01470.08190.192300
110.44222.78150.12410.09270.11400.050000.103600
120.38131.0911000.14510.0198000.26100
130.32574.75070.28060.45220.10890.09630.30540.171300
140.38381.6707000.13560.03120.15350.338300.1311
150.28523.4015000.20480.04310.46120.19470.01110.1837
1500.25431.81530.07620.27250.21730.09210000
Table 4. Experimental results of carrot grading.
Table 4. Experimental results of carrot grading.
Serial NumberMethod
Fuzzy Comprehensive EvaluationTechnique for Order Preference by Similarity to Ideal SolutionGray Relational EvaluationExpert Grading
1First GradeSpecial GradeSpecial GradeFirst Grade
2Second GradeFirst GradeSpecial GradeFirst Grade
3Second GradeFirst GradeUnqualifiedSecond Grade
4UnqualifiedSecond GradeUnqualifiedUnqualified
5UnqualifiedSecond GradeSecond GradeUnqualified
6First GradeSpecial GradeSpecial GradeFirst Grade
7UnqualifiedUnqualifiedUnqualifiedUnqualified
8Second GradeFirst GradeFirst GradeSecond Grade
9Special GradeSpecial GradeSpecial GradeSpecial Grade
10Second GradeSpecial GradeSpecial GradeSecond Grade
11First GradeFirst GradeSpecial GradeSpecial Grade
12Special GradeSpecial GradeSpecial GradeSpecial Grade
13UnqualifiedFirst GradeFirst GradeUnqualified
14First GradeFirst GradeSpecial GradeFirst Grade
15Second GradeFirst GradeSpecial GradeSecond Grade
150First GradeSpecial GradeSpecial GradeFirst Grade
Note: Data were collected from 150 carrot samples. Statistical significance was verified using the Chi-square goodness-of-fit test to compare the consistency between each algorithm’s grading results and expert grading results. The overall Chi-square statistic (χ2) = 128.36, degrees of freedom (df) = 448, p < 0.001, indicating extremely significant differences in consistency between different algorithms and expert judgments. Post hoc pairwise comparisons (Bonferroni correction) showed that the Fuzzy Comprehensive Evaluation method had the highest consistency with expert results (Kappa = 0.91, p > 0.05, no significant difference), while both TOPSIS (Kappa = 0.48, p < 0.001) and Gray Relational Evaluation (Kappa = 0.27, p < 0.001) had significantly lower consistency than expert grading, with the Gray Relational Evaluation showing the weakest consistency. Significance level α = 0.05.
Table 5. Performance of Different Evaluation Methods.
Table 5. Performance of Different Evaluation Methods.
MethodFuzzy Comprehensive EvaluationTechnique for Order Preference by Similarity to Ideal SolutionGray Relational EvaluationExpert Grading
Accuracy94%62.67%44.67%1
Average Time Consumption0.36 ms0.90 ms0.91 ms2.1 s
Table 6. System test results.
Table 6. System test results.
Test IndexSorting Method
Manual SortingCarrot Grading and Sorting System Sorting
Special Grade Correct Sorting Rate88.46%96.15%
First Grade Correct Sorting Rate79.72%96.50%
Large Fruit Correct Sorting Rate93.43%98.48%
Small Fruit Correct Sorting Rate91.34%98.43%
Comprehensive Accuracy Rate88.24%97.39%
Efficiency (carrots/Minute)27310
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Zhang, C.; Wang, Y.; Liu, H.; Xu, X.; Li, Y.; Zhu, Y. Deep Learning-Based Research on Carrot Grading and Sorting System. Electronics 2025, 14, 3839. https://doi.org/10.3390/electronics14193839

AMA Style

Zhang C, Wang Y, Liu H, Xu X, Li Y, Zhu Y. Deep Learning-Based Research on Carrot Grading and Sorting System. Electronics. 2025; 14(19):3839. https://doi.org/10.3390/electronics14193839

Chicago/Turabian Style

Zhang, Chengliang, Yunpeng Wang, Hao Liu, Xiaohui Xu, Yizheng Li, and Yanpu Zhu. 2025. "Deep Learning-Based Research on Carrot Grading and Sorting System" Electronics 14, no. 19: 3839. https://doi.org/10.3390/electronics14193839

APA Style

Zhang, C., Wang, Y., Liu, H., Xu, X., Li, Y., & Zhu, Y. (2025). Deep Learning-Based Research on Carrot Grading and Sorting System. Electronics, 14(19), 3839. https://doi.org/10.3390/electronics14193839

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop