Raspberry Pi Face Recognition

In last week’s blog post you learned how to perform Face recognition with Python, OpenCV, and deep learning.

But as I hinted at in the post, in order to perform face recognition on the Raspberry Pi you first need to consider a few optimizations — otherwise, the face recognition pipeline would fall flat on its face.

Namely, when performing face recognition on the Raspberry Pi you should consider:

  • On which machine you are computing your face recognition embeddings for your training set (i.e., onboard the Raspberry Pi, on a laptop/desktop, on a machine with a GPU)
  • The method you are using for face detection (Haar cascades, HOG + Linear SVM, or CNNs)
  • How you are polling for frames from your camera sensor (threaded vs. non-threaded)

All of these considerations and associated assumptions are critical when performing accurate face recognition on the Raspberry Pi — and I’ll be right here to guide you through the trenches.

To learn more about using the Raspberry Pi for face recognition, just follow along.

Looking for the source code to this post?
Jump right to the downloads section.

Raspberry Pi Face Recognition

This post assumes you have read through last week’s post on face recognition with OpenCV — if you have not read it, go back to the post and read it before proceeding.

In the first part of today’s blog post, we are going to discuss considerations you should think through when computing facial embeddings on your training set of images.

From there we’ll review source code that can be used to perform face recognition on the Raspberry Pi, including a number of different optimizations.

Finally, I’ll provide a demo of using my Raspberry Pi to recognize faces (including my own) in a video stream.

Configuring your Raspberry Pi for face recognition

Let’s configure our Raspberry Pi for today’s blog post.

First, go ahead and install OpenCV if you haven’t done so already. You can follow my instructions linked on this OpenCV Install Tutorials page for the most up to date instructions.

Next, let’s install Davis King’s dlib toolkit software into the same Python virtual environment (provided you are using one) that you installed OpenCV into:

If you’re wondering who Davis King is, check out my 2017 interview with Davis!

From there, simply use pip to install Adam Geitgey’s face_recognition module:

And don’t forget to install my imutils package of convenience functions:

PyImageConf 2018, a PyImageSearch conference

Would you like to receive live, in-person training from myself, Davis King, Adam Geitgey, and others at PyImageSearch’s very own conference in San Francisco, CA?

Both Davis King (creator of dlib) and Adam Geitgey (author of the Machine Learning is Fun! series) will be teaching at PyImageConf 2018 and you don’t want to miss it! You’ll also be able to learn from other prominent computer vision and deep learning industry speakers, including me!

You’ll meet others in the industry that you can learn from and collaborate with. You’ll even be able to socialize with attendees during evening events.

There are only a handful of tickets remaining, and once I’ve sold a total of 200 I won’t have space for you. Don’t delay!

I want to attend PyImageConf 2018! 

Project structure

If you want to perform facial recognition on your Raspberry Pi today, head to the “Downloads” section of this blog post and grab the code. From there, copy the zip to your Raspberry Pi (I use SCP) and let’s begin.

On your Pi, you should unzip the archive, change working directory, and take a look at the project structure just as I have done below:

Our project has one directory with two sub-directories:

  • dataset/ : This directory should contain sub-directories for each person you would like your facial recognition system to recognize.
    • adrian/ : This sub-directory contains pictures of me. You’ll want to replace it with pictures of yourself 😁.
    • ian_malcolm/ : Pictures of Jurassic Park’s character, Ian Malcolm, are in this folder, but again you’ll likely replace this directory with additional directories of people you’d like to recognize.

From there, we have four files inside of pi-face-recognition/ :

  • encode_faces.py : This file will find faces in our dataset and encode them into 128-d vectors.
  • encodings.pickle : Our face encodings (128-d vectors, one for each face) are stored in this pickle file.
  • haarcascade_frontalface_default.xml : In order to detect and localize faces in frames we rely on OpenCV’s pre-trained Haar cascade file.
  • pi_face_recognition.py : This is our main execution script. We’re going to review it later in this post so you understand the code and what’s going on under the hood. From there feel free to hack it up for your own project purposes.

