My kids recently played MagiQuest, a game wherein people run around with "magic wands" that shoot out infrared light into sensors that activate different portions of the game. Each wand shoots out a pattern of infrared light that is unique to that wand. I'd like to write a Mathematica function that can distinguish one wand from another.

My laptop's webcamera can detect the light from the wand. Using img=Dynamic[CurrentImage[]]; I can analyze a stream of "video" from the webcam (where to process img, one has to use img[[1]] as the head of img is Dynamic.)

My question is very open-ended: how do I go about building a function that detects the pattern given by a wand? So far, all I have done is create a simple function that can detect when a light is shining on the camera in a dark room (i.e., it simply knows when the wand is shining at the camera). What is missing is a way to properly analyze the stream and detect patterns, no small job.

A significant problem: my webcam detects the infrared light as white light, so any white light can throw off the camera's detection. Bonus points for showing how to hack the camera to only recognize infrared light and disregard all other light sources.

  • $\begingroup$ I would be worried about the framerate (and framerate stability) of Dynamic@CurrentImage[] ... How quickly are these wands flashing? If you record video separately, it would guarantee a stable framerate somewhere between 15-30 fps depending on your webcam and recording mode. Then you can analyse the pre-recorded video with Mathematica. $\endgroup$
    – Szabolcs
    Mar 20, 2015 at 18:44
  • $\begingroup$ @Szabolcs, the wand's IR emission is modulated at 37 kHz according to a post here $\endgroup$ Mar 20, 2015 at 18:51
  • $\begingroup$ @SimonWoods I guess that settles it. It can't be done with a webcam. You could post that as an answer. $\endgroup$
    – Szabolcs
    Mar 20, 2015 at 18:56
  • $\begingroup$ I was worried about the stability of the framerate as well, which was one of the reasons I thought I'd ask. The answer of "you can't" isn't what I was looking for, but now I know to not waste more time trying to make it work. $\endgroup$
    – GregH
    Mar 20, 2015 at 19:44

1 Answer 1


This link talks about hacking a MagiQuest receiver with an Arduino. It mentions that the modulation rate of the IR signal is somewhere in the region of 37 kHz, a factor of more than 1000 times faster than anything your webcam can detect.

So you simply will not be able to do this with a webcam.

Even if the modulation rate were much lower you would still struggle to get it working. As Szabolcs commented, there is no guarantee that the frame rate obtained with CurrentImage is stable, which would make demodulation tricky.

Finally, the way to "hack" a camera to see only IR light and not visible is with a filter.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.