In this DIY project, we are going to build a Raspberry Pi face recognition smart doorbell that identifies the person on the door, for example it will inform whether the person is a family member, a friend or a stranger.
How Raspberry Pi face recognition doorbell works?
- Process each video frame at 1/4 resolution
- Detect faces in every other frame of video.
- Load sample pictures of known faces in memory and learn how to recognize.
- See if the face is a match for the known face(s)
- Call the “espeak” speech synthesis to say the name of person in video.
We need to collect the following components before starting the project.
- Raspberry pi with 1GB or higher RAM
- Raspberry pi Camera
- Pam 8403 Amplifier (Or any speaker)
- A plastic box or case for enclosure
- A RPI power adapter
First, open RPi SSH or Terminal and install the required libraries and modules. Then install the espeak module, followed by the espeak library for Python. Follow the snippet below for installation. (Refer Fig 1,2).
Now install the ‘opencv’, ‘numpy’, ‘dlib’ library. You might need to swap the memory for installation. Follow the instruction for installation of opencv and dlib available on the internet.
After that install the face recognition library for python 3 using the following command in the terminal.
‘pip3 install face recognition’
As we have installed our required library, let’s start coding.
First open the folder of ‘Face Recognition’ library folder and then paste the images of those friends/family members who you want the doorbell to identify. You get the folder in this directory
Then open the “facerec_from_webcam_faster” example and make a copy of that with bell or any other name.
Now let’s understand the code and make some changes in it for face recognition doorbell.
Here in the first part of the code we import the following required library in python code (Refer Fig 3).
After that we have to create different arrays for known faces as well as the array of their names. Then we have to write the image file name for the face recognition of that member (Refer Fig 4)
In the next part of code, we will try to match the face in camera video with the array of known faces. If the face matched then the code will run the espeak synthesizer to call the name of that person using the syntax ‘espeak.synth ()’ as in the pic below. We can also add other function here after the face recognition (Refer fig 5.)
Now connect the camera module ribbon with RPi camera pin as in the pic below.
Then solder the wires at the analog out pin of raspberry pi TRRS pin as in Pic below (Refer Fig 7).
Then connect the Pam8403 to RPi analog pin as in Fig 8.
Now set everything in an enclosure of your choice as in Fig 9. Then power the raspberry pi and use VNC for remote raspberry display (For VNC setup you can see instruction on VNC installation process on internet). After that run the python code that we have just made for doorbell. When you run the code, you will get window on raspberry pi, displaying the camera video when any person come near the camera.It will recognize the face and try to match the face with known face. If it matches it will announce the name of person present at door.
Note:- We will soon update it with more features
Download Source Folder
We have also designed a corona-protected doorbell too using Arduino. This is touchless and works only if the person’s hands are sanitized. For that, we have used an MQ3 sensor.
there is only one python program file in the zip no more files are there
how does cv2.videocapture(0) work with pi camera?