Background/foreground detection
Background/foreground detection, or segmentation, which is often also to as background subtraction for quite good reasons, is the method of differentiating between the moving or changing regions in an image (foreground), as opposed to the regions that are more or less constant or static (background). This method is also very effective in detecting motions in an image. OpenCV includes a number of different methods for background subtraction, with two of them being available in the OpenCV installation by default, namely BackgroundSubtractorKNN
and BackgroundSubtractorMOG2
. Similar to the feature detector classes we learned about in Chapter 7, Features and Descriptors, these classes also originate from the cv::Algorithm
class, and they are both used quite easily and similarly since they differ not in the usage or the result, but in the implementation of the classes.
BackgroundSubtractorMOG2
can be used to detect the background/foreground by using the Gaussian...