Ask Your Question

Revision history [back]

The easiest way is to look at segment_objects.cpp in OpenCV samples. It used a BackgroundSubtractorMOG object (doc). MOG stands for Mixture of Gaussian, which is a classical algorithm for this problem. To make a background subtraction, you have to take images of the background, and after you can make the subtraction when new objects appear. It uses BackgroundSubtractorMOG::operator() overloading to perform subtraction. Look at the parameter 'update_bg_model' which is used to stop the background update. If you stand in the foreground, without moving during some time, you become the background if this parameter is on, otherwise, the background isn't update. You can look at the original paper Stauffer & Grimson, CVPR 98.

The sample made a connected components analysis also.