The basecutter collides with obstacles in the field while sugarcane harvesters operate, easily damaging the blades of the basecutter. The design of an emergency obstacle avoidance system with machine vision and deep learning for sugarcane basecutters was used to identify obstacles in the cane field. The embedded system then was used to control the lifting and lowering of the basecutter to complete the real-time obstacle avoidance work. The YOLOv5s target detection model was structurally optimized in a real field trial environment. With a weight file that is 8.4 M, 41.6 % smaller than the original model, and a detection speed increase of 7.98 fps, the improved detection model generally satisfies the real-time needs of the field detection tests. The detection model used on the Raspberry Pi in the field test can achieve better detection accuracy with an inference delay of just 0.2 s, ensuring both detection accuracy and speed while accounting for the size of the model memory. A better obstacle avoidance effect can be achieved under light to moderate occlusion conditions and the positive obstacle avoidance rate can be greater than 80 % when the harvester is moving at a speed between 0.25 m⋅s−1 and 0.35 m⋅s−1. The effect of obstacle avoidance is diminished when the harvester is moving at its general top speed and comes into contact with severe occlusion conditions, but it may still satisfy obstacle avoidance requirements in field work settings and fully protect the blade.