|
||||||||
|
||||||||
| Cette page est aussi disponible en français | ||||||||
| What is it? | [cacher] |
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 | [cacher] |
|
Pictures from me: Pictures from Brian Dahlem:
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 | [cacher] |
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.
|
| Supported cameras | [cacher] |
Here is a list of webcams and/or video capture peripherals that
have been tested with laserspotcam:
|
| Installation and configuration | [cacher] |
| 1: Compilation You will need to have the sdl library installed. To compile laserspotcam, simply type: # make2: Start laserspotcam In the directory where you compiled laserspotcam, type: # ./laserspotcamlaserspotcam uses /dev/video0 by default. If you want to use another video device, use the -d option, like this: # ./laserspotcam -d /dev/video1Laserspotcam 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: TestNow 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.hsOf course, you replace 'xmms.hs' by your config file name. 6: Start laserspotcam in the background and enjoy! # ./laserspotcam xmms.hs -bNotive the -b for background mode. Try -h for more options. |
| Used algorithms | [cacher] |
| 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:
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:
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. |
Coded manually using
|