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

Defining a face as a hierarchy of rectangles


Before we start implementing a high-level tracker, we should define the type of tracking result that we want to get. For many applications, it is important to estimate how objects are posed in real, 3D space. However, our application is about image manipulation. So we care more about 2D image space. An upright, frontal view of a face should occupy a roughly rectangular region in the image. Within such a region, eyes, a nose, and a mouth should occupy rough rectangular subregions. Let's open trackers.py and add a class containing the relevant data:

class Face(object):
    """Data on facial features: face, eyes, nose, mouth."""
    
    def __init__(self):
        self.faceRect = None
        self.leftEyeRect = None
        self.rightEyeRect = None
        self.noseRect = None
        self.mouthRect = None

Note

Whenever our code contains a rectangle as a property or a function argument, we will assume it is in the format (x, y, w, h) where the unit...