Magic Wand with Computer Vision

By Nicola King. Posted

What wizarding fan wouldn’t want a wand that actually, really, properly makes something move? Nicola King explores a simply magical idea

Jasmeet Singh is an electronics student from New Delhi who enjoys expanding his knowledge with hands-on projects. He also has a keen interest in the field of AI, and wants to bring the cool tech of movies to real life.

Following a trip to Universal Studios in Japan by his brother, who was able to perform some ‘magical’ tricks with a retroreflector-tipped wand while he was there, maker Jasmeet Singh was inspired to explore what he could do with a replica wand.

“I have been highly inspired by tech portrayed in sci-fi movies – be it some cool gadget owned by a superhero, or wands that can cast incredible charms,” he reveals. “That was the time I was exploring the field of computer vision and machine learning. Hence, I saw this as just the right opportunity to use the wand and create my own version of the ‘wizarding experience’ using computer vision and some basic electronics.”

Jasmeet used this original Universal Studios wand, but you can make your own

A wave of the wand

Jasmeet’s project involves creating a motion capture system which enables him to open a box with a flick of his wand. To achieve this, he used a night-vision camera (Raspberry Pi NoIR Camera Module), a Raspberry Pi, some electronics, a Python program using OpenCV, and machine learning. 

So, how does it work exactly? Jasmeet elaborates, “My main goal for this project was to give its user a real wizarding experience with a wand, and that could only be achieved by attaching as little electronics as possible on the wand. The wands used at Universal Studios achieve this by using a retroreflector attached at the tip of the wand.”

Jasmeet continues, “When the retroreflector at the tip of the wand is illuminated using an infrared light source, it can be seen as a bright circular blob in the real-time video from the [Raspberry Pi NoIR Camera Module]. Then, using a Python script running on Raspberry Pi with some basic functions of the OpenCV computer vision module, the path taken by the wand is traced after the tip of the wand’s blob has entered a starting point in the frame. The person now has to draw the letter, which ends at the ending point, and then the last frame with the drawn letter is passed on to a trained machine-learning model which predicts the letter drawn. Depending on the prediction, Raspberry Pi commands a servo to open/close a box.”

Stellar speller

Wizarding aficionados will be aware that ‘Alohomora’ is a spell that allows the opening of locks. So, appropriately, if someone draws a letter ‘A’, Raspberry Pi commands the servo to open the box. By the same token, if someone draws a letter ‘C’ (for close), the box will close. 

Jasmeet printed out images to stick on an old box – use your creativity and make your own

Jasmeet used a dataset from Kaggle to train the machine-learning algorithm and, as it contained a large number of images for each letter, the accuracy of predictions is an impressive 99%. In addition, he says, “Since the setup of the project uses a night-vision camera for detecting the wand in real time, it can work without any errors in a darkened room, as well as with an additional source of visible light.”

Unsurprisingly, the feedback Jasmeet has received from friends and family has been very positive, as has the response from the Instructables and Hackster platforms where his written tutorial is available. All in all, it’s a very fun and inspiring project, especially when you consider that Jasmeet was completely new to the fields of computer vision and machine learning when he started his wand-waving idea. Proof that having a go at something new can really pay dividends – “Project-based learning is the best and most efficient way to get yourself acquainted with new technologies,” he tells us. 

The project’s Raspberry Pi NoIR Camera Module is surrounded by a ring of infrared LEDs

Quick facts 

  • The project took Jasmeet around two months to complete

  • It was his first using Raspberry Pi

  • You can use any stick with retroreflector tape or paint on the end

    Jasmeet plans to add a wizard duelling capability…

  • …with a second wand and night-vision headsets!

From The MagPi store

Subscribe

Subscribe to the newsletter

Get every issue delivered directly to your inbox and keep up to date with the latest news, offers, events, and more.