For the low light environment such as road tunnels, the acquired vehicle images are affected by external factors, which leads to low vehicle detection accuracy. For this problem, a real-time vehicle detection method for low light environment with improved YOLOx algorithm is proposed. Firstly, the collected vehicle images are enhanced based on the guiding filter and regional energy characteristic fusion criterion to solve the problems of uneven illumination and blurred target contour information in the images.Secondly, based on the Swin-Transformer network structure, the backbone network of the vehicle detection algorithm with improved YOLOx is constructed, and the global modeling capability of Transformer is used to encode the key semantic information in the images and strengthen the extraction capability of the network detail features. Meanwhile, recursive gated convolution is introduced to replace the null convolution in the neck network to improve the network's high-level semantic modeling capability. Finally, a convolutional attention mechanism is introduced to enhance the network's extraction and fusion of key features for low-illumination images. Experimental validation on the constructed tunnel vehicle detection dataset UA-DETTUN shows that the proposed method achieves an average detection accuracy of 96.1%,which is 6.5% better than the YOLOx algorithm before improvement, while the detection speed of the network meets the requirement of real-time detection. The proposed method has high application value in vehicle detection.