Now that we’re familiar with the project files and directories, let’s discuss the first step to building a face recognition system for your Raspberry Pi.

Step #1: Gather your faces dataset

Figure 1: A face recognition dataset is necessary for building a face encodings file to use with our Python + OpenCV + Raspberry Pi face recognition method.

Before we can apply face recognition we first need to gather our dataset of example images we want to recognize.

There are a number of ways we can gather such images, including:

  1. Performing face enrollment by using a camera + face detection to gather example faces
  2. Using various APIs (ex., Google, Facebook, Twitter, etc.) to automatically download example faces
  3. Manually collecting the images

This post assumes you already have a dataset of faces gathered, but if you haven’t yet, or are in the process of gathering a faces dataset, make sure you read my blog post on How to create a custom face recognition dataset to help get you started.

For the sake of this blog post, I have gathered images of two people:

Using only this small number of images I’ll be demonstrating how to create an accurate face recognition application capable of being deployed to the Raspberry Pi.

Step #2: Compute your face recognition embeddings

Figure 2: Beginning with capturing input frames from our Raspberry Pi, our workflow consists of detecting faces, computing embeddings, and comparing the vector to the database via a voting method. OpenCV, dlib, and face_recognition are required for this face recognition method.

We will be using a deep neural network to compute a 128-d vector (i.e., a list of 128 floating point values) that will quantify each face in the dataset. We’ve already reviewed both (1) how our deep neural network performs face recognition and (2) the associated source code in last week’s blog post, but as a matter of completeness, we’ll review the code here as well.

Let’s open up encode_faces.py  from the “Downloads” associated with this blog post and review:

First, we need to import required packages. Notably, this script requires imutils , face_recognition , and OpenCV installed. Scroll up to the “Configuring your Raspberry Pi for face recognition” section to install the necessary software.

