Foreground detection is one of the major tasks in the field of computer vision and image processing whose aim is to detect changes in image sequences. Background subtraction is any technique which allows an image's foreground to be extracted for further processing (object recognition etc.).
For calculating the image containing only the background, a series of preceding images are averaged. For calculating the background image at the instant t,
where N is the number of preceding images taken for averaging. This averaging refers to averaging corresponding pixels in the given images. N would depend on the video speed (number of images per second in the video) and the amount of movement in the video. After calculating the background B(x,y,t) we can then subtract it from the image V(x,y,t) at time t = t and threshold it. Thus the foreground is
where Th is threshold. Similarly we can also use median instead of mean in the above calculation of B(x,y,t).
sbt "run ForegroundDectectorApp [video_absolute_path]"
Source : Wikipedia