Abstract:The integrated monitoring of airborne pathogenic spores using intelligent spore trapping devices has become a crucial approach for early online warning of crop airborne diseases. To address issues such as image defocus blur and low spore detection accuracy caused by fixedfocus microscopic imaging under complex working conditions, focusing on urediospores of wheat stripe rust, an automatic focusing system for spore microscopic imaging was designed. This system integrated YOLO v5n object detection with a spore morphology-adaptive dynamic step search strategy to achieve adaptive tracking and counting of urediospores in complex backgrounds. Firstly, a low-cost portable microscopic image acquisition device was constructed by using a Raspberry Pi microcontroller and CMOS image sensor. A stepper motor drived the lens barrel vertically (1/8 microstepping mode, step size 0.625μm) to capture multifocal urediniospore image sequences. Secondly, an improved spore focusing evaluation function was innovatively proposed by combining the YOLO v5n model with the traditional squared modified Laplacian (SML) gradient evaluation function, effectively solving the misjudgment of focal planes caused by background impurities. Finally, a spore morphology-adaptive dynamic step search strategy (coarse search: 10 micrometers per step;fine search: 2.5 micrometers per step) was implemented to optimize focusing efficiency. Experimental results demonstrated that the proposed evaluation function achieved 97.44% spore counting accuracy, representing a 56.54 percentagepoint improvement over that of traditional gradient-based methods. The automatic focusing success rate reached 98% with an average focusing time of 116.49s. The developed autofocusing algorithm (high accuracy/robustness) combined with the low-cost, fastresponse portable imaging device significantly advanced intelligent spore trap automation, offering key technological solutions for cross-regional management of airborne crop pathogens.