The Laserfind-Routine...
view the source code
This site tries to explain the routine wich is used to find a laserpoint
in a picture, and to decide wether there is a laser or not.
First apicture without any laserpoints is grabed and is marked as the
ORIGINAL. Then the next grabbed picture (now with a laser-spot) is COMPARED
to the ORIGINAL. This happens EVERY TIME a laser-spot must be detected!
(every time -> one without and then with the laser switched on)
"COMPARING" here means substraction of the brightness-values of the
ORIGINAL with the actual picture. In our program the files are read in into
different layers in a 3D-array. For example the ORIGINAL gets into layer 0
the actual picture gets into layer 1 and the diff-picture is written into
layer 2. The declaration of our array looks like this:
signed int im_data[650][490][3];
While creating the DIFF-MAP the maximum and minimum of the difference
between ORIGINAL and actual image are calculated. They are used to maximise
the visibility of differences in the output image (if one is created).
And every time a value greater than MAX is found MAX is overwritten with
that value and the coordinates of this pixel are stored. So when the routine
has gone through the complete image, we have stored the minimal/maximal
value of difference and the coordinates of the maximum.
The calculated coordinates should be the ones of the laser-spot. But if the
laser is not in sight this must be also detected in form of x=-1. So imagine
having a box with a mirror-smoothly surface and the laser-spot should be
behind the box and therefor be not in sight but causes a visible reflection
on the invisible side of the box.
In most cases these reflections lead to a valid detection of a non-existent
laser-spot. (or at least an invalid one) Now the algorythm takes the
maximum-brightness and compares values beside the maximum-coordinates to it.
It runs from the maximumX to maximumX + 20. When the brightness falls
below 10% of maximum-brightness it stops and runs in the other direction
(from maximumX to maximumX - 20). Now we have the 10% broad of the laser-spot.
If this is to large it mostly is a reflection because all reflections on
natural surfaces get spreaded more or less by the sourface roughness.
In our first tests we found out that looking for the broadness of the spot
is not really shure or at least a few values (like the percentage or maximum
size of the spots broad) must be determined experimentally. Perhaps if these
values get adjusted the routine solves the most images correct.
OUTPUT IMAGE...
For an output image the offset of the difference values is removed. So if
the whole actual image is a bit darker than the ORIGINAL there might be a
difference-minimum of 2. Then a loop runs through the image and substracts 2
of every pixel.