To address the challenge of nail recognition and retrieval on roads at night, we present an enhanced nighttime nail detection system leveraging an improved YOLOv5 model. The proposed model integrates modified C3 modules, reparametrized feature pyramid networks (RepGFPN), and an optimal transport assignment loss (OTALoss), significantly boosting recognition accuracy while reducing parameters by 16%. Deployed on an NVIDIA Jetson Orin Nano device with a stereo matching algorithm, the system achieves synchronized recognition and localization of road nails within a 120° field of view, with localization errors maintained within 2.0 cm. Integrated with a binocular vision-based electromagnetic retrieval system and a ring marker system, the complete robot control system achieves retrieval and marking accuracies exceeding 98%. Experimental results demonstrate an average recognition accuracy of 91.5%, outperforming the original YOLOv5 model by 11.3%. This study paves the way for more efficient and accurate road nail removal, enhancing road traffic safety and demonstrating substantial practical value.