Face Detection Using OpenCV With Raspberry Pi


Introduction: Face Detection Using OpenCV With Raspberry Pi

About: We are a team of IoT & Embedded Systems developers. We are working in Raspberry Pi and Arduino.

In this Project we are going to detect Face Detection using OpenCv with Raspberry Pi.

Step 1: Project Description:

In this project we are using OpenCv in Raspberry pi. This project is used to detect the human Face with the help of OpenCv tool. In order to do object detection with cascade files, you first need cascade files. For the extremely popular tasks, these file already exist.

Step 2: Software Used

1.Raspian OS:

This is the recommended os for raspberry pi. You can also installed other OS from third party. Raspbian OS is debian based OS. We can install it from noobs installer. you can get the link from here


PuTTY is an SSH and telnet client, developed originally by Simon Tatham for the Windows platform. PuTTY is open source software that is available with source code and is developed and supported by a group of volunteers. Here we are using putty for accessing our raspberry pi remotely.

You can download PuTTY here


OpenCV (Open Source Computer Vision Library) is an open source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in the commercial products. Being a BSD-licensed product, OpenCV makes it easy for businesses to utilize and modify the code. The library has more than 2500 optimized algorithms, which includes a comprehensive set of both classic and state-of-the-art computer vision and machine learning algorithms. These algorithms can be used to detect and recognize faces, identify objects, classify human actions in videos, track camera movements, track moving objects and extract 3D models of objects.

Step 3: Hardware Used

You only need two hardware here:

1. Raspberry Pi:

This is the latest version of raspberry pi. In this we have inbuilt Bluetooth and wi-fi, unlike previously we have to use Wi-Fi dongle in one of its usb port. There are total 40 pins in RPI3. Of the 40 pins, 26 are GPIO pins and the others are power or ground pins (plus two ID EEPROM pins.)
There are 4 USB Port and 1 Ethernet slot, one HDMI port, 1 audio output port and 1 micro usb port and also many other things you can see the diagram on right side. And also we have one micro sd card slot wherein we have to installed the recommended Operating system on micro sd card. There are two ways to interact with your raspberry pi. Either you can interact directly through HDMI port by connecting HDMI to VGA cable, and keyboard and mouse or else you can interact from any system through SSH(Secure Shell). (For example in windows you can interact from putty ssh.) Figure is given above.

2. Raspberry Pi Camera:

The Raspberry Pi camera module can be used to take high-definition video, as well as stills photographs. It’s easy to use for beginners, but has plenty to offer advanced users if you’re looking to expand your knowledge. There are lots of examples online of people using it for time-lapse, slow-motion and other video cleverness. You can also use the libraries we bundle with the camera to create effects.

Step 4: Installation of OpenCv

Here are the Installation steps for Python OpenCv on Raspberry Pi:

1) sudo apt-get update

2) sudo apt-get upgrade

3) sudo apt-get install build-essential

4) sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

5)sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

6) sudo apt-get install python-opencv

7) sudo apt-get install python-matplotlib

Step 5: Configure and Enable Camera

For Face Detection you have to Configure PiCamera. We have shown all the Steps description for enablingcamera are given above:

After following these Steps first you want Check Camera is enable or not. by taking one picture for this command:

sudo raspistill -o filename.jpg

If camera is enabled successfully then you get the picture in the same directory.

Step 6: Project Code and Video

Link of Project Code is give below. and you can also go our GitHub link

And Video of Project is given Above. for more details related our project you go to our YouTube Link

All the best. You have finished your face detection Project.

For any query regarding this project comment us below or you also mail us sales@deligence.com or Info@deligence.com

Thanks and Regards,

Deligence Technologies



    • Water Contest

      Water Contest
    • Clocks Contest

      Clocks Contest
    • Oil Contest

      Oil Contest

    7 Discussions

    why invalid syntac
    print ("Found "+str(len(faces))+" face(s)"

    when i try to run the code i get ImportError: No Moduel names 'CV2' can any one help with this as i went through all the steps

    1 reply

    It seems Open CV isn't installed. Please install Open CV first and then try.

    Hi when I try to install the libtbb-dev, Raspbyan can't install... "Package libtbb-dev is not avaible, but is referred to by another package. Thi may mean that the package is missing, has been obsoleted, or is nly avaible from another source"

    my question is that this library y really necesary? because the code run very good... but detect 0 faces :(

    How can I get that library

    2 replies

    problem was resolved :) I just download de haarcascade_eye.html, and other versión from faces.xml... my old file faces.xml was corrupt :) but I have the question about the libtbb-dev? is necesary? why? what is his function?

    libtbb-dev is a free and open-source library of codecs for encoding and decoding video and audio data.

    Thanks for sharing. It would be better if you also write the step by step commands you are showing on the video because these are the actual OpenCV usage. You've shown the steps for rhe installation and activating the camera, so I don't see why it can't be done on step 6.