The causes are too long to explain here, but some time ago I made the schematics for an intrusion repellent device with facial recognition.
How complicated is it to build such a device? Will it be possible to recognize a face with just one picture? Sometimes, reality throws challenges so bizarre that they sound straight out of a movie script. In my case, it involved some surreal Argentine laws and a fugitive car watcher—too complicated to unpack here. Long story short, I found myself sketching up a solution: a simple device to deter intrusions using facial recognition.
The situation eventually found resolution through institutional channels, but the idea stuck with me. Could such a device actually be built without much hassle? As makers, curiosity often takes the wheel. So, I decided to explore the feasibility of this concept. Spoiler: It’s entirely doable with simple tools and a little coding.
SchematicsThe device needed to recognize a specific person using just one picture as a reference, which ruled out the use of traditional machine learning training methods. If the device detects a person who isn’t the target, it should send a Telegram notification with an attached picture.
However, if the device recognizes the target, it should take a picture, deploy a customizable liquid to a range of 3 to 4 meters, and then take a second picture. Both pictures are included in a notification sent via Telegram.
Parts used- Raspberry Pi 5 with Active Cooler
- Rpi Cam v2
- 1 Channel Relay
- DC 12V Water Pump
- 12V Power Supply
- DC Female
- Jerrycan
The circuit is simple and straightforward.
The cam is connected to the Raspberry using the ribbon.
The relay is connected to Pin 18, VCC and GND.
The Pump power + line is interrupted by the el relay using NO – normally open – and CONTROL.
The Raspberry Pi 5 board is connected to a 5V 3Ampers Power Supply using a USBC cable.
While there are various ways to perform facial recognition, most require training a machine learning model. In this case, however, there was only a single photograph of the target, so a method capable of making inferences using just that one image was necessary.
After some testing, I came across the face-recognition library by by Adam Geitgey, built on the Dlib toolkit. Its implementation is remarkably straightforward, provided the dependencies are installed correctly.
sudo apt install -y python3-picamera2
sudo pip3 install numpy
sudo apt-get install python3-cmake
sudo pip install face-recognition
Initially, I used a Raspberry Pi 2 since I had one lying around in a drawer, but the delays in performing inferences led me to eventually switch to a Raspberry Pi 5
unknown_encoding = face_recognition.face_encodings(unknown_image)[0]
results = face_recognition.compare_faces([target_encoding], unknown_encoding)
Liquid throwerMy first choice for the sprayer was a Craftsman repellent sprayer, but during testing, I forgot to activate a valve, which ended up breaking the mechanism. I then repurposed a 12V water pump I had previously used for a mate dispenser project and adapted the tip of the Craftsman sprayer to achieve greater range. I connected the pump's power supply to a relay and wired the relay to the Raspberry Pi.
print("Target located...")
print("Firing...")
relayLine.set_value(1)
time.sleep(sprayTime)
relayLine.set_value(0)
picam2.capture_file("/home/YOURFOLDER/dataset/take2.jpg")
I made an admin Tkinter based utility to load the target picture and configure some of the settings. Picture is just copied to a folder and settings updated in a txt file.
# Settings
relayPin = 18 # relay pin
api_id = "" # Telegram
api_hash = '' # Telegram
telegramUser = '' # notification user
sendTelegram =1 # enable or disable
sprayTime=3 # liquid time
LogSince the machine operates autonomously, the script saves all actions in a log for further analysis
def writeLog(myLine):
now = datetime.datetime.now()
dtFormatted = now.strftime("%Y-%m-%d %H:%M:%S")
with open('log.txt', 'a') as f:
myLine=str(dtFormatted)+","+myLine
f.write(myLine+"\n")
Telegram notificationsThe library used for Telegram integration is Telethon.
pip install Telethon
Next, the API ID, API Hash, and user credentials are configured in the script settings.
If the device detects a person who is not the target, a single picture is sent. For a target detection, two pictures are taken—one before and one after the action—and both are sent.
Pictures are actually pinkish, which is a not so rare issue. I solved that in other projects with a tuning file.
rpicam-jpeg --output test.jpg --tuning-file /usr/share/libcamera/ipa/rpi/pisp/imx219_noir.json
But in this case I do use Picamera2() and I wasn't able to fix the colors yet.
picam2 = Picamera2()
Bledsoe Liquid TherapyThe name is a homage to Woodrow Bledsoe, who, in the mid-1960s, conducted research on enabling computers to recognize faces. It's a reminder that, from a certain perspective, AI isn’t so much a revolution as it is the result of a slow and steady process of progress.
Bledsoe Liquid Therapy and some context
Also on YT Shorts
Maker Counterculture
Comments
Please log in or sign up to comment.