What is it?
Laserspotcam is a software I wrote to control
xmms
using a laser pointer by pointing defined areas on a wall.
The software monitors the wall for the presence of a small spot using a webcam. When
the spot appears somewhere, if it is inside a defined hotspot, the appropriate
command is executed.
Images
Pictures from me:
On 4 paper sheets, I used a fluorescent pencil to draw the standard symbols
for Previous, Stop, Play and Next.
Since version 0.2, there is also an invisible volume bar right below the buttons.
|
With a blacklight, the sheets are easy to see.
|
Here I'm using the Play button. A few moments later, the music started playing.
|
Here is what laserspotcam's window looks like. The red rectangles shows the defined
hotspots. In this case, the pointer is inside the Play hotspot.
|
In this picture, the pointer is outside the hotspots.
|
|
Pictures from Brian Dahlem:
Brian printed a remote control for his MythTV on a
61x61cm square sheet of paper.
|
Here's the hotspots seen from the webcam. He uses quite a few more hotspots than I did.
|
If you would like to show me your laserspotcam setup, please
contact me. If it's really cool,
I might post the pictures here with your permission of course ;)
Source code
Laserspotcam is designed to run on Linux. It uses the video4linux API for
for video capture and sdl for the display. It is released under the
terms of the GPL license.
File | Date | Comments |
laserspotcam-0.3.tar.gz |
September 25, 2005 |
Patch received from Brian Dahlem:
- Added new type of hotspot (bottom to top) for volume bars.
- Added support for repeatable hotspots. Config file format has
changed to accomodate this new flag.
- The value was not appended to the command run by "left to right"
hotspots. (But the right command was printed in verbose mode... Oops)
|
laserspotcam-0.2.tar.gz |
September 20, 2005 |
- Added new type of hotspot (left to right) for volume bars.
- Added -t switch for test mode (commands not executed)
- Hotspots now turn green when triggered in visual mode.
|
laserspotcam-0.1.tar.gz |
September 18, 2005 |
Initial release. |
Supported cameras
Here is a list of webcams and/or video capture peripherals that
have been tested with laserspotcam:
Model | Interface | Driver | Info |
Philips PWC 740 |
USB |
pwc |
Works perfectly. I suggest that you adjust
the AGC (Manual) with SDLcam
or
camstream to prevent saturation in high light conditions. |
logitech QuickCam Express |
USB |
Spca5xx |
Works perfectly. |
Logitech QuickCam Notebook Pro |
USB |
pwc |
Works perfectly. |
Please
contact me if you have tested laserspotcam with a webcam not in this list. If
your webcam does not work, I'll try to fix laserspotcam to make it work.
Installation and configuration<
1: Compilation
You will need to have the
sdl library installed.
To compile laserspotcam, simply type:
# make
2: Start laserspotcam
In the directory where you compiled laserspotcam, type:
# ./laserspotcam
laserspotcam uses /dev/video0 by default. If you want
to use another video device, use the -d option, like this:
# ./laserspotcam -d /dev/video1
Laserspotcam will open a window where you should see
the video received from the camera.
3: Determining hotspots coordinates
You may have drawn buttons on the wall, of have sticked coloured
sheets of paper, or you name it. Align your webcam on the wall or
surface you want to use.
Write down the coordinates of all your rectangle hotspots by clicking
each hotspot's upper left corner followed by the same hotspot's lower right
corner iwth the mouse in laserspotcam's window. Each time you click somewhere
in the window, the coordinates are outputted to the console.
4: Create a config file
The config file format is simple. Each hotspot is defined on one line. Each
line contains 6 comma separated values. The first value defines the type
of hotspot. Valid types are:
0: Normal hotspot. Command executed when hotspot is activated.
1: Left to right hotspot. The pointer's position is converted
to the 0 - 100 range. Left is 0, right is 100. Useful for volume control.
2: Bottom to top hotspot. The pointers' position is converted
to the 0 - 100 range. Bottom is 0, top is 100. Useful for volume control.
The second value is a boolean. If set to 0, the hotspot will not be
retriggerable. This means that you will need to turn your laser off and
back on to retrigger it (was the behaviour of version < 0.3). If the
value is 1, the hotspot will be triggered approximately at one second
intervals.
The next first 4 values are upper left X,
upper left Y, lower right X and lower right Y. The last value is the command to
be executed when the laser pointer enters the hotspot. Here is a sample:
0,0,174,111,242,164,xmms --play-pause
1,0,29,169,318,196,setmixer vol
0,1,0,0,50,50,echo -en "\\007"
In the first example above, the upper left coordinate is 174,111 and the
lower right coordinate is 242,164. The command "xmms --play-pause" toggles
play and pause on an xmms instance running on the same machine.
The second example implements a volume bar. The command setmixer will
be appended a value from 0 to 100. eg: "setmixer vol 55"
The third example demonstrates the repeat function of hotspots. If laserspotcam
is not running in background, you should hear a beep each time the command
is executed.
5: Test
Now that you've written your config file, try it by specifying it on
the command line when starting laserspotcam. The hotspots you defined
will now appear in red. ex:
# ./laserspotcam -vVr xmms.hs
Of course, you replace 'xmms.hs' by your config file name.
6: Start laserspotcam in the background and enjoy!
# ./laserspotcam xmms.hs -b
Notive the -b for background mode. Try -h for more options.
Algorithms
Pictures are continuously received from the webcam. First of all, the picture
is converted to grayscale (Luminance). Next, the average of the last 8 pictures
is substracted from the current picture, to obtain a picture containing only
de differences.
In this new picture, each pixel represents the amount of variation against the average (8 picture
average). The bigger the difference, the higher the pixel value. Usually, there are small
difference everywhere because of the noise (webcams are not perfect).
In order to be able to track the pointer's position, we need to consider only the biggest
differences. To
do this, each pixel's value is checked. If it is higher than the threshold, it is set to 255 (max). If
it is lower than the threshold, it is set to 0. After doing this, we have a black and white picture,
without noise.
The black and white picture is easy to interpret. The rectangle containing all the pixels that
have changed is calculated. Since the laser only generates a small spot, we check the
size of the rectangle:
- If the rectangle is too big, it is ignored.
- If the rectangle is very big, laserspotcam assumes
the difference is due to a light that has just been turned on or off. To prevent
the light event to trigger hotspots by mistake, the 8 next images (configurable)
received from the webcam are ignored. This allows the webcam to adjust itself to
the new lighting condition, and it also lets the average of the 8 last pictures
rebuild.
- If the rectangle size makes sense, the list of hotspots is searched for an
hotspot in which the rectangle fits. (it is a little more complex, see below)
Anti-repeat
To prevent a hotspot from being activated more than once because you left the pointer
inside it a little too long, the following strategies are used:
- Once a hotspot is activated, the following pictures
containing changes (valid or not) are ignored until a picture
without changes (not laser pointer) is received. (Note: This does not
apply to repeatable zones)
- When a hotpot is activated, the time (hour/second/millisecond) is saved and
the hotspot is disabled during one second.
Why a 8 picture average?
This yields a stable picture to compare the received pictures with as it illiminates
short changes (8 frames are needed for a new object to by 100% visible). In the future,
this will make it possible to have hotspot that triggers only if the pointer is in the
hotspot during a minimum number of frames. Without the 8 image average, the pointer would not
be detected in the second frame since there would be no differences.