TV remote with gestures
School project to control a computer or a TV with hand gestures

The purpose
This was a school project with my team (Nino Pireaud, Julien Minvielle, Hugo Bénard and Étienne Duclos): control a computer, or a TV, just by waving your hand at a webcam. No remote, no keyboard. Scroll a page, pause a video, press OK, turn the TV off.
Code is here: github.com/Epwo/GestureControl
The gestures
| Gesture | What it looks like | Action |
|---|---|---|
| 🤘 Horns | index and pinky up, the rest folded | Play / Pause |
| ✋ Vertical swipe | open hand moving up or down | Scroll up / down |
| ✌️ V sign | index and middle finger up | OK / Enter |
| ✊ Closed fist | all fingers closed, thumb tucked in | Close the app (Alt+F4), or TV on/off |
How it works
Seeing the hand: MediaPipe
MediaPipe Hands does the heavy lifting: for every frame from the webcam it gives 21 landmarks per hand (each fingertip, each joint, the wrist), in 3D, plus whether it’s a left or a right hand. We only track the right hand, so the left one can do whatever it wants.
There’s no model training in this project. Every gesture is just geometry on those 21 points.
Recognizing a gesture: rules on landmarks
The base of it all is counting folded fingers: a finger is folded if its tip is lower in the image than its base joint. Then each gesture is a small detector in its own file (src/gestures/):
- Swipe: the index, middle and ring fingertips all moved more than a threshold vertically compared to 3 frames ago. The sign of the movement gives the direction.
- Horns: index and pinky far from the wrist, middle and ring finger close to it, thumb tucked.
- V sign: index and middle extended, exactly two fingers folded.
- Fist: 4 fingers folded and the thumb hidden “inside” the hand.
Adding a gesture means adding one file and calling it from logic.py. That made it easy to split the work between 5 people, each on their own branch.
The distance problem
Thresholds in pixels (or in normalized image coordinates) only work at one distance from the camera: step back, your hand looks smaller and nothing triggers anymore. We fixed it with a hand ratio, computed from the distance between the wrist and the base of the index finger. All the thresholds are multiplied by it, so they scale with the apparent size of the hand.
It’s not perfect: the values were first calibrated on Nino’s laptop webcam, and a different camera can need some tuning.
Not triggering 50 times per second
The camera gives dozens of frames per second, and a gesture lasts a lot longer than one frame. Without care, one “swipe” scrolls ten times. Two things handle this:
- The wrist must be still. If the base of the hand moves too much between frames, you’re just moving your hand around, not making a gesture, so nothing is detected.
- An idle state. After a gesture fires, a “recent action” flag blocks the next ones. You need to go back to a neutral pose (all fingers open, or all closed) for ~0.4 s before the next gesture can trigger. It feels like “lifting your finger” between two taps.
Controlling a real TV: an ESP32 as an IR blaster
Controlling the computer is easy: PyAutoGUI simulates the scroll, the key presses and Alt+F4. For the TV, we needed to send infrared like a real remote.
So we built a small IR blaster with an ESP32 and an IR LED:
- First, a small sketch with an IR receiver to log the hex codes of the original TV remote (power, up, down, volume, play/pause, OK). They live in
codes.json. - Then the ESP32 connects to the Wi-Fi and exposes a tiny HTTP API:
POST /sendwith{"code": "0x..."}, and it fires that code with the NEC protocol. - On the computer side, every detected gesture is mapped to its code and sent to the ESP32.
webcam
▼ MediaPipe (21 landmarks)
▼ gesture rules
├─► PyAutoGUI ─► 💻
└─► HTTP ─► ESP32 ─► IR LED ─► 📺
The firmware is built with PlatformIO (arduino/GestureControl/).
What I’d do differently
- Learn the gestures instead of hand-writing rules. The rules work, but every new gesture means new thresholds to tune. A small classifier on the 21 landmarks (even a few dense layers) trained on a few hundred examples per gesture would be more robust, and it would work with both hands.
- A confirmation for destructive gestures. Closing the app with a fist is a bit too easy to do by accident. The plan was a “loading circle” you hold for a second before it actually closes.
- Calibrate per camera at startup instead of hard-coding the values.
What I learned
- MediaPipe is incredibly good and fast, even on a laptop CPU. The hard part is everything after the landmarks.
- Debouncing and state (idle / recent action) matter as much as the detection itself. A gesture that triggers once, reliably, is what makes it usable.
- Working at five on one codebase means you need a clean way to plug in new pieces. “One gesture = one file” saved us a lot of merge conflicts.