Book Image

OpenCV Computer Vision with Python

By : Joseph Howse
Book Image

OpenCV Computer Vision with Python

By: Joseph Howse

Overview of this book

<p>OpenCV Computer Vision with Python shows you how to use the Python bindings for OpenCV. By following clear and concise examples, you will develop a computer vision application that tracks faces in live video and applies special effects to them. If you have always wanted to learn which version of these bindings to use, how to integrate with cross-platform Kinect drivers, and how to efficiently process image data with NumPy and SciPy, then this book is for you.</p> <p>This book has practical, project-based tutorials for Python developers and hobbyists who want to get started with computer vision with OpenCV and Python. It is a hands-on guide that covers the fundamental tasks of computer vision, capturing, filtering, and analyzing images, with step-by-step instructions for writing both an application and reusable library classes.</p>
Table of Contents (14 chapters)
OpenCV Computer Vision with Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Modifying the application


For the depth-camera version of Cameo, let's create a new class, CameoDepth, as a subclass of Cameo. On initialization, a CameoDepth class creates a CaptureManager class that uses a depth camera device (either CV_CAP_OPENNI for Microsoft Kinect or CV_CAP_OPENNI_ASUS for Asus Xtion, depending on our setup). During the main loop in run(), a CameoDepth function gets a disparity map, a valid depth mask, and a normal color image in each frame. The normal color image is used to estimate facial rectangles, while the disparity map and valid depth mask are used to refine the estimate of the facial region using createMedianMask(). Faces in the normal color image are swapped using copyRect(), with the faces' respective masks applied. Then, the destination frame is displayed, optionally with debug rectangles drawn overtop it. We can implement CameoDepth in cameo.py as follows:

class CameoDepth(Cameo):
    def __init__(self):
        self._windowManager = WindowManager('Cameo...