Green apples exhibit a coloration that closely matches their surrounding environment, leading to low recognition accuracy for existing artificial intelligence models. This paper presents a green apple recognition algorithm that integrates an improved U-shaped network (U-Net) and you only look once network (YOLO) v8 to address this challenge. First, the U-Net is enhanced via Dilated Convolution, Attention Gates, and Residual Connections to blur the background, thereby emphasizing the green apple target. Second, convolutional transformations and an attention mechanism are incorporated into YOLO v8, enabling it to focus more effectively on green apple targets within similarly colored backgrounds. Finally, the improved YOLO v8 is employed to recognize green apple targets segmented by the U-Net, with its performance compared against existing models. Research results show that the proposed algorithm achieves a precision of 92.5% and a Recall of 96.8% in green apple recognition, representing a significant improvement over classical models. To mitigate omission issues and further enhance overall performance, an improved YOLO v8 module is connected in parallel with the primary model. Based on its underlying principles, this approach is also applicable to other green fruits with colors and textures highly similar to their backgrounds, demonstrating strong robustness and generalization capabilities.