Abstract:Accurate counting of tomato fruits is crucial for yield assessment and intelligent management. To achieve dynamic detection and counting of fruits among clustered branches in greenhouse environments, a dynamic tomato fruit counting method was proposed, primarily based on an improved YOLO v8n detection model and the ByteTrack tracking algorithm. A wavelet downsampling module and a P2 detection head were introduced into the YOLO v8n detection model, and an MLLA attention mechanism was designed to improve the model's detection performance in complex backgrounds. An adaptive low-score matching retry strategy was introduced based on ByteTrack. Finally, a counting method based on sequence region matching was proposed by using the improved ALRM Track. Experimental results showed that the improved YOLO v8n MAFP model achieved an average detection accuracy of 96.9% on the tomato fruit dataset, a 2.4 percentage points improvement over the original model. Combined with the improved ALRM Track algorithm of YOLO v8n MAFP, the multi-target tracking accuracy was increased to 88.2%, and the number of ID switching operations was reduced to 2. Using a sequence region matching mechanism for counting, the average absolute error in five greenhouse video experiments was only 1.4, with a counting accuracy of 96.6%, significantly outperforming traditional line-based counting and region-based counting methods. Greenhouse environment experiments demonstrated that the improved YOLO v8n ByteTrack model was suitable for the statistical needs of greenhouse tomato yield estimation.