O'Reilly logo

IPython Interactive Computing and Visualization Cookbook - Second Edition by Cyrille Rossant

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 install them with the following command:

conda install -c conda-forge opencv

How to do it...

  1. First, we import the packages:
    >>> import io
        import zipfile
        import requests
        import numpy as np
        import cv2
        import matplotlib.pyplot as plt
        %matplotlib inline
  2. We download and extract the dataset in the data/ subfolder:
    >>> url = ('https://github.com/ipython-books/' 'cookbook-2nd-data/blob/master/' ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required