Detecting faces in an image with OpenCV

OpenCV (Open Computer Vision) is an open source C++ library for computer vision. It features algorithms for image segmentation, object recognition, augmented reality, face detection, and other computer vision tasks.

In this recipe, we will use OpenCV in Python to detect faces in a picture.

Getting ready

You need OpenCV and the Python wrapper. You can find installation instructions on OpenCV's website,

On Windows, you can install Chris Gohlke's package, available at

You also need to download the Family dataset from the book's GitHub repository at


OpenCV ...

Get IPython Interactive Computing and Visualization Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.