There are potential safety hazards associated with defects in solar panels, and traditional detection methods suffer from low efficiency and limited application ranges. Currently, machine vision-based image detection methods for solar panel defects face challenges in balancing the speed and accuracy of model recognition. To address these issues, an improved MSRCR (Multi-Scale Retinex with Color Restoration) algorithm is applied to process images, enhancing the dark regions of solar panel defect images while ensuring uniform brightness and image clarity post-enhancement. Furthermore, an improved lightweight solar panel defect detection method based on YOLOv8n is proposed to reduce data redundancy and improve recognition accuracy. The experimental results show that the computational cost of the improved lightweight model is 6.6GFLOPs, which is only 81.5 % of the original model. The Mean Detection Time (MDT) was only 86.5 % of the original model. Accuracy, recall, and average accuracy reached 98.6 %, 97.9 %, and 98.9 %. Compared with the original model, it was increased by 3.7, 0.9 and 0.9 percentage points, respectively, which effectively avoided the phenomenon of missed detection and improved the accuracy and portability of the model.