Video-based moving vehicle detection and tracking is an important prerequisite for vehicle counting under complex transportation environments. However, in the complex natural scene, the conventional optical flow method cannot accurately detect the boundary of the moving vehicle due to the generation of the shadow. In addition, traditional vehicle tracking algorithms are often occluded by trees, buildings, etc., and particle filters are also susceptible to particle degradation. To solve this problem, this paper proposes a kind of moving vehicle detection and tracking based on the optical flow method and immune particle filter algorithm. The proposed method firstly uses the optical flow method to roughly detect the moving vehicle and then uses the shadow detection algorithm based on the HSV color space to mark the shadow position after threshold segmentation and further combines the region-labeling algorithm to realize the shadow removal and accurately detect the moving vehicle. Improved affinity calculation and mutation function of antibody are proposed to make the particle filter algorithm have certain adaptivity and robustness to scene interference. Experiments are carried out in complex traffic scenes with shadow and occlusion interference. The experimental results show that the proposed algorithm can well solve the interference of shadow and occlusion and realize accurate detection and robust tracking of moving vehicles under complex transportation environments, which has the potentiality to be processed on a cloud computing platform.