The high cost of manual weed control and the overuse of herbicides restrict the yield and quality of soybean. Intelligent mechanical weeding and precise application of pesticides can be used as effective alternatives for weed control in the field, and these require accurate distinction between crops and weeds. In this paper, images of soybean seedlings and weeds in different growth areas are used as datasets. In the aspect of soybean recognition, this paper designs a YOLOv8nGP algorithm with a backbone network optimisation based on GhostNet and an unconstrained pruning method with a 60% pruning rate. Compared with the original YOLOv8n, the YOLOv8nGP improves the Precision (P), Recall (R), and F1 metrics by 1.1% each, reduces the model size by 3.6 mb, and the inference time was 2.2 ms, which could meet the real-time requirements of field operations. In terms of weed recognition, this study utilises an image segmentation method based on the Normalized Excess Green Index (NExG). After filtering the soybean seedlings, the green parts of the image are extracted for weed recognition, which reduces the dependence on the diversity of the weed datasets. This study combines deep learning with traditional algorithms, which provides a new solution for weed recognition of soybean seedlings.