How to extract the background/foreground

The segmentation of background and foreground content in images is one of the most important video and motion analysis topics, and there has been a huge amount of research done in this area to provide some very practical and easy-to-use algorithms, which we're going to learn in the final section of this chapter. Current versions of OpenCV include the implementation of two background segmentation algorithms.

To use a terminology that is shorter, clearer, and more compatible with OpenCV functions and classes, we'll refer to background/foreground extraction and background/foreground segmentation simply as background segmentation.

The following two algorithms are available by default to be used for background segmentation using OpenCV:

  • BackgroundSubtractorKNN
  • BackgroundSubtractorMOG2

Both of these classes are subclasses of BackgroundSubtractor, which contains all of the required interfaces that one can expect from a proper background segmentation algorithm, which we'll get to later on. This simply allows us to use polymorphism to switch between algorithms that produce the same results and can be used in a very similar fashion for the exact same reason. The BackgroundSubtractorKNN class implements the K-nearest neighbors background segmentation algorithm, which is used in the case of a low foreground pixel count. BackgroundSubtractorMOG2, on the other hand, implements the Gaussian mixture-based background-segmentation algorithm. You can refer to the OpenCV online documentation for detailed information about the internal behavior and implementation of these algorithms. It's also a good idea to go through the referred articles for both of these algorithms, especially if you are looking for a custom background segmentation algorithm of your own.

Besides the algorithms we already mentioned, there are many more algorithms that can be used for background segmentation using OpenCV, which are included in the extra module, bgsegm. We'll omit those algorithms, since their usage is quite similar to the algorithms we'll be talking about in this section, and also because they do not exist in OpenCV by default.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.205.136