To address the problems of low accuracy in slender defect feature extraction, insufficient multi-scale feature fusion, and difficult deployment of existing deep learning models, this study first improves the YOLOv8 algorithm using convolutional attention mechanism and coordinate attention mechanism, and carries out lightweight design; Furthermore, based on a lightweight model, a defect edge detection system for ancient buildings was constructed, and the model deployment and field verification were completed on the NVIDIA Jetson Orin Nano terminal. The results show that the mAP@0.5 increases from 80.4% to 95.8%, the parameter size decreases from 4.0MB to 2.7MB, and the running speed improves from 108FPS to 118FPS. Compared with other defect detection models, the proposed model achieves an average accuracy of 96.2%, a detection error of 1.2%, and a missed detection rate of 0.4%. Under normal lighting conditions, the detection accuracy for weathering and peeling, wall cracks, component defects, and paint aging reaches 98.5%, 96.7%, 94.6%, and 97.4%, respectively. Under six interference conditions, including low light, strong light overexposure, rainy blur, haze, and shadow obstruction, the accuracy remains above 90%. The proposed model effectively improves defect detection performance and provides technical support for ancient building protection.