Raspberry Pi Face Detection Used to Turn on the Lights

Redditor Zippyzapdap used a neural network to automatically switch on the lights when he sits down at his desk.

Face detection is one of the most useful computer vision tasks, as it can be utilized for many different applications. If, for instance, you want to count how many people enter a building, a face is one of the easiest things to recognize. People wear all kinds of clothes that can dramatically alter the shape of their body, but our faces tend to always look like faces. Because it’s such a popular task, there are many computer vision systems that can handle it. Redditor Zippyzapdap used one of those to automatically turn on some lights when he sits down at his desk.

In this specific case, an MTCNN (Multitask Convolutional Neural Network) face detector for Keras and TensorFlow in Python 3.4. That may run on a Raspberry Pi, as they are capable of handling many TensorFlow models, but Zippyzapdap instead decided to run the neural network on an Apple MacBook. A Raspberry Pi sits on the desk, and a Raspberry Pi camera module points at the desk chair. A Flask server runs on the Raspberry Pi and continuously captures images, which are then sent to the MacBook for processing.

If the neural network running on the MacBook detects a face in one of the images, then a POST request is sent back to the Flask endpoint on the Raspberry Pi. The Raspberry Pi then sends out a signal to turn on the strip of Adafruit NeoPixel LEDs. Conversely, if a face isn’t detected for ten successive frames, those LEDs are turned off. This will turn the lights on and off when any face is detected — it doesn’t actually recognize or identify an individual’s face. You could also argue that simply sticking a switch in the desk chair would be a far more practical and efficient solution. But this is really just a demonstration of how you can use neural networks in the real world.

Related articles
Sponsored articles
Related articles