AI on the Edge LESSON 52: Gesture Recognition on the Raspberry Pi 5

Welcome back, everyone! In today’s lesson, AI on the Edge LESSON 52: Gesture Recognition on the Raspberry Pi 5, we are building a custom, real-time hand gesture recognition system from scratch. Up until now, we have been using MediaPipe to track keypoints, identify individual hand joints, and extract raw 3D coordinate data. But raw coordinates alone don’t tell the computer what your hand is actually doing. Today, we bridge that gap by teaching our Raspberry Pi 5 how to train on custom hand positions and dynamically classify live hand gestures using pure mathematics and vector geometry—no heavy neural network retraining required.

The core secret to making gesture recognition work reliably across different camera distances is scale-invariant distance normalization. If you simply measure the pixel distance between your fingertips and your wrist, bringing your hand closer to the camera lens will blow out those numbers and break your classifier. To solve this, our script establishes a baseline unit of measurement for every single frame: the distance between the wrist (landmark 0) and the index finger base joint (landmark 5). By dividing all measured finger-tip-to-wrist and tip-to-tip distances by this dynamic scale factor, the resulting feature vector remains identical whether your hand is two feet away or five feet away from the lens.

Once we extract this normalized 15-element feature vector—representing the spatial ratios between all five fingertips relative to the wrist and each other—we construct an interactive training phase directly inside the live video loop. The program prompts you in the terminal for the number of custom gestures you wish to record, along with their labels (such as “Peace”, “Thumbs Up”, or “Fist”). As you present each gesture to your camera feed and press the spacebar, the algorithm captures the instantaneous geometric signature of your hand and stores it in a runtime training dictionary.

During live inference, our classifier calculates the Sum of Absolute Errors (SAE), or Manhattan distance, between the live incoming feature vector and every stored profile in our training dataset. The function loops through all saved gestures to find the candidate with the absolute lowest cumulative error score. To prevent false positives when an untrained or messy hand pose is shown, we compare that lowest error score against a strict threshold value (maxErrorThreshold = 3.5). If the error falls within the allowable boundary, the matched gesture label is instantly displayed on the live OpenCV HUD; otherwise, the system safely defaults to “Unknown”.

We manage our camera feed using high-speed frame capture with Picamera2 running at 60 frames per second at 1280×720 resolution, processing hand detection with MediaPipe Hands, and rendering real-time performance diagnostics—including an exponential moving average FPS counter—directly onto the video output. Go ahead, study the methodology, load the concept onto your Raspberry Pi 5, grab a hot cup of coffee, and let’s get building!

 

AI on the Edge LESSON 51: Gesture Control of NeoPixel Ring

 

Welcome back, everyone! In today’s class, AI on the Edge LESSON 51: Gesture Control of NeoPixel Ring, we are bridging the gap between computer vision and physical hardware in a big way. Up until now, we have spent a lot of time tracking hands, plotting 3D landmarks, and rendering graphical user interfaces directly onto our camera feeds. But today, we take those virtual interactions and project them out into the real physical world using a 12-LED NeoPixel ring driven over SPI by our Raspberry Pi 5.

The core concept of this lesson is creating an intuitive, spatial gesture interface. Imagine looking at your monitor display where a graphical representation of a circular LED ring is overlaid onto your live camera feed. By extending your hand and placing your index finger tip over any of the twelve virtual LED nodes on screen, the system detects your hover position. When you pinch your thumb and index finger together, the program registers a toggle event, turning the corresponding physical LED on or off on the actual hardware ring sitting on your workbench.

To make this work reliably without wild bouncing or rapid flickering, we dive deep into the mechanics of gesture latching and debouncing. When a student first attempts spatial tracking, holding a pinch gesture over a target often causes the state to flip back and forth dozens of times per second. In this lesson, we implement a stateful boolean latch flag that locks down the trigger state the moment a pinch is registered. The algorithm strictly requires you to release the pinch—breaking contact between your thumb and index finger—before it will accept another command. This simple state machine logic is essential for turning noisy computer vision inputs into rock-solid physical control interfaces.

Beyond individual pixel control, we also construct a dynamic UI Mode Selection Panel on the right side of the screen. By hovering over the panel buttons and executing the same pinch gesture, you can cycle through five distinct lighting animation profiles in real time:

  • Static Mode: Displays fixed, custom-assigned palette colors for each active LED node.
  • Rainbow Mode: Distributes a static 360-degree color wheel spectrum across all twelve positions using HSV-to-RGB conversion algorithms.
  • Pulsate Mode: Modulates the physical brightness using a squared sine wave math function to guarantee a true black-floor fade on turned-on pixels.
  • Blink Mode: Synchronizes an on/off strobe animation derived from live system timestamps.
  • Running Rainbow Mode: Dynamically rotates the active hue spectrum around the ring by stepping the color offset frame-by-frame.

We handle all of this frame rate processing seamlessly using high-speed SPI bus communications through neopixel_spi and direct frame acquisition via Picamera2. By keeping auto-write disabled until all mathematical animation steps and hand-tracking calculations are completed for a given frame, we push smooth, flicker-free updates out to both the physical hardware and the OpenCV display overlay simultaneously.

Work through the complete Python script provided on this page, load it onto your Pi, and assemble your hardware circuit. Pay close attention to how the spatial math maps coordinates from normalized MediaPipe landmark spaces directly into circular screen coordinates using polar angle formulas. Grab your components, fire up your IDE, and let’s get building!

 

 

