Facial Recognition Robot

Objective: To create a Facial Recognition Robot using Raspberry Pi. This is a small project where I can use the knowledge to learn about the Amazon Rekognition a deep-learning image analysis service, a little practice of programming and at the end to complete my dream robot Autonomous Robot. Please continue to check my Test Robot page for update.

Requirements:

  1. Raspberry Pi 2 or 3, both will work.
  2. Raspberry Pi Camera
  3. Monitor, Keyboard and Mouse. Most of us already have this in our network lab.

I bought an old Raspberry Pi through Amazon to be the brain of this project. I downloaded Raspbian for my operating system, basically a lite debian linux. I copied this to the microSD that I will use to boot Raspberry Pi.

To check the Raspberry Pi operating system version. In terminal, type “cat /etc/os-release“. This will show something like this.

PRETTY_NAME=”Raspbian GNU/Linux 7 (wheezy)”
NAME=”Raspbian GNU/Linux”
VERSION_ID=”7″
VERSION=”7 (wheezy)”
ID=raspbian
ID_LIKE=debian
HOME_URL=”http://www.raspbian.org/”
SUPPORT_URL=”http://www.raspbian.org/RaspbianForums”
BUG_REPORT_URL=”http://www.raspbian.org/RaspbianBugs”

And if you want to check the kernel version. In terminal, type “uname -a” currently using Kernel 3.x

I run “sudo get-apt update” to get the latest update.

Then, “sudo get-apt dist-upgrade” to upgrade the software. This is to make sure that I have the latest operating system on my raspberry pi. It will take some time to complete.

After several minutes later …

$ uname -a [enter]

Linux raspberrypi 4.1.19-v7+ #858 SMP Tue Mar 15 15:56:00 GMT 2016 armv71 GNU/Linux

I was able to upgrade my kernel version from 3.x to 4.1.19, but not the raspbian still version 7 (wheezy).

I re-run “sudo get-apt update” and “sudo get-apt dist-upgrade“.

0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

