Aiming at the problem that the classical visual background extraction algorithm (ViBe) is prone to ghost images due to the presence of moving objects in the initial frame and poor adaptability to dynamic backgrounds, an improved ViBe algorithm is proposed. Using the improved three-frame difference method and the minimum circumscribed rectangle. The initial frame moving target is located, and ghosting is suppressed by the method of local initialization; In the initial stage of the background model, a grayscale similarity function is defined to select pixels in a moderate proportion from the temporal and spatial information to establish a background model to enhance the robustness of the background model; In the foreground detection stage, the average difference method is used to measure the dispersion of the sample set, and an adaptive segmentation threshold is constructed to replace the original fixed segmentation threshold to adapt to the background disturbance. Experiments show that the improved algorithm can effectively suppress ghosting and improve the performance of the algorithm in disturbance Adaptability and detection accuracy in context.