Implementing Face Recognition on Raspberry Pi

Implementing Face Recognition on Raspberry Pi

In the near future, face recognition and identity authentication technology will play a very important role in our daily lives. This technology opens up a whole new world for us, and it is applicable to almost every aspect of our lives. Use cases for face recognition/identity authentication include security systems, authentication systems, personalized smart homes, and home care assistants.

What will we build?

This tutorial will help you build a Raspberry Pi that can train the HARASCALDES model, which can be used to detect recognized/unrecognized individuals, monitor in real-time using a surveillance camera, and use the IoT JumpWay to send sensing and alert messages, allowing your devices to communicate with other devices via other IoT JumpWay networks.

This tutorial will utilize the TechBubble Technologies IoT JumpWay Python MQTT library for communication, implement computer vision using OpenCV, and build a mobile web stream and secure NGNX server on a local port for secure external access to the video stream.

This example is our initial TASS version; as our progress relies on many more advanced computer vision libraries and frameworks, we decided to open-source the code.

Python Versions

  • Version 2.7

  • Version 3.4 or higher

Software Requirements

  • Jessie

  • TechBubble IoT JumpWay Python MQTT Client (https://github.com/TechBubbleTechnologies/IoT-JumpWay-Python-MQTT-Clients)

  • Linux Drivers

  • Nginx

Hardware Requirements

  • Raspberry Pi

  • Linux compatible camera

Preparation

Before starting, there are several tutorials you should check out, especially if this is your first time following our Raspberry Pi tutorials or if this is your first time using the TekBaseIO-JavaWoW development program. If this is your first time using TechBubble IoT JumpWay in an IoT project, you need to register a developer account before creating IoT devices and perform some basic setups. Visit the IoT JumpWay developer usage documentation (5-10 minutes reading/setup https://github.com/TechBubbleTechnologies/IoT-JumpWay-Docs/) and check the guide to register and set up your location, zone, devices, and applications (about 5 minutes).

  • IoT JumpWay Developer Program Documentation

  • Prepare your Raspberry Pi

  • Set up the zone name & SSL for Raspberry Pi

  • Configure OpenCV on your Raspberry Pi

  • Configure Linux drivers on your Raspberry Pi

  • Install Linux drivers on Raspberry Pi

  • Secure Raspberry Pi with IPTables

Prepare your Raspberry Pi

Take some time to ensure that your Raspberry Pi hardware and packages are up to date, and make sure your preparation process strictly follows the Raspberry Pi 3 tutorial file (https://github.com/TechBubbleTechnologies/IoT-JumpWay-RPI-Examples/blob/master/_DOCS/1-Raspberry-Pi-Prep.md), and that the device is secure.

Clone Repo

You will need to download the echBubble IoT JumpWay (https://github.com/TechBubbleTechnologies/IoT-JumpWay-RPI-Examples) Raspberry Pi instance Examples library to your Raspberry Pi and navigate to the directory you want to download to; the following command is the easiest way to download it to your home directory.

git clone https://github.com/TechBubbleTechnologies/IoT-JumpWay-RPI-Examples.git

Install Requirements

Next, you need to navigate to the directory of the computer vision library and install the requirements; if you have already copied the library to your home directory, then the commands for this part are as follows:

cd IoT-JumpWay-RPI-Examples/Computer-Vision/Python
pip install --upgrade pip
pip install -r requirements.txt

Install OpenCV

OpenCV needs to follow the Raspberry Pi tutorial (https://github.com/TechBubbleTechnologies/IoT-JumpWay-RPI-Examples/blob/master/_DOCS/2-Installing-OpenCV.md) for installation; it is a computer vision library we will use.

Install Linux Drivers

We will use Linux drivers to transmit the video stream to the local port on Raspberry Pi; OpenCV connects to the video stream here and reads image frames from it. To establish Linux drivers, follow the installation tutorial (https://github.com/TechBubbleTechnologies/IoT-JumpWay-RPI-Examples/blob/master/_DOCS/5-Installing-Motion.md) to install Linux drivers on your Raspberry Pi.

Here are some modifications; in section 9 of the driver installation tutorial, it tells you how to modify the media save directory; in this tutorial, you should change these settings to:

/home/YOURUSERNAME/IoT-JumpWay-RPI-Examples/Computer-Vision/Python/media

Don’t forget to note the issue about turning off image saving in section 10 to save disk space.

Set Up Domain Name and SSL

We hope that the tutorial we provide can help people learn to create secure projects. To make the video stream work securely, you need to set up a domain name pointing to your Raspberry Pi, and you also need to set up an SSL certificate to ensure that the server used for the video stream is secure. The Raspberry Pi domain name and SSL setup tutorial (https://github.com/TechBubbleTechnologies/IoT-JumpWay-RPI-Examples/blob/master/_DOCS/3-Raspberry-Pi-Domain-And-SSL.md) will explain in detail how to do this; if you have any questions, you can ask your registrar or host for assistance. If you have copied this repository to your home directory, you need to use the following CSR and key generation paths:

/etc/nginx/key.key
/etc/nginx/csr.csr

Once you receive your signed crt.crt and ca.crt files from the certificate authority, you need to upload them to:

/etc/nginx/ca.crt
/etc/nginx/crt.crt

Install Secure NGINX Server for Linux Drivers

We will use NGINX as our server solution and set it to an A+ SSL rating in the QualSS-SSL lab SSL report. To do this, we provide a guide to install the NGINX server on the Linux driver on RasBuriPi (https://github.com/TechBubbleTechnologies/IoT-JumpWay-RPI-Examples/blob/master/_DOCS/6-Secure-Nginx-Server-For-Motion.md). Before starting this step, you need to install Linux drivers on your Raspberry Pi (https://github.com/TechBubbleTechnologies/IoT-JumpWay-RPI-Examples/blob/master/_DOCS/5-Installing-Motion.md) and set up the domain name and SSL for your Raspberry Pi (https://github.com/TechBubbleTechnologies/IoT-JumpWay-RPI-Examples/blob/master/_DOCS/3-Raspberry-Pi-Domain-And-SSL.md).

Secure Raspberry Pi with IPTables

The next security step you should take is to set up IPTABLE. Follow the Securing Your Raspberry Pi With IPTables document (https://github.com/TechBubbleTechnologies/IoT-JumpWay-RPI-Examples/blob/master/_DOCS/4-Securing-Your-Raspberry-Pi-With-IPTables.md) to implement this.

Video Stream

If you have followed the above steps, and if they are not running, you need to follow the steps below.

sudo service motion start
or
sudo /etc/init.d/motion start
start NGINX
sudo service nginx start
or
sudo /etc/init.d/nginx start

It is important: this streaming is a new feature, and we are still eliminating some knots; if you want OpenCV to access the network camera directly without the driver/NGNIX stream, then uncomment line 43 in TASS.py, and comment lines 44 and 45.

Connect Certificates and Sensor Settings

The next step is to install the device instance in the Internet JumpWay developer console. Follow the IoT JumpWay Location Device Doc (https://github.com/TechBubbleTechnologies/IoT-JumpWay-Docs/blob/master/4-Location-Devices.md) to set up your device. You will need to set up a device with CCTV and add the sensor/actuator section.

Retrieve your connection certificate and update the configuration JSON file with the new connection certificate and camera ID (you need to go to the device page after creating it to get the correct camera ID).

"IoTJumpWaySettings": {
        "SystemLocation": 0,
        "SystemZone": 0,
        "SystemDeviceID": 0,
        "SystemDeviceName" : "Your Device Name",
        "SystemCameraID":0
    }
 "IoTJumpWayMQTTSettings": {
        "username": "Your MQTT Username",
        "password": "Your MQTT Password"
    }

Train Your Data

Now that the basic framework has been set up, it is time to train your model with your own photos. When you download this RPO, there is already a trained model and processed images in that processed folder, but this model will not recognize you. You need to select photos of yourself in different locations and lighting. The more photos you train the model with, the more accurate it will be; if your device does not recognize you, you just need to train it with more images.

You can add as many images as you like (depending on the space available on your Raspberry Pi 3); there are many people like you. To navigate the training data to the training folder and create a directory, the directory should be a number and not the number in the processed folder.

Once you have created the image folder, go into the Tas.Py file and change line 34 (self.train = 0) to self.train = 1, and start the program. The program will loop to detect your images; if it detects a face, it will recreate an image in the required format for the model, save it to the matching folder in the processed directory, and delete the original image to save space. If it does not detect a face, it will simply delete the original image as it is an invalid face recognition.

Once the processing phase is complete, your new model will automatically start training, and when the training is complete, it will automatically run the main face recognition program. Put your face in front of the connected camera and watch the program output who you are.

Note: Delete the readme file from the processed directory.

Run the Program

sudo python/python3 TASS.py

Autonomous IoT Communication

Whenever your device detects a person, it will send sensor data to TechBubble IoT JumpWay (https://iot.techbubbletechnologies.com/), and when the motion sensor detects an intruder, it will issue an alert. You can use sensor values and alert messages to achieve autonomous communication with other devices connected to IoT JumpWay Location.

On the “Device Edit” page, scroll down to the “Create Rules” section under “Actuators/Sensors.” You can create rules here using the dropdown menu, allowing your device to send you emails or autonomously communicate with other devices on its network in the case of status updates, sensor data, and alerts.

View Data

Each time your device detects a person or an intruder, it will send data to TechBubble IoT JumpWay. You will be able to access the data in the TechBubble IoT JumpWay developer zone (https://iot.techbubbletechnologies.com/developers/dashboard/). Once logged into the developer zone, visit the TechBubble IoT JumpWay Location Devices Page (https://iot.techbubbletechnologies.com/developers/location-devices), find your device, and access the sensor/actuator page and alert page to view the data sent from your device. IoT JumpWay Raspberry Pi computer vision instance defects/issues.

When you encounter difficulties running the IoT JumpWay Raspberry Pi computer vision instance, please remain calm; you can also seek help in the question area when you encounter trouble.

IoT JumpWay Raspberry Pi Instance Contributors

Founder of TechBubble Technologies: Adam Milton Barker TechBubble Technologies Dev Company: Andrej Petelin Original link: https://www.hackster.io/AdamMiltonBarker/facial-recognition-identification-on-raspberry-pi-1c7495 Translated from Leifeng Network: https://club.leiphone.com/page/TextTranslation/624

The links in the text can be clicked to read the original text at the end

Implementing Face Recognition on Raspberry Pi

More Exciting Content

Make a wireless controller for GoPro with Arduino

Create a “magical” infinite mirror

TensorFlow 1.9 now officially supports Raspberry Pi!

Implement video streaming media WEB server with Raspberry Pi + Flask

Raspberry Pi-based multi-servo control positioning photography platform

How to install Windows 10 ARM on Raspberry Pi 3B

Install Nginx + PHP7.0 + Pi Dashboard on Raspberry Pi

Implementing Face Recognition on Raspberry Pi

Leave a Comment

×