But Raspbian still version 7 (wheezy). I need to have the latest version 8. Searching for solution continue … I found it from the Raspberry Pi website (https://www.raspberrypi.org/blog/raspbian-jessie-is-here/). It is recommended a clean install of Jessie, too much work for me. I will do the update, if this breaks then I will do the clean install of Jessie.

Stack Exchange forum, got these steps.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo sed -i /deb/s/wheezy/jessie/g /etc/apt/sources.list
sudo sed -i /deb/s/wheezy/jessie/g /etc/apt/sources.list.d/*.list
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade

 

The upgrade takes hours to complete. It is faster a clean install of Raspbian version 8 (jessie) than doing the upgrade. So, don’t waste your time doing upgrade.

$ cat /etc/os-release [enter]

PRETTY_NAME=”Raspbian GNU/Linux 8 (jessie)”
NAME=”Raspbian GNU/Linux”
VERSION_ID=”8″
VERSION=”8 (jessie)”
ID=raspbian
ID_LIKE=debian
HOME_URL=”http://www.raspbian.org/”
SUPPORT_URL=”http://www.raspbian.org/RaspbianForums”
BUG_REPORT_URL=”http://www.raspbian.org/RaspbianBugs”

Update: October 4

Next, preparing the Raspberry Pi – Web Camera.

This is a facial recognition robot, I need to store all the images that my robot will see.

But before we go further. Let’s change the default hostname from “raspberrypi” to something else. This is a Facial Recognition project, so I’m calling my Raspberry Pi as “facial“. You can change this using /etc/hosts and /etc/hostname, from “raspberrypi” to “facial”. Another method is using “sudo raspi-config” then select 2. Hostname to change it. Both action will work.

For this project, I run the following command to update the hostname.

sudo raspi-config [enter] this will open a GUI screen. I selected option 2 for Hostname, change it to “facial“, click ok to save. Then, reboot.

I will use the following command to check my changes.

cat /etc/hosts

cat /etc/hostnames

If everything is correct, you will see your new host name in there. You can also run “ping facial” to test if Raspberry Pi recognize your new host name.

Now the fun part, installing RPi Cam Web Interface.

The RPi Cam Web Interface is a web interface for the Raspberry Pi Camera module. It can be used for a wide variety of applications including surveillance, dvr recording and time lapse photography.

For my purpose, storing images for later comparison.

Let’s proceed.

Turn-off the Raspberry Pi. I attached the web Camera on Raspberry Pi board. Plug-in the power to boot up. Follow the instruction provided my RPi Cam Web interface.

I just updated my Raspberry Pi, but if you haven’t done it. Run the following command.

sudo apt-get update
sudo apt-get dist-upgrade

For Jessie Lite run sudo apt-get install git

Clone the code from github and enable and run the install script with the following commands:

git clone https://github.com/silvanmelchior/RPi_Cam_Web_Interface.git
cd RPi_Cam_Web_Interface
./install.sh

5 separate scripts are provided to do separate installation and maintenance functions.

The scripts are

  • install.sh main installation as used in step 4 above
  • update.sh check for updates and then run main installation
  • start.sh starts the software
  • stop.sh stops the software
  • remove.sh removes the software
  • To run these scripts make sure you are in the RPi_Cam_Web_Interface folder then precede the script with a ./
  • E.g. To update an existing installation ./update.sh
  • E.g. To start the camera software ./start.sh
  • E.g. To stop the camera software ./stop.sh

The main installation always does the same thing to simplify its logic. It gathers all user parameters first in one combined dialog and then always applies the parameters as it goes through the process. Autostart should be yes if you want this software to start automatically when raspberry boots up. jpglink should normally be no. Change it to yes if you have external software that needs direct access to the cam.jpg image file.

Wait for the GUI (Configuration Option) to show up, so we can continue the setup. You will see some like this.

  • Cam subfolder: – html
  • Autostart: (yes/no) – yes
  • Server: (apache/nginx/lighttpd) – apache (the default) I changed it to nginx for this project.
  • Webport: 80
  • User: (blank=nologin)
  • Password:
  • jpglink: (yes/no) no
  • phpversion: (5/7) 7

When ready to install, select OK to proceed. Wait for the system to finish.

Start camera system now? Yes to continue.

Got an error: mmal_vc_component_create_core:  Could not create component “vc.ril.camera’ /var/www/html/macros/error_hard.sh Permission denied

I reboot the Raspberry Pi to see if it will correct the error.

To test it, open a browser and go to http://YourIPAddress:80/subfolder

Still can’t access my website “This website at http://192.168.0.x seems to be unavailable. The precise error was. Could not connect: Connection refused.

I run sudo raspi-config to enable my camera.

$ sudo raspi-config [enter]

In Raspberry Pi Software Configuration Tool, select option 5, select Camera press enter.

Would you like the camera interface to be enabled? Yes

The camera interface is enabled. Click OK. Restart if needed.

For some reason, the installation of web server didn’t work as plan. So, I re-install it step by step.

Start with NGINX web server.

sudo apt-get update
sudo apt-get install nginx

Install PHP5

sudo apt-get install php5-fpm

Still not working …

I un-install the NGINX.

cd RPi_Cam_Web_Interface
./remove.sh

then re-install, but this time using Apache for web server.
./install.sh

  • Cam subfolder: – html
  • Autostart: (yes/no) – yes
  • Server: (apache/nginx/lighttpd) – apache (the default)
  • Webport: 80
  • User: (blank=nologin)
  • Password:
  • jpglink: (yes/no) no
  • phpversion: (5/7) – I left it blank

Restarted Raspberry Pi.

Then, start
$ startx [enter] to enter GUI mode.

Testing apache web server.

Start Epiphany Web Browser, enter the URL address.

http://192.168.0.x or http://facial  (the name of Raspberry Pi)

It Works! Well, the Apache Web Server.

Going to http://192.168.0.x/html (sub-folder) for RPi Cam got an error.

Error in RaspiMJPEG:
Restart RaspiMJPEG (./RPi_Cam_Web_Interface_installer.sh start) or the the whole RPi.

Running ./RPi_Cam_Web_Interface_installer.sh start

Produce the same error.

Got an error: mmal_vc_component_create_core:  Could not create component “vc.ril.camera’ /var/www/html/macros/error_hard.sh Permission denied

Let’s check if the camera is being recognize by the Raspberry Pi. Run this command.

raspistill -o image.jpg [enter]. This is to capture an image in jpeg forma.

Test result with error:

  • mmal: mmal_vc_component_create: failed to create component ‘vc.ril.camera’ (1:ENOMEM)
  • mmal: Failed to camera component
  • mmal: main: Failed to camera component
  • mmal: Camera is not detected. Please check carefully the camera module is installed correctly.

Searching Google for solution … in progress.

Update. October 8

The camera did not work for me, so I decided to replaced it.

Today, I received my new camera and will be testing it. See how it goes.

Then, start again.

I run sudo raspi-config to enable my camera.

$ sudo raspi-config [enter]

In Raspberry Pi Software Configuration Tool, select option 5, select Camera press enter.

Would you like the camera interface to be enabled? Yes

The camera interface is enabled. Click OK. Restart if needed.

$ startx [enter] to enter GUI mode.

Testing apache web server.

Start Epiphany Web Browser, enter the URL address.

http://192.168.0.x or http://facial  (the name of Raspberry Pi)

It Works! Well, the Apache Web Server.

Going to http://192.168.0.x/html (sub-folder) for RPi Cam. Choosing the right camera this time and it works!

Next, Setting up Amazon S3 and Amazon Rekognition

 

 

Still updating this document … I will continue finishing my Raspberry Pi setup.

Stay tune!

Image by EM@QUE.com

Support @QUE.COM

Founder, QUE.COM Internet Media. | Founder, Yehey.com a Shout for Joy! | MAJ.COM Management of Assets and Joint Ventures. More at KING.NET Ideas to Life.

Leave a Reply