https://github.com/gloworm72/interactive-wand-gesture-recognition
Raspberry Pi wand system using OpenCV & machine learning to cast spells via real-time motion tracking, servo control, LEDs, and sound.
https://github.com/gloworm72/interactive-wand-gesture-recognition
computer-vision gesture-recognition gesture-tracking harry-potter harrypotter machine-learning maker-project opencv raspberry-pi raspberry-pi-5 raspberrypi themepark
Last synced: 2 months ago
JSON representation
Raspberry Pi wand system using OpenCV & machine learning to cast spells via real-time motion tracking, servo control, LEDs, and sound.
- Host: GitHub
- URL: https://github.com/gloworm72/interactive-wand-gesture-recognition
- Owner: Gloworm72
- Created: 2025-05-16T02:36:07.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-31T19:25:11.000Z (about 1 year ago)
- Last Synced: 2025-06-20T02:05:10.309Z (about 1 year ago)
- Topics: computer-vision, gesture-recognition, gesture-tracking, harry-potter, harrypotter, machine-learning, maker-project, opencv, raspberry-pi, raspberry-pi-5, raspberrypi, themepark
- Language: Python
- Homepage:
- Size: 15 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Interactive Wand
A personal passion project recreating the magic of spellcasting through computer vision, machine learning, and themed show control — all powered by a Raspberry Pi 5 and written entirely in Python.
**Webpage Link:** https://andrewcongdon14.wixsite.com/andrew-congdon/interactive-wand
---
## Project Summary
This wand system detects spellcasting gestures in real-time using OpenCV and an infrared-lit wand. It recognizes and responds to two specific spells:
- **"Alohamora"** — opens the magical box with warm purple fire
- **"Colloportus"** — closes it with a cool burst of blue flame
The system features:
- Real-time IR blob tracking and wand path tracing
- Spell recognition using a trained SVM classifier
- Servo-based box movement
- Custom LED animations tied to spell type
- Themed sound effects with seamless background music
- Filtering to prevent false or accidental spell detection
All code runs on-device using multithreaded Python and a Pi Camera.
---
## Technologies Used
- `OpenCV` for video input and motion tracking
- `scikit-learn` SVM with `GridSearchCV` for spell classification
- `Pi5Neo` to control RGB LED strip over SPI
- `pygame` for real-time sound effects and music
- `pigpio` and `gpiozero` for hardware PWM and servo control
- Custom wand trace dataset of 400+ samples, labeled and trained manually
- Threading to keep vision, servo, LED, and audio systems responsive
---
## Spellcasting Flow

---
## File Overview
**HarryPotterWandcv.py**
↳ Main runtime script: blob detection, trace drawing, spell prediction, and show control.
**HarryPotterWandsklearn.py**
↳ Used to run the pre-trained SVM classifier concurrently.
**new_custom_classifier.pkl**
↳ Pre-trained model for classifying spells based on trace shape.
**lastframe.jpg**
↳ Latest wand trace visualization, saved for debugging or training.
**Sounds/**
↳ Sound effects and background music used in spellcasting.
**DatasetCreation/**
↳ Python for drawing custom training data, converting that training data into the correct format, training the SVM classifier to produce the .pkl file
---
## ML & Classification
I created a custom dataset by collecting over 400 wand path traces drawn in-air. These were:
- Centered and normalized
- Smoothed and resampled
- Converted to vector features
I used `GridSearchCV` to tune a Support Vector Machine (SVM) classifier that could distinguish between gestures with over 99% accuracy.
The classifier runs on-device in real time with minimal latency.
---
## Show Control Highlights
- **Servo Logic** – Smooth actuation of box lid using hardware PWM and `pigpio`
- **LED FX** – Custom “fire” animations with randomized color flickers using `Pi5Neo`
- **Audio Layers** – Spell SFX mixed over looping background music via `pygame`
- **Gesture Filtering** – Start and stop conditions prevent noisy traces from triggering spells
---
## 🎥 Demo Video
[](https://www.youtube.com/watch?v=IFpQFHPK7W4)
*Click the image to watch the full demo.*
---
## Final Thoughts
This was one of the most technically rewarding projects I've created — combining embedded hardware, computer vision, machine learning, and interactive storytelling. It’s a small glimpse into how software and show control can bring magic to life.