ViBe moving detection algorithm eliminates the ghost slowly, and the detection precision will be declined when classifing the pixels due to fixed distance threshold. Thus an improved method is proposed aiming at the two problems. The selection range of samples is expanded from the 8-connected neighborhood to the 24-connected neighborhood of each pixel, avoiding the selection of repetitive samples, and thus accelerating the elimination process of the ghost. According to background dynamics, the distance threshold is determined adaptively when each pixel is classified as a foreground pixel or a background pixel. It enhances the ability of resisting background interference. The improved algorithm was tested with two datasets. Test results indicate that the improved algorithm is able to eliminate the ghost shadows more rapidly, and the detection results are more accurate.