Chapter 5. Detecting Foreground/Background Regions and Depth

This chapter shows how to use data from a depth camera to identify foreground and background regions, such that we can limit an effect to only the foreground or only the background. As prerequisites, we need a depth camera, such as Microsoft Kinect, and we need to build OpenCV with support for our depth camera. For build instructions, see Chapter 1, Setting up OpenCV.

Creating modules

Our code for capturing and manipulating depth-camera data will be reusable outside Cameo.py. So we should separate it into a new module. Let's create a file called depth.py in the same directory as Cameo.py. We need the following import statement in depth.py:

import numpy

We will also need to modify our preexisting ...

Get OpenCV: Computer Vision Projects with Python 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.