Hello! My name is Nenad, and I created a Raspberry Pi face recognizer, and I implemented it as an alarm for my computer desk, so that I know if someone sat in front of my computer, and tried to mangle with it.
I started it off from simply creating a face recognizer, and that was fun for a while. Then it clicked to me, someone's always coming to my computer, closing my open windows, shutting it down, stealing my snacks, why wouldn't I use it to alarm me when someone's doing it?
Okay, so firstly I created a simple a face recognizer, it uses the Raspberry Pi very simply, I created my.xfr file hooks, that have the name of the person and image file name in it, the script read those on it's start, and it can recognize all those faces. Then I made it save new faces also, giving them random names for now. I created a NodeJS HTTP Server, to provide a interface that allows you to delete and rename faces.
The faces the script recognized were written in Terminal, and it was fun for a while.
Then, I implemented the platform too, in this project. This was also when I thought of the idea of the alarm. So, I created an account, hooked my python script that was already there, with their connector on the platform, and it wrote the faces it recognizes over there.
And, I needed to create a rule that would tell the platform to send me a notification on my phone when someone sat in front of the computer, or rather, when the face recognizer would see someone, other than no-one, or me.
So now, when someone, other than me, sits in front of my computer, I get this handy notification.
This is the tutorial:
1. Set up the Raspberry PI- Flash the operating system on the SD card
- Connect the camera and enable it in sudoraspi-config
(This part you can actually do from my Git, I went there into more detail.)
Python3 already comes with Raspbian, so we already have that, but we need NodeJS for the web interface.
NodeJS
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
sudo apt install nodejs
Then, the basis of this all, OpenCV, which you don't need to compile!
OpenCV (courtesy of yoursunny.com )
echo 'deb [trusted=yes] http://dl.bintray.com/yoursunny/PiZero stretch-backports main' |\ sudo tee /etc/apt/sources.list.d/bintray-yoursunny-PiZero.list
sudo apt update
sudo apt install python3-opencv
And then, the face-recognition library, made by github.com/ageitgey. I suggest you that you follow his guide on installing the library onto a Raspberry PI, that also requires you to compile dlib.
https://gist.github.com/ageitgey/1ac8dbe8572f3f533df6269dab35df65
WolkConnect library
sudo pip3 install wolk-connect
If it happens so that you do not have pip3, do
sudo apt install python3-pip
After that, you're ready to clone my code
git clone https://gitlab.com/nexylmao/pi-facerecognizer.git
cd pi-facerecognizer/
And we need to install required libraries for the web interface
npm install
And then we can start everything by
npm start &
python3 face-recognizer.py
OptionalI like to put these things into services for SYSTEMCTL, therefore you can create services, that you can easily use by
sudo service $SERVICE_NAME start
sudo service $SERVICE_NAME status
sudo service $SERVICE_NAME stop
sudo service $SERVICE_NAME restart
To create these, we first must decide on two names, for my interface I'm gonna choose 'recognizer-interface', so I'm gonna create a file like this
sudo vim /etc/systemd/system/recognizer-interface.service
And inside, create a service
[Unit]
Description = This is the web interface, for renaming recognizable faces!
[Service]
WorkingDirectory=/home/pi/pi-facerecognizer/
User=pi
ExecStart=/usr/bin/env env node /home/pi/pi-facerecognizer/app.js
[Install]
WantedBy=multi-user.target
We do a similiar thing for the python script, which I'm going to name face-recognizer
sudo vim /etc/systemd/system/face-recognizer.service
And inside
[Unit]
Description=Recognizer Python Script
[Service]
Type=simple
User=pi
ExecStart=/usr/bin/env env python3 /home/pi/pi-facerecognizer/face-recognizer.py
[Install]
WantedBy=multi-user.target
3. Connecting to the PlatformYou can register on
This is a demo version of their platform, we get to use alot of the features, and can create up to 3 devices. We need one, so we're okay
I created an account, logged in and landed on the dashboard.
I will create a device, and before that, the device template. The template can be uploaded, where my manifest.json comes in. Upload that file, and you will have my device template.
Next, I'll create a device with that manifest.
I'll click next step, and give the device a name. When we click save, we will get a prompt with our credentials. I really suggest you download this or send yourself as an email.
Now, I will return to the my python script to replace the credentials that are already there, with the ones I got here.
In these lines of the python script, put in your credentials
device = wolk.Device(
key = "*YOUR DEVICE KEY*",
password = "*YOUR DEVICE PASSWORD*"
)
So, now when I restart my service/script, the camera will start sending the data on to the platform.
We create a widget to see our data...
I chose Semantic groups
And click save!
Success!It even already detects my face!
Now, for the final stepsInstall the application on your phone.
https://play.google.com/store/apps/details?id=com.wolkabout.visualization&hl=en
And login. This will allow for you to see this widget on your phone too, and for push notifications to reach you.
You need to create a rule that will tell the platform to send you a notification, when it sees someone.
I created the rule, and placed these conditions. This says, that, when the recognizer feed is different both from "I dont see anyone!", and my name, It will trigger this event. I put "send a push notification", on my email address as the user, with a title and description of the message.
Clicked save, and I made a rule that looks like this.
And we're done!
Now when my brother sits in front of my computer, I will receive the notification on my phone!
That's it!
Comments