In order to optimize the efficiency of pineapple harvesting robots in recognition and target detection, this paper introduces a lightweight pineapple detection model, namely MSGV-YOLOv7. This model adopts MobileOne as the innovative backbone network and uses thin neck as the neck network. The enhancements in these architectures have significantly improved the ability of feature extraction and fusion, thereby speeding up the detection rate. Empirical results indicated that MSGV-YOLOv7 surpassed the original YOLOv7 with a 1.98% increase in precision, 1.35% increase in recall rate, and 3.03% increase in mAP, while the real-time detection speed reached 17.52 frames per second. Compared with Faster R-CNN and YOLOv5n, the mAP of this model increased by 14.89% and 5.22%, respectively, while the real-time detection speed increased by approximately 2.18 times and 1.58 times, respectively. The application of image visualization testing has verified the results, confirming that the MSGV-YOLOv7 model successfully and precisely identified the unique features of pineapples. The proposed pineapple detection method presents significant potential for broad-scale implementation. It is expected to notably reduce both the time and economic costs associated with pineapple harvesting operations.