Foreground detection with the GrabCut algorithm

Calculating a disparity map is a useful way to segment the foreground and background of an image, but StereoSGBM is not the only algorithm that can accomplish this and, in fact, StereoSGBM is more about gathering three-dimensional information from two-dimensional pictures than anything else. GrabCut, however, is a perfect tool for foreground/background segmentation. The GrabCut algorithm consists of the following steps:

  1. A rectangle including the subject(s) of the picture is defined.
  2. The area lying outside the rectangle is automatically defined as a background.
  3. The data contained in the background is used as a reference to distinguish background areas from foreground areas within the user-defined ...

Get Learning OpenCV 4 Computer Vision with Python 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.