Abstract:
Manual egg counting is limited by the high labor costs, low efficiency, and large errors in layer hen farming. It is often required for high detection performance in modern agriculture. However, complex farming environments have posed great challenges in the tasks, where eggs are frequently occluded, adhered to one another, or exhibit only subtle phenotypic differences between normal and abnormal eggs. In this study, an egg-counting method was proposed using an improved YOLOv11n model and the DeepSORT multi-object tracking algorithm. Three functional modules were constructed: detection, tracking, and counting. (1) In the detection module, an enhanced detection model, named YOLO-SR, was developed to replace the original YOLOv11n model. Specifically, a spatial and channel synergistic attention (SCSA) mechanism was integrated into the C2PSA module of the backbone network. This attention mechanism adaptively recalibrated feature responses along both spatial and channel dimensions, providing the network with the most discriminative regions of eggs to suppress irrelevant background information. Additionally, a reparameterized generalized feature pyramid network (RepGFPN) was introduced into the neck network of YOLOv11n. The RepGFPN improved multi-scale feature fusion using reparameterization techniques. Inference speed was enhanced with the representation power. Fine-grained features were extracted to manage scale variations, leading to a significant increase in detection accuracy for both normal and abnormal eggs under challenging conditions. (2) In the tracking module, the DeepSORT algorithm was employed to alleviate identity switching that frequently occurred during re-identification, particularly when eggs were temporarily occluded. Unlike conventional tracking on motion cues, appearance features were extracted from a pre-trained convolutional neural network with motion estimation using Kalman filters. Robust performance of egg detection was realized over consecutive frames. The target identities were effectively maintained even under prolonged occlusions or rapid movements. The appearance feature extractor was fine-tuned on egg image data for individual eggs. (3) In the counting module, a virtual line-crossing counting mechanism was designed to prevent duplicate counting. Specifically, a counting line was placed at a designated position in the video frame. An egg was counted only once when its tracked centroid crossed this line from one side to another. As such, the tracking module ensured that each egg was counted exactly once, thereby eliminating both false positives and missed counts. Experimental results demonstrated that the better performance of the YOLO-SR detector was achieved in an average precision of 95.4% and an F1 score of 89.0%, which were 1.9 and 0.6 percentage points higher than those of the original YOLOv11n, respectively. DeepSORT algorithm was obtained with a higher-order tracking accuracy (HOTA) of 93.6%, a multi-object tracking accuracy (MOTA) of 96.4%, and an ID F1 score (IDF1) of 98.2%. Notably, the number of identity switches (IDS) was zero using DeepSORT, indicating its robustness to occlusions. The overall egg counting was achieved with an average counting accuracy of 89.46%, which was 6.66 percentage points higher than that of manual counting, with a root mean square error (RMSE) of 2.37. In conclusion, there was excellent application potential for real-time egg tracking and counting tasks. The findings can provide effective technical support for egg counting in egg health monitoring and smart poultry.