## 1 Introduction
[27] proposed a vehicle-target detection algorithm based on improved the YOLOv4-tiny algorithm, which improves the detection speed of the algorithm while losing detection accuracy, and does not achieve a good balance between detection accuracy and speed. [PERSON] et al. [28] proposed a target detection algorithm based on improved YOLOv5, which replaces all convolution modules in YOLOv5 with the Ghost module with low computational complexity and simplifies the backbone network to improve network performance. However, because the improved algorithm is very lightweight, it is not effective for environment detection purposes, such as mutual occlusion and background interference. [PERSON] et al. [29] proposed a type of foreign-body detection device in a coal mine conveyor belt based on CBAM-YOLOv5. In order to solve the problem that the foreign-body target was difficult to accurately detect due to the low-illumination conditions, the convolution block attention model was introduced into the YOLOv5 detection network to improve the salience of the foreign-body target in the image, enhance the feature-expression ability of the foreign-body target in the detection network, and then improve the detection accuracy of the foreign-body target. However, the speed of the algorithm needs to be improved further. Based on this result, a real-time obstacle detection method when driving automatic rail locomotives based on DeblurGANv2 and improved YOLOv4 is proposed. DeblurGANv2 is used to solve the problem of motion blur. The YOLOv4 algorithm is improved to ameliorate the detection performance in an environment with low illumination, occlusions, small targets, and background interference, and the detection speed of the algorithm is improved to meet the requirements of the real-time detection of edge equipment. This paper (1) calculates the blur of the image by the Laplace operator to accurately judge whether the image needs to be deblurred or not, and the blurred image is deblurred by DeblurGANv2. (2) The improved design is based on YOLOv4, and the lightweight feature extraction network MobileNetv2 [30] is used to replace the original CSPDarknet53 network to improve the detection speed of the algorithm. There is a high amount of background interference information in the target detection of the coal mine scene. In order to improve the attention paid to the target, the SANet [31] attention module is embedded in the Neck network to improve the detection accuracy of the algorithm under low-illumination, target-occlusion, small-target, and other conditions. To further improve the detection accuracy of the algorithm, the K-means++ algorithm is adopted to cluster prior frames, and the focal [32] loss function is introduced to increase the weight loss of small-target samples. (3) The obstacle datasets of the rail locomotive operation area are constructed to provide a test environment for all kinds of obstacle detection algorithms, for which dataset 1 is composed of clear pictures, dataset 2 is composed of blurred pictures, and dataset 3 is composed of pictures deblurred by DeblurGANv2. The experimental results show that the deblurring of the motion-blurred picture can effectively improve the detection accuracy of obstacles and reduce missed detections. Compared with other commonly used models, the improved YOLOv4 algorithm presents a better balance and can ensure the detection accuracy and speed of the model simultaneously.