Realizing moving target detection through visual algorithms is a major branch of computer technology. Moving target detection has a wide range of applications in many fields such as video surveillance, unmanned driving, and behavior research. The current algorithm has been able to achieve moving target detection well in a static background, but the detection of multiple moving targets in a dynamic background is still a challenging research area. The main pain points are complex background, light changes, noise interference and Occlusion and real-time detection requirements, etc. Aiming at the detection of moving targets in complex scenes, a moving target detection algorithm based on dynamic threshold is proposed. The algorithm first uses the gray difference gradient of three adjacent frames of the video sequence to calculate the segmentation threshold of foreground moving targets to realize the dynamic threshold. Then use dynamic thresholds to achieve multi-target motion detection in complex backgrounds or scenes with changing lighting. Because the gradient change of adjacent frames of the scene is considered in the process of moving target detection and segmentation, and the gradient change is converted into a dynamic threshold to participate in moving target detection and segmentation, the algorithm can adapt to scenes with changing lighting. Experiments show that this algorithm is feasible for moving target detection in complex scenes, and has a lower error rate than that of traditional algorithms, and is more suitable for to complex or changing lighting scenes.