AI on the Edge LESSON 50: Control NeoPixel Ring With Hand Gestures and MediaPipe

Hey everybody, welcome back to AI on the Edge! In Lesson 50 we’re taking things to the next level — we’re combining real-time hand tracking with a physical NeoPixel ring so you can change colors just by pointing at the screen! Using MediaPipe on the Raspberry Pi, we track your index finger tip and turn the big camera view into an interactive color picker. Hover over any of the seven big colored circles (Red, Green, Blue, Cyan, Magenta, Yellow, or Black) and — boom — the NeoPixel ring instantly lights up with that color!
This lesson is super fun because it finally brings together everything we’ve been building: smooth hand detection, coordinate mapping between camera and OLED, visual feedback, and real-world hardware control. You’ll see your finger tracked with a big blue dot, watch the selected color update live on both the screen and the OLED, and control actual RGB lights with nothing but a gesture.
By the end of this lesson you’ll have a working gesture-controlled color mixer that feels like real interactive magic. This is the kind of project that makes people say “Wow, you built that on a Raspberry Pi?!”
This is also a perfect foundation for even cooler future projects — gesture-controlled lighting, touchless interfaces, interactive games, or even a full gesture-controlled robot or light show.
So grab your Raspberry Pi, hook up that NeoPixel ring, fire up the camera, and let’s start waving our hands around like we’re casting spells! As always, the complete code is right below the video. Watch along, run the code, then start tweaking it — maybe add more colors, make the ring react differently to gestures, or combine it with the hand connection drawing from earlier lessons.I’m really excited to see what you create with this one!Now go make something awesome! 

This is the core circuit we use for the class:

Fusion Hat Circuit Diagram
This is the circuit we will use moving forward in the class

This is the schematic to add the OLED:

OLED
SSD1306 OLED Connected to the Fusion AI Hat

Then this is the schematic to add the NeoPixel

NeoPixel
NeoPixel Schematic

AI on the Edge LESSON 49: Live Animated Avatars on the SSD1306 OLED With OpenCV

Hey everybody! Welcome back to the AI on the Edge series!

In Lesson 49, we’re doing something that’s just plain cool — we’re turning that tiny little SSD1306 OLED into a live animated avatar that follows your face and hands in real time!

That’s right — no more static images, and no more being tethered to your desktop and monitor. This time your OLED is alive! Move your head, smile, raise your eyebrows, wave your hands… and the little display instantly mirrors your movements like a miniature digital twin. It’s like having a tiny version of yourself living on that 128×64 screen!

What You’ll Learn in This Lesson:

  • How to use MediaPipe Face Mesh to track 468 facial landmarks
  • How to combine it with Hand Tracking at the same time
  • The trick to projecting those landmarks onto a tiny OLED in real time
  • How to draw both points and connecting lines to create smooth, animated avatars
  • How to keep everything running fast on the Raspberry Pi

This is one of those projects that makes people stop and say “Wait… how is that even possible on that little screen?!”

By the end of this lesson, you’ll have a foundation for building all kinds of fun real-time avatar projects — everything from simple face mirrors to gesture-controlled characters and beyond.

Why This Is Awesome:

We’re not just displaying video on the big screen anymore — we’re compressing all that AI power down onto a cheap little OLED. This is real AI on the Edge stuff, and it looks incredibly impressive for how simple the hardware is.

Whether you want to build interactive displays, robot faces, wearable tech, or just blow your friends’ minds, this lesson gives you the core technique to make it happen.


Ready to make your OLED come alive?

Fire up the code, run it, and watch your tiny digital self start moving with you. Then start experimenting! Try drawing just the eyes and mouth, or just the hands, or maybe even turn it into a little stick figure avatar.

As always, I want to see what you create with this! Drop your versions in the comments or tag me — I love seeing the creative stuff you guys come up with. Don’t just copy and paste my code. Show you really understand the video by making the code yout own.

Enough talk, lets get this party started!

 

AI on the Edge LESSON 48: Hand Detection in OpenCV and MediaPipe on the Raspberry Pi

In Lesson 48 we’re taking a huge step forward — we’re bringing real-time hand detection to the Raspberry Pi using the incredible power of MediaPipe combined with OpenCV and the Pi Camera. This is one of those projects that feels like pure magic when you see it working: the camera picks up your hands instantly, tracks all 21 landmarks on each hand, draws beautiful connections in real time, and does it all right on the edge with no cloud required.
You’ll learn how to set up MediaPipe’s Hands solution for reliable multi-hand tracking, how to efficiently process frames from the Picamera2 library, flip and convert images for proper display, and draw professional-looking landmarks and connections with custom styling. We also keep a smooth FPS counter running so you can see exactly how well your Pi is performing.
This lesson is exciting because hand tracking is the foundation for so many advanced gesture-control projects — think touchless interfaces, sign language recognition, robotic control, virtual instruments, and interactive art installations. Once you have solid hand detection running smoothly on your Raspberry Pi, the creative possibilities are almost endless.
So grab your Raspberry Pi, fire up the camera, and let’s get those hands dancing on the screen! As always, the full code is waiting for you below. Watch the video, follow along, and then start experimenting — I can’t wait to see what you build with this!
Let’s make something awesome!

 

Making The World a Better Place One High Tech Project at a Time. Enjoy!