The fixed window algorithm used in the traditional vehicle flow virtual loop detection has inherent shortcomings and limitations. The traditional algorithm can achieve a good detection effect when the driving vehicles strictly follow the lane. However, in real life, the phenomenon of vehicles driving across lanes is relatively serious, which often leads to the simultaneous detection of vehicles on the detection lines of two adjacent lanes, thus causing false detection. Aiming at the shortcomings of traditional fixed window algorithm in traffic flow detection, this paper proposes an improved dynamic window algorithm, which can effectively overcome the shortcomings of fixed window detection by setting two detection lines on multiple lanes across the entire road. The experimental results show that the improved algorithm has achieved good results in traffic flow detection, and has good robustness and stability.