Detection of moving objects in video streams is the first relevant step of information extraction in many computer vision applications. Aside from the intrinsic usefulness of being able to segment video streams into moving and background components, detecting moving objects provides a focus of attention for recognition, classification, and activity analysis, making these later steps more efficient. In this paper, a background subtraction based on Bayesian estimation is proposed. The basic of our solution is a Bayesian likelihood test which can distinguish between foreground variation and dynamic background variation. The prior knowledge about the likelihood test is brought to bear by appropriately specified a priori probability as Markov random field. Based on this approach, decision thresholds vary depending on context, thus improving detection performance substantially. We compare our method with other modeling techniques and report experimental results, both in term of detection accuracy, for color video sequences that represent typical situations critical for video surveillance systems. Quantitative evaluation and comparison with the existing methods show that the proposed algorithm provides much improved results.