threshold (currently, any pixel with a Y value greater than
0.3). If so, the pixel is set to ‘1’ (white). If not, the pixel is
set to ‘0’ (black).
3. Column Sum. Count the number of 1 pixels within
each vertical column. This results in a one-dimensional array
containing the number of valid pixels per column. By
summing the valid pixels, we can more easily and quickly
search to locate any blobs within the frame. The following
image shows the zoomed-in blob with the column’s sum
printed at the bottom of each column:
4. Blob Detection. Traverse the one-dimensional array
of column sums looking for any sums above a defined
threshold (currently, a column sum needs to be greater
than two in order to be considered part of the blob). For
example, in the previous image, the blob would start at
column 7 (which has a sum of five) and end at column 22
(which has a sum of six). This is repeated across the entire
frame until all blobs have been detected.
5. Mass/Centroid Calculation. Calculate the total
mass and centroid for the detected blob(s) in the frame.
The mass is simply the number of valid 1 pixels within the
total blob. The centroid of a blob is calculated by weighting
every valid pixel with where it is in the blob and averaging
by the total mass:
For column 1..n of the blob:
sum = 1 s1 + ( 2 s2) + ... + (n sn)
where sn = column sum for column n
44 SERVO 11.2011
Then, centroid = sum / mass
Simpler image processing — like the CMUcam3’s blob
detection — sets the centroid as the center point of the
bounding box. However, this type of calculation would only
return a proper value for round, balanced spots. Since we
don’t know what type of object the laser will be pointing at
and how the light will vary when it reflects off of the
object, the resulting blob may neither be round nor
balanced. Performing the weighted average gives a more
accurate center of mass result, regardless of blob shape.
centroid = sum / mass = 1737 / 200 = 8. 7
The blob with the largest mass is then chosen as the
primary blob (which we assume is the actual laser spot) and
will be used for the subsequent range finding calculations.
If there are multiple blobs with the same mass, the first
occurrence remains the primary.
To account for manufacturing and assembly variances
— particularly related to the camera and laser diode
alignments — each LRF module must go through a
calibration step during production. The unit can also be re-calibrated by the user at a later date if desired.
The calibration routine requires the user to place the
LRF module at a number of fixed distances (currently 20 cm
to 70 cm at 10 cm intervals). The LRF takes measurements
at each distance and calculates the SLOPE, INTERCEPT, and
PFC_MIN values (the routine is based lightly on
values are then stored in an unused portion of the non-volatile boot serial EEPROM. The LRF has a 64 KB EEPROM
which leaves 32 KB available for data storage after the
Propeller uses the first 32 KB for program code. This also
means that the values will not get overwritten when the
LRF code is re-loaded into the EEPROM.
The SLOPE and INTERCEPT are used to convert the pixel
offset to angle using a best-fit slope-intercept linear
equation (discussed earlier in this article). The PFC_MIN
value is used to set the maximum allowable distance of the
LRF module which is represented by a minimum of pixels
from center value. Check out this video demonstrating the