The aim of motion detection is to decide whether a given part of an image belongs to a moving object or to the static background. This paper proposes an automatic decision rule for the detection of moving regions. The proposed framework is derived from a perceptual grouping principle, namely the Helmholtz principle. This principle basically states that perceptually relevant events are perceived because they deviate from a model of complete randomness. Detections are then said to be performed a contrario: moving regions appear as low probability events in a model corresponding to the absence of moving objects in the scene. A careful design of the events considered under the hypothesis of absence of moving objects results in a general and robust motion detection algorithm. No posterior parameter tuning is necessary. Furthermore, a confidence level is attached to each detected region.