The principle of operation:
- Person approaches to the intercom
- Looks at the camera
- The system compare his face with authorized people
- If it finds it, then the door opens and a person can enter
- There is also another way to pass;
- The person with the pass card place it to the RFID location and the door opens if it finds the code of this card in its database
**This project is still in work. I hope the final version will be more beautiful.
Preparation:
Relay connection
- Connect relay to RPI 3. In my case i used GPIO12 pin for data , 5v for power and you can choose any GND.
You can test the relay with shell script, just create a simple sh script:
nano open.sh
chmod +x open.sh
sh open.sh
paste the code below and run it
Script code:
#!/bin/bash
echo 12 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio12/direction
echo 0 > /sys/class/gpio/gpio12/value
ping -c 1 localhost
echo 12 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio12/direction
echo 1 > /sys/class/gpio/gpio12/value
Camera connection
- Connect camera module and enable it in raspi-config:
Open the raspi-config tool from the Terminal:
sudo raspi-config
Select Enable camera and hit Enter, then go to Finish and you'll be prompted to reboot.
To test that the system is installed and working, try the following command:
raspistill -v -o test.jpg
Led Connection
Connect your led to any gpio you want + GND. In my case i used GPIO16 for green led and GPIO26 for red. When you are done, test it:
Create 2 simple python scripts for green and red led with following content:
- Green led.py
from gpiozero import LED
from time import sleep
led = LED(16)
while True:
led.on()
sleep(3)
led.off()
led.cleanup()
- Red led2.py
from gpiozero import LED
from time import sleep
led = LED(26)
while True:
led.on()
sleep(3)
led.off()
led.cleanup()
And then test it. If led's are glowing, then everything works good.
python led.py
python led2.py
Face Recognition Script
Install this module from pypi using pip3(or pip2 for Python 2):
pip3 install face_recognition
Create directory "pic" and "unknown" in Documents for example and place there some face pics of people you know. My case it's ("/home/pi/Documents/pic/") and ("/home/pi/Documents/unknown/").
Create python script with following code
import face_recognition
import picamera
import numpy as np
import os
camera = picamera.PiCamera()
camera.resolution = (320, 240)
output = np.empty((240, 320, 3), dtype=np.uint8)
print("Loading known face image(s)")
ep_image = face_recognition.load_image_file("/home/pi/Documents/pic/ep.jpg")
ep_face_encoding = face_recognition.face_encodings(ep_image)[0]
vl_image = face_recognition.load_image_file("/home/pi/Documents/pic/vl.jpg")
vl_face_encoding = face_recognition.face_encodings(vl_image)[0]
face_locations = []
face_encodings = []
while True:
print("Capturing image.")
camera.capture(output, format="rgb")
face_locations = face_recognition.face_locations(output)
print("Found {} faces in image.".format(len(face_locations)))
face_encodings = face_recognition.face_encodings(output, face_locations)
for face_encoding in face_encodings:
match = face_recognition.compare_faces([ep_face_encoding,vl_face_encoding], face_encoding)
name = "<Unknown Person>"
os.system("python /home/pi/led2.py &")
import time
date_string = time.strftime("%Y-%m-%d-%H:%M:%S")
camera.capture("/home/pi/Documents/unknown/image-" + date_string + ".jpg")
Test it
python facerec.py
RFIDConnection
Pins:
We need this to connect our RFID module to Raspberry pi 1.
- Preparation
$ sudo nano /etc/modprobe.d/raspi-blacklist.conf
#blacklist spi-bcm2708
$ sudo apt-get install python-dev
$ git clone https://github.com/lthiery/SPI-Py.git
$ cd SPI-Py
$ sudo python setup.py install
- read.py When the script finds authorized card, it opens user picture on the remote RPI 3 (runs led scripts), then it opens the door.
import MFRC522
import signal
import os
continue_reading = True
MIFAREReader = MFRC522.MFRC522()...
Read more »
very impressive! I will set this up soon!