Chapter 4. Depth Estimation and Segmentation

This chapter shows you how to use data from a depth camera to identify foreground and background regions, so 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.

We'll deal with two main topics in this chapter: depth estimation and segmentation. We will explore depth estimation with two distinct approaches: firstly, by using a depth camera (a prerequisite of the first part of the chapter), such as Microsoft Kinect, and then, by using stereo images, for which a normal camera will suffice. For instructions on how to build OpenCV with support for depth cameras, see Chapter 1, Setting Up OpenCV. The second part of the chapter is about segmentation, the technique that allows us to extract foreground objects from an image.

Creating modules

The code to capture and manipulate 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 rects.py file so that our copy operations can be limited to a nonrectangular subregion of a rectangle. To support the changes we are going to make, let's add the following import statements to rects.py:

import numpy
import utils

Finally, the new version of our application will use depth-related functionalities. So, let's add the following import statement to Cameo.py:

import depth

Now, let's go deeper into the subject of depth.

..................Content has been hidden....................

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