This paper proposes an automatic foreground segmentation system based on Gaussian mixture models and dynamic graph cut algorithm. An adaptive perpixel background model is developed to set the data cost of an image graph. Shadow detection which is important to the foreground segmentation is introduced in this paper. A boundary smoothing algorithm is presented so as to eliminate edge aliasing and composite a foreground object onto a new background seamlessly. We verify our algorithm in different video sequences including some public video sequences. Experimental results demonstrate the efficiency of our proposed method.