Interactive Computer Interface Using Webcam project demo #2How to Make A Pocket Penlight-based Mouse Controller for Your Notebook or PC by lohchinfei, 19Feb2007

In this project we will show you how to use the webcam and an infrared light spot – either from a pocket touchlight or “penlight” or from a infrared (IR) LED – to control the mouse cursor control on your PC or notebook computer.
Combined with a external wired or wireless mouse, you can then move the mouse around on the screen and use it to control other applications, play games, etc, simply by waving the penlight around like a wand.
BackgroundThe basic idea is really simple: a program running on the PC will process the images viewed from the webcam, find the position of the penlight/light spot, and use this position to deternine where to place the mouse cursor on the screen.

Now, if we can assume that the light spot/point is always the brightest object in the area, than the detection algorithm will be very simple: find the location of the pixel with the highest intensity level.
We make use of two additional useful facts:
- a normal pocket touchlights (or any incandescent lamp for that matter) actually emits several times more infrared light than visible light, and so works better as IR point source than a visible light source.
- most webcam are able not only to detect visible lights (red, green and blue, etc) but they can also detect infrared (IR) lights – for example as emitted by the IR LEDs commonly found on TV/Hifi remote controls – which are invisible to the human eyes.
So if we can somehow use the webcam to capture only the infrared lights from our light source and reject the surrounding visible lights, we will be ensured of a very reliable system. An additional feature of this system will be it will work if we replace the torchlight with any IR LEDs.
One way to do so is by converting the webcam into an infrared webcam – you can do a Google search on the internet for websites on how to convert normal webcams into IR webcams. The methods normally involved taking apart the camera, removing a small piece of filter in the lens assembly and replacing it with a piece of photography film negative. The film negative is actually an excellent infrared filter which blocks out all visible light while allowing only infrared light to pass through.
However, it may not be possible to dismantle and modify your webcam (in the case of built-in webcams for some notebook computer), and fortunately, it is also unnecessary to do so as we have discovered. By simply placing the piece of film negative in front of the webcam, we found that in most cases it is sufficient to do the trick for our purpose.
Instruction:
To keep the long story short, here’s a simple video to show how to make your own Wii-like controller.
What we used in our demo :
- Light source – a mini touchlight Eveready Energizer Pocket Penlight, S$4/US$2.50.
- A piece of film negative – to act as an infrared filter. Free.
- Notebook: Apple Macbook Pro running WinXP+Bootcamp
- Webcam - the iSight built-in webcam on my Macbook Pro.
What’s not shown in the video: clicking of the mouse buttons is done using external mouse devices: in the demo we used a wireless presenter device most of the time.
The control code is available for download at my MeL website, see detail below.
Converting the system into a Light Gun ControllerWe tried converting the system into a light gun for playing shooting games like Virtual Cops 2 and House of the Dead 3.
The simple solution we used is to modding existing toy guns with IR LEDs. We have two variations:
1. a simple S$2.60 candy toy gun with Red LED lights and sound. We simply replace the LED with an IR LED and disabled the irritating sound.
2. a more complex S$6.00 toy gun with multiple trigger and switches. We were able to insert the circuits from a small wired mouse into the gun, and wired the mouse buttons to the trigger and reload lever on the gun to control the firing and reload actions of these games. See picture below.
The guns modification was done by our design project student Mohd Sufi.
The result were surprisingly good, initially anyway.
Note that the system at its present form is not really a precision pointing device, i.e. you can move the penlight to move the mouse around the screen, but you can’t actually point the penlight towards any part of the screen.
Therefore, to use the device as a precision pointing device we are required to perform a calibration process before running the control program.
The precision achieved is surprisingly good. The calibration process takes into account all characteristic of the user holding the gun: his height, his arm length, where he stands, how he hold and aim the gun, etc.
However the accuracy will drift the moment the person moves away from where he is standing during the calibration process. In other word, the accuracy is only as good as long as the person holding the gun remains in his "calibration position". So for all practical purpose, the calibration works but is effective only “temporarily”.
So the system works, it’s fun even if the fun is only temporary, but is really not a very good solution.
Coming Up Next ...I will elaborate about the calibration process in my next bog. In the meantime, the softwares (both the calibration and the control program) are now available on my MeL website at:
https://mel.np.edu.sg/webapps/cmsmain/webui/_xy-629307_1
for downloading.
More next time ...