From there, we handle our command line arguments with argparse :

  • --dataset : The path to our dataset (we created a dataset using method #2 of last week’s blog post).
  • --encodings : Our face encodings are written to the file that this argument points to.
  • --detection-method : Before we can encode faces in images we first need to detect them. Our two face detection methods include either hog  or cnn . Those two flags are the only ones that will work for --detection-method .

Note: The Raspberry Pi is not capable of running the CNN detection method. If you want to run the CNN detection method, you should use a capable compute, ideally one with a GPU if you’re working with a large dataset. Otherwise, use the hog  face detection method.

Now that we’ve defined our arguments, let’s grab the paths to the images files in our dataset (as well as perform two initializations):

From there we’ll proceed to loop over each face in the dataset:

Inside of the loop, we:

  • Extract the person’s name  from the path (Line 32).
  • Load and convert the image  to rgb  (Lines 36 and 37).
  • Localize faces in the image (Lines 41 and 42).
  • Compute face embeddings and add them to knownEncodings  along with their name  added to a corresponding list element in knownNames  (Lines 45-52).

Let’s export the facial encodings to disk so they can be used in our facial recognition script:

Line 56 constructs a dictionary with two keys — "encodings"  and "names" . The values associated with the keys contain the encodings and names themselves.

The data  dictionary is then written to disk on Lines 57-59.

To create our facial embeddings open up a terminal and execute the following command:

After running the script, you’ll have a pickle file at your disposal. Mine is named   encodings.pickle  — this file contains the 128-d face embeddings for each face in our dataset.

Wait! Are you running this script on a Raspberry Pi?

No problem, just use the --detection-method hog  command line argument. The --detection-method cnn  will not work on a Raspberry Pi, but certainly can be used if you’re encoding your faces with a capable machine. If you aren’t familiar with command line arguments, just be sure to give this post a quick read and you’ll be a pro in no time!

Step #3: Recognize faces in video streams on your Raspberry Pi

Figure 3: Face recognition on the Raspberry Pi using OpenCV and Python.

Our pi_face_recognition.py  script is very similar to last week’s  recognize_faces_video.py  script with one notable change. In this script we will use OpenCV’s Haar cascade to detect and localize the face. From there, we’ll continue on with the same method to actually recognize the face.

Without further ado, let’s get to coding pi_face_recognition.py :

First, let’s import packages and parse command line arguments. We’re importing two modules ( VideoStream  and FPS ) from imutils  as well as imutils  itself. We also import face_recognition  and cv2  (OpenCV). The rest of the modules listed are part of your Python installation. Refer to “Configuring your Raspberry Pi for face recognition” to install the software.

We then parse two command line arguments:

  • --cascade : The path to OpenCV’s Haar cascade (included in the source code download for this post).
  • --encodings : The path to our serialized database of facial encodings. We just built encodings in the previous section.

From there, let’s instantiate several objects before we begin looping over frames from our camera:

In this block we:

  • Load the facial encodings data  (Line 22).
  • Instantiate our face detector  using the Haar cascade method (Line 23).
  • Initialize our VideoStream — we’re going to use a USB camera, but if you want to use a PiCamera with your Pi, just comment Line 27 and uncomment Line 28.
  • Wait for the camera to warm up (Line 29).
  • Start our frames per second, fps , counter (Line 32).

From there, let’s begin capturing frames from the camera and recognizing faces:

We proceed to grab a frame  and preprocess it. The preprocessing steps include resizing followed by converting to grayscale and rgb  (Lines 38-44).

In the words of Ian Malcolm:

Your scientists were so preoccupied with whether they could, they didn’t stop to think if they should.

Well, he was referring to growing dinosaurs. As far as face recognition, we can and we should detect and recognize faces with our Raspberry Pi. We’ve just got to be careful not to overload the Pi’s limited memory with a complex deep learning method. Therefore, we’re going to use a slightly dated but very prominent approach to face detection — Haar cascades!

Haar cascades are also known as the Viola-Jones algorithm from their paper published in 2001.

The highly cited paper proposed their method to detect objects in images at multiple scales in realtime. For 2001 it was a huge discovery and share of knowledge — Haar cascades are still well known today.

We’re going to make use of OpenCV’s trained face Haar cascade which may require a little bit of parameter tuning (as compared to a deep learning method for face detection).

Parameters to the detectMultiScale  method include:

  • gray : A grayscale image.
  • scaleFactor : Parameter specifying how much the image size is reduced at each image scale.
  • minNeighbors : Parameter specifying how many neighbors each candidate rectangle should have to retain it.
  • minSize : Minimum possible object (face) size. Objects smaller than that are ignored.

For more information on these parameters and how to tune them, be sure to refer to my book, Practical Python and OpenCV as well as the PyImageSearch Gurus course.

The result of our face detection is rects , a list of face bounding box rectangles which correspond to the face locations in the frame (Lines 47 and 48). We convert and reorder the coordinates of this list on Line 53.

We then compute the 128-d  encodings  for each face on Line 56, thus quantifying the face.

Now let’s loop over the face encodings and check for matches:

The purpose of the code block above is to identify faces. Here we:

  1. Check for matches  (Lines 63 and 64).
  2. If matches are found we’ll use a voting system to determine whose face it most likely is (Lines 68-87). This method works by checking which person in the dataset has the most matches (in the event of a tie, the first entry in the dictionary is selected).

From there, we simply draw rectangles surrounding each face along with the predicted name of the person:

After drawing the boxes and text, we display the image and check if the quit (“q”) key is pressed. We also update our fps  counter.

And lastly. let’s clean up and write performance diagnostics to the terminal:

Face recognition results

Be sure to use the “Downloads” section to grab the source code and example dataset for this blog post.

From there, open up your Raspberry Pi terminal and execute the following command:

Raspberry Pi Face Recognition

I’ve included a demo video, along with additional commentary below, so be sure to take look:

Our face recognition pipeline is running at approximately 1-2 FPS. The vast majority of the computation is happening when a face is being recognized, not when it is being detected. Furthermore, the more faces in the dataset, the more comparisons are made for the voting process, resulting in slower facial recognition.

Therefore, you should consider computing the full face recognition (i.e., extracting the 128-d facial embedding) once every N frames (where N is user-defined variable) and then apply simple tracking algorithms (such as centroid tracking) to track the detected faces. Such a process will enable you to reach 8-10 FPS on the Raspberry Pi for face recognition.

We will be covering object tracking algorithms, including centroid tracking, in a future blog post.


In today’s blog post we learned how to perform face recognition using the Raspberry Pi, OpenCV, and deep learning.

Using this method we can obtain highly accurate face recognition, but unfortunately could not obtain higher than 1-2 FPS.

Realistically, there isn’t a whole lot we can do about speeding up the algorithm — the Raspberry Pi, while powerful for such a small device, is naturally limited in terms of computation power and memory (especially without a GPU).

If you would like to speedup face recognition on the Raspberry Pi I would suggest to:

  1. Take a look at the PyImageSearch Gurus course where we use algorithms such as Eigenfaces and LBPs to obtain faster frame rates of ~13 FPS.
  2. Train your own, shallower deep learning network for facial embedding. The downside here is that training your own facial embedding network is more of an advanced deep learning technique, to say the least. If you’re interested in learning the fundamentals of deep learning applied to computer vision tasks, be sure to refer to my book, Deep Learning for Computer Vision with Python.

I hope you enjoyed today’s post on face recognition!

To be notified when future blog posts are published here on PyImageSearch, just enter your email address in the form below!


If you would like to download the code and images used in this post, please enter your email address in the form below. Not only will you get a .zip of the code, I’ll also send you a FREE 11-page Resource Guide on Computer Vision and Image Search Engines, including exclusive techniques that I don’t post on this blog! Sound good? If so, enter your email address and I’ll send you the code immediately!

, , , , , , ,

63 Responses to Raspberry Pi Face Recognition

  1. Zubair Ahmed June 25, 2018 at 10:46 am #

    Loved to hear your voice for the first time and your accent 🙂

    Before you said it while going through the post I was also thinking what would it be like to run this on Intel Movidius NCS, would love to see a post on it in the future


    • Adrian Rosebrock June 25, 2018 at 1:39 pm #

      I’m not sure if you can call a Maryland/Baltimore accent a true “accent” but people do pick up on it. I’ve actually started taking speech therapy lessons to help not speak the way I do 😉

      • Zubair June 26, 2018 at 12:31 am #

        You’re kidding me, are you serious right now?

        I think this is a fine accent and you don’t need to change it, what would you sound like after this therapy or rather who would you sound like?

        • Adrian Rosebrock June 26, 2018 at 8:10 am #

          Hah! Yes, I am serious. It’s a long, boring story but basically I talk with a low register of my voice, common for Marylanders. It’s sometimes called “vocal fry”. Just fixing that, that’s all 🙂

          • Zubair Ahmed July 2, 2018 at 8:27 am #

            Oh wow I googled ‘vocal fry’ right now, sounds like something you should definitely do if you have this, I’m wiser now.

            Its interesting to know that having a deeper voice is correlated with making more money (not bad) and attracting opposite gender (think you’re set over here, hello T 🙂

            Good luck

          • Adrian Rosebrock July 3, 2018 at 7:26 am #

            Googling for vocal fry can lead you to a lot of really, really bad cases of what it is. Mine is nowhere near as bad — I just talk in a low voice 😉

          • Zubair Ahmed July 5, 2018 at 8:52 am #

            Happy to hear that its not that bad

    • Vijay June 26, 2018 at 5:57 am #

      me too looking in this direction. Would be good idea to try this in small “toy” experiments at home.

  2. Francisco Rodriguez June 25, 2018 at 1:07 pm #

    Hello Adrian Rosebrock, I want to congratulate you for all your contribution in this field, I have a question and that is that I have mounted the topic of facial recognition, but the same program that I run on my laptop recognizes a distance of up to 5 meters but in the Raspberry device does not do it at 1 max and sometimes at 2 meters away, is there any way to overcome this problem?

    • Adrian Rosebrock June 25, 2018 at 1:37 pm #

      That sounds like a difference in your camera sensors — your Raspberry Pi camera is not good enough to detect the faces from your distance. You can either:

      1. Use a better camera sensor
      2. Upsample the image prior to applying face detection — the problem here will be speed. The more data, the longer it will take to process.

      • rush June 26, 2018 at 7:23 am #


  3. Shan June 25, 2018 at 1:19 pm #

    Thanks for this tutorial Adrian. I was somewhere waiting to see how Adrian would run Deep Learning on SMB’s like RBP.

    Very informative post and I learned a lot.

    Next I will keep my eyes open for Centroid Tracking that interests me more than anything.


    • Adrian Rosebrock June 25, 2018 at 1:36 pm #

      Thanks Shan, I’m glad you enjoyed the post.

  4. Mansoor June 25, 2018 at 3:23 pm #

    Great tutorial Adrian!!

    Can Intel Movidius NCS improve the FPS? and by how much?

    Thank you.

    • Adrian Rosebrock June 26, 2018 at 8:20 am #

      This model (dlib) cannot be directly used by the Movidius NCS so a comparison cannot really be done. Some work has been done with OpenFace and FaceNet to run on the NCS, such as this repo but I haven’t been able to run it on the NCS.

  5. Damir June 25, 2018 at 3:28 pm #

    Hi Adrian,

    Love your work, I’ve been learning about neural networks and machine learning in the last couple of months and your blog has been of HUGE help for me, so wanted to thank you for that 🙂

    Regarding this topic, have you considered converting some Tensorflow model for face recognition, such as those provided with facenet by David Sandberg, to Movidius graph in order to increase FPS for face recognition on RPi platform?

    • Adrian Rosebrock June 26, 2018 at 8:21 am #

      See my reply to Mansoor.

  6. Gus June 25, 2018 at 6:29 pm #

    Hi Adrian! I recently discovered your site and I love your tutorials. I have a question about implementing the face detection technique you described in your post “Face detection with OpenCV and deep learning” with the face recognition technique described here on a RPI3. The caffe model from the previous post achieves between 1 and 0.25 fps on my PI (running a few other real-time things). I’ve yet to implement the face recognition technique described in this post but it sounds like this method will slow my face detection/recognition pipeline down to about 0.1 fps or worse. I’m really impressed by the accuracy of the caffe model vs the haar cascades so I’d like to continue using them if possible. Do you have any suggestions for using these two models together on a RPI? I don’t expect to achieve anywhere near real-time performance but a frame rate of ~0.5fps would be nice if possible.

    • Adrian Rosebrock June 26, 2018 at 8:24 am #

      The Pi just isn’t fast enough to run both the Caffe face detector along with dlib’s facial embedding network. There isn’t really any “tricks” here, unfortunately. You’ll likely less than 1 FPS if you try to combine both of them on the Pi. There is some work being done with the Movidius NCS (see other comments on this post) to help speedup the pipeline but all the pieces aren’t quite there yet.

  7. Xue Wen June 25, 2018 at 7:29 pm #

    Thank you for the wonderful post! Always wait for your post to learn new things. Are you planning to write a blog about running face recognition on Intel Movidius NCS?

    • Adrian Rosebrock June 26, 2018 at 8:19 am #

      I’m considering it but I do not have any definite plans yet.

  8. naitik June 25, 2018 at 10:42 pm #

    Thanks for creating this level of informative posts which anyone can learn, This post is also very informative and useful too..
    Can i ask you for some more updated posts on OCR from image let’s say my driving license with current advancements in the field will be really helpful for many.

  9. Ian Carr-de Avelon June 26, 2018 at 12:14 am #

    Dear Adrian,
    In your post on face recognition on the Raspberry Pi you say:
    “is naturally limited in terms of computation power and memory (especially without a GPU)”

    I can’t imagine that you are unaware that different information is out there:
    ” and on-chip graphics processing unit (GPU).”

    apparently the most openly documented GPU:

    and other video hardware they will uncripple for a price:

    What are you saying? Is this all “fake news”? or the Pi’s GPU is some kind of joke you shouldn’t really call GPU? or you just mean it’s not supported by your favourite software?


    • Adrian Rosebrock June 26, 2018 at 8:18 am #

      Indeed, the Pi does have a GPU. The problem is pushing the computation to the GPU using existing libraries — it’s not an easy task. Secondly, I would suggest you read through Pete Warden’s post again. Notice how the inference on a single image took 3.3 seconds (even while using the GPU).

      The Raspberry Pi GPU is not a “joke” but when people think of GPUs they are normally thinking of more powerful ones, such as NVIDIA’s line. Keep in mind that the Raspberry Pi, no matter what, is still limited by it’s power draw and processing power. It’s not a powerful GPU.

      Furthermore, while OpenCL is making it easier, but we’ve still got a long way to go.

  10. Anthony The Koala June 26, 2018 at 2:51 am #

    Dear Dr Adrian,
    Thank you for this tutorial. My particular question is about increasing the frame rate. You informed us about using eigenfaces and local binary patterns (LPB) as a method of increasing the processing rate.

    You also have a tutorial at https://www.pyimagesearch.com/2017/02/06/faster-video-file-fps-with-cv2-videocapture-and-opencv/ which talks about faster video file FPS with cv2.VideoCapture and OpenCV, and another tutorial at https://www.pyimagesearch.com/2015/12/28/increasing-raspberry-pi-fps-with-python-and-opencv/.

    Would these tutorials help with speeding up the processing?

    Thank you,
    Anthony of Sydney

    • Adrian Rosebrock June 26, 2018 at 8:14 am #

      Both do. It just depends if you’re using a USB camera or the Raspberry Pi camera module. I actually implemented the VideoStream class in this blog post to combine the two blog posts you are referring to into an easy to use class. The code used in this post is already taking advantage of threaded video stream.

  11. Amit Roy June 26, 2018 at 5:00 am #

    Adrain, check below blog.


    They claimed to achieve 18FPS on Pi-Zero-W with ResNet18 trained on CIFAR-10 with their technology. And they claim that they were your students 🙂

    • Adrian Rosebrock June 26, 2018 at 8:11 am #

      This is awesome, thanks so much for sharing Amit! 😀

  12. Lotfi June 27, 2018 at 5:03 am #

    Hello Adrian,

    Firstly Thanks for this tutorial Adrian.

    i have a RaspberryPi and i want do the same thing that you do, but instead o do detection and the recongition in the raspberryPi , i want to stream the camera feed to the cloud and do all the proccesing their because raspberryPi is very slow.

    could you suggest me a way to do that, especially the stream step.


    • Adrian Rosebrock June 27, 2018 at 2:48 pm #

      Thanks for reaching out. I don’t have any tutorials on taking a Raspberry Pi stream and piping it to the cloud for processing, but if I do cover it in the future, I’ll certainly let you know.

      However, I will say that if your goal is true real-time processing that this likely isn’t a good idea. The I/O latency introduced by network overhead will be slower than just processing the frame locally.

  13. Daniel Lopez June 28, 2018 at 6:20 am #

    Hello Adrian,
    First of all thanks for this tutorial.
    I’m having problems when trying to install the dlib libraries on my Raspberry Pi 3 Model B.
    I’m using your Raspbian.img on 32GB SD card, updated and upgraded the system (as suggested in some post) and using this command to get into the Python3 + OpenCV environment:
    source start_py3cv3.sh

    Once I got the py3cv3 shell I have tried: pip install dlib
    and the libraries downloaded fine but the installation procedure never finish ( it was running for almost one hour) and the command cc1plus is using almost the 100% of the CPU.

    Any help will be appreciate.

    • Daniel Lopez June 28, 2018 at 7:04 am #

      Hi again,

      please discard this post, finally the library was installed (it took almost two hours to complete)


      • Adrian Rosebrock June 28, 2018 at 7:55 am #

        Indeed, it can take awhile for dlib and the face_recognition libraries to compile and install. Congrats on configuring your Pi for face recognition, Daniel!

  14. Julian June 28, 2018 at 6:32 pm #

    Hello Adrian,
    i really appreciate your work !
    But i have a problem right now. If i want to intall the dlib toolkit, the installation stucks at “Running setup.py bdist_wheel for dlib…” this also happens if i try to install the face_recognition module.
    I tried to install dlib by your guide :https://www.pyimagesearch.com/2018/01/22/install-dlib-easy-complete-guide/ but if i want to check at the end if its installed it doenst show up in the terminal. I dont know why it is not working. Any idea?

    • Adrian Rosebrock June 29, 2018 at 5:33 am #

      It’s probably not “stuck” — it’s more likely compiling and installing. Check your CPU usage and let the Pi sit overnight just to make sure.

  15. Lucian June 29, 2018 at 11:11 am #

    Hi Adrian

    Will you ever make a tutorial for object detection based on HOG/SVM which not includes face detection ?

    I am asking because, using Haar cascades, this task seems to be “too simple” compared to detecting, for example, an apple / a car / a pen.


    • Adrian Rosebrock July 1, 2018 at 6:38 am #

      Hey Lucian — I actually cover HOG + Linear SVM detectors for non-face detection inside the PyImageSearch Gurus course. One of the examples in the course is training a car detector with HOG + Linear SVM.

  16. pursotam niraula July 4, 2018 at 2:21 am #

    cant we detect particular object in the similar way??

    • Adrian Rosebrock July 5, 2018 at 6:36 am #

      You would need a model trained to recognize an object. If you’re new to object detection give this post a read.

  17. Michael July 4, 2018 at 6:45 am #

    Hi Adrian. First of all, I’m sure that you haven’t heard it before :-): you articles rocks. Very informative and interesting, but also pedagogical.

    I’m building an architecture of different classifications of live video from multiple Raspberry Pi’s (Zero’s preferred) where I need to classify:
    1. different objects (people, cars, animals)
    2. states in specific locations in in the image (door open/door closed
    3. face detection/recognition

    I lean towards 3 different models, but would like to hear your take on this architecture?

    I’m satisfied with 1-2 FPS, so with the architecture of 3 models in mind (3 * 1-2 FPS = 3-6 FPS), I believe the Pi will come to short. I’m therefore thinking of a low powered centralized unit that handles image processing from 3-4 livestreams (3-4 Pi’s * 3-6 FPS = 9-24 FPS)
    What low powered unit do you recommend to handle this processing or do you recommend another overall architecture?

    • Adrian Rosebrock July 5, 2018 at 6:31 am #

      The Pi Zero is far too underpowered — I would immediately exclude it unless you wanted to play around with something like a Movidius NCS or Google’s AIY kit, but then you need to be concerned with power consumption as I assume you are. You could have a centralized system for processing all frames but keep in mind network overhead — while the central machine is technically faster you also need to account for the time it takes for the frame to be transmitted and the results returned. You might want to run some experiments to determine if that is viable. Otherwise, you might be able to replace the entire Pi architecture with a Jetson TX1 or TX2.

      • Michael July 11, 2018 at 1:53 am #

        Hi Adrian,
        Thank you for the quick answer. Yeah, need to do some testing with network latency.

        Have a wonderful summer

  18. Chris July 6, 2018 at 5:26 pm #

    Hi David,

    Which generation Raspberry Pie did you use for this case?

    • Chris July 6, 2018 at 5:29 pm #

      Also, will the 1st generation Raspberry Pie work for this case, if performance is not a concern at this moment? It is said to be an ARM11 running at 700MHz

      • Adrian Rosebrock July 10, 2018 at 8:49 am #

        I used a Pi 3B for this example. I would not use a Pi 2 or earlier.

  19. Patrik July 6, 2018 at 9:41 pm #

    Hi Adrian!
    Is it possible that the face recognition omit the photographs?


    • Adrian Rosebrock July 10, 2018 at 8:48 am #

      Hey Patrik — could you be a bit more specific in what you mean by saying omitting a photograph?

  20. Paul Christian July 9, 2018 at 11:14 am #

    Adrian, thanks for your efforts in developing this demo. Can you please tell me the OS version on RPi that you used? I have been having a difficult time just getting the python packages installed! Also, did you develop and test the detector on a PC or MAC then transfer to the RPi? If not, what editor did you use on the RPi? The default RPi editor is unable to find the required python libraries? The python 3 command line can identify the libraries.

    Thanks for the help

    • Adrian Rosebrock July 10, 2018 at 8:23 am #

      I used Raspbian Stretch for the example. I normally use either Sublime Text or PyCharm with the SFTP plugin to code on my Mac but the code itself is actually stored on the Pi. Sublime Text will run on the Pi though, that’s another good option.

      If you are having trouble getting your Pi configured make sure you take a look at my Raspbian .img file included in the Quickstart Bundle and Hardcopy Bundle of my book, Practical Python and OpenCV. The .img file comes with OpenCV, Python, and the face recognition modules pre-installed. Just flash the .img file to your Pi, boot, and you’re good to go. It will save you a lot of time and hassle.

  21. Antony Smith July 11, 2018 at 6:49 am #

    Hey Adrian, will try a couple ideas on this one but it seems I’m the only one to get the:

    ValueError: unsupported pickle protocol: 3

    when it come to line 22: data = pickle.loads(open(args[“encodings”], “rb”).read())?

    Any idea what could be causing this as I get the same error if I just run the rec on a single still image.
    Same ‘pickle’ error, though no error on importing any of the libraries?

    • Adrian Rosebrock July 13, 2018 at 5:17 am #

      Which version of Python are you using? I would suggest you re-run the script to extract the facial embeddings (which generates the pickle file). Then try to execute the facial recognitions scripts.

  22. Khaw Oat July 12, 2018 at 1:21 pm #

    Is this a deep learning?

    • Adrian Rosebrock July 13, 2018 at 5:01 am #

      It’s using deep learning under the hood. See this post for more details.

      • Khaw Oat July 13, 2018 at 6:40 am #

        I don’t understand this word.

        • Adrian Rosebrock July 13, 2018 at 7:30 am #

          Hood as in “under the hood of a car”. The blog post I linked you to will show you how deep learning object detection works similar to how if I opened the hood of a car you would see how the engine works.

          • Khaw Oat July 13, 2018 at 10:37 am #

            Thank You.
            I’m working on a deep learning project.

  23. Vincent Kok July 15, 2018 at 10:04 am #

    Hi Adrian,

    Very cool tutorial! I am doing some research on how a small or large database would affect the performance of the face recognition. Any ways I could measure the performance/time from when the input image is given to it is being recognize as a person ID? I would like to try for a database with 100 person VS 50 person to see if there is speed difference.
    Hope you could help me on this.


    • Adrian Rosebrock July 17, 2018 at 7:26 am #

      All you would need is a simple call to the “time” function in Python:

      From there you can perform your evaluation.

  24. Kasidet Pea July 16, 2018 at 9:44 pm #

    Hi Adrian! Thanks for this tutorial. Would you recommend what camera I could use to do face recognition with raspberry pi

  25. Sahil July 17, 2018 at 4:21 am #

    Instead of only name, is it possible to make a user interface that can display all the information of person.?

    • Adrian Rosebrock July 17, 2018 at 7:08 am #

      Sure, that’s totally possible. You’ll want to look into dedicated Python GUI libraries such as TKinter, QT, and Kivy.

Leave a Reply