The traffic flow is usually estimated to evaluate the traffic state in traffic management, and vehicle counting is a key method for estimating traffic flow. With wide deployment of cameras in urban transportation systems, the surveillance video becomes an important data source to conduct vehicle counting. However, the efficiency and accuracy of vehicle counting are seriously affected by the complexity of traffic scenarios. In this paper, we employ the virtual loop method to improve the quality of video-based vehicle counting method. As details, the expectation-maximization (EM) algorithm is fused with the Gaussian mixture model (GMM) for improving the segmentation quality of moving vehicles. In addition, a restoration method is designed to remove noise and fill holes for obtaining a better object region. Finally, a morphological feature and the color-histogram are utilized to solve occlusion issues. The effectiveness and efficiency experiments show that the proposed approach can improve the vehicle segmentation result and the vehicle occlusion detection. The accuracy of vehicle counting can also be improved significantly and reach 98%.