Building a Homemade Laser Line Scanner (CS6998, Spring '01)
May 1, 2001
Team: "Have Screwdriver Will Travel"
- Ethan Gold <etgold at thaumaturgy dot net>
a.k.a:
"Crazy Bastard with a Screwdriver"
"Your Loving TA"
"You-can't-see-me-I'm-not-here"
"You want to scan when?!?"
Summary
The goal of this project is to build a low-cost laser line scanner
out of off-the-shelf parts and stuff I find around the house and to
use it to construct a reasonable point-cloud scan of a recognizable
object. From the point cloud, existing software can be used to create
surfaces, and hopefully solid models as well (undetermined).
Contents
The cost and performance of the system was determined partly by the
hardware available. I chose the Nikon camera because I already owned
it, thus reducing the entire cost to under $100. For the laser, I
decided that since I would be doing image processing in software anyway,
it would be far easier and more cost-effective to correct for the effects
of a low-quality laser in software than by trying to get my hands on a
proper research-quality laser. For image acquisition in the computer,
I used my existing video card which also has video inputs. In the end,
I spent the most money on parts I didn't actually use, such as mounting
brackets and other junk from the hardware store, and a small batch of
unuseable laser diodes (needed laser diode modules) from digikey.
- Camera: Nikon Coolpix 800 1600x1200 stills w/ NTSC video out
at 640x480, 1/3" CCD
- Video Capture Card: ATI All-In-Wonder Pro w/ NTSC input
(10-14fps) using the Gatos ATI capture package for Linux.
- Laser: $12.95 laser pointer powered by 2 AAA cells
- Lens: $0.60 3"x0.4" clear plastic rod from Industrial Plastics
- Turntable: $30 Gaurraud turntable (33,45,78rpm) from the
Salvation Army
- Computer: K6-II/450 desktop running Linux 2.2.18
The software is divided into three logical pieces.
- Scanner driver pieces (detectbutton, timerotation,
beep)
- There are two programs that talk to the scanner
direcly.
Detectbutton detects the scan-control button
on the scanner box. It simply waits for the signal on the serial
control line to go high.
Timerotation times the speed
of the turntable over the serial port by watching another
control line.
- Scan-acquisition scripts (takescan_*.pl)
- These are perl scripts which call third-party
image-acquisition software for whatever video hardware is being
used. This could be ATI, SANE, or V4L2. They prepare the data to
be processed and deliver the time-of-scan data necessary to do
the per-image data rotation.
- Scan-processing program (procscan4)
- This is the C program that does most of the work. It reads
in a set of configuration files which define the parameters for
the camera, scanning geometry, and the individual scan and then
processes all the grayscale images one-by-one. Each image is
processed using a simple Mean Pulse Analysis without regard for
the other images in the set:
- Find the center of the laser for each scanline in image
coordinates
- Cast rays though each pixel and
intersect them with the known position of the laser plane
using standard vector math techniques to discover their 3D
locations in camera coordinates
- Transform each point into world coordinates using the
camera calibration matrix and rotate them into the correct
position based on the angular rotation of the frame.
- Output the points in an NxM grid, including 0-data
points to preserve the rectilinear grid structure of the
data for later meshing.
Some third-party software was used to edit the point clouds and
create the surfaces on the data page. The Alias suite comes with a
tool called EvalView which is useful for editing point clouds, but
does't preserve the rectilinear structure of the data. This is really
really really annoying. Fortunately, there is a cool piece of software
(which mostly works) called Alvis (Alpha Shapes Visualizer) from NCSA
which will create surfaces from unstructured point data. The surfaces
on the data page were created with this tool. Unfortunately, as with
many research projects, this code is no longer supported and
occasionally fails under Linux. The source code is not available for
the recent versions.
Platform:
The scanning platform is built from a piece of scrap wood from the
hardware store into which I mounted two roughly vertical pieces of
1/4" threaded rod 30cm apart. Several pieces of angle-iron on each
armature serve to support the camera and laser assembly on their
respective mounts. The laser is strapped to a T-shaped piece of wood
onto which the cylyndrical lens is strapped (laser and lens mounting
is achieved via innovative duct-tape restraints, the details of which
will be discussed in a later journal article). Radial lines were
inscribed on the wood base around the axis of the laser for measuring
laser angle, but these were later discovered to be both inaccurate and
unnecessary. The short axis of the platform is oriented towards the
center of the axis of rotation of the turntable.
- The Platform on my coffee
table where it was developed w/ the qcam instead of the Nikon
(which is taking the pictures)
- The Platform in the
lab w/ the quickcam. Note the unconnected turntable timing plug on the electrics
box
- The Platform in the Lab w/
improvised turntable using flimsy catering platters, a 3/16"
stove bolt, and 5 berring balls (kids, don't do this at
home)
Laser:
The laser is a basic red single-spot laser
pointer from an online source (it is not legal to sell laser pointers
in NYC because apparently violent criminals strap them to their
pistols). The laser is powered by two 1.5v AAA batteries which are
normally housed in the barrel of the device. I replaced the batteries
with an internal structure which makes the necessary electrical
contacts and has wires running out to an RCA plug so that power can
easily be moved, replaced, or controlled externally. The spot produced
by the laser is not perfectly round - it is actually slightly
rectangular in shape. I orient the long axis of the spot vertically so
that the cylindrical lens stretches the laser along the long axis of
the spot, producing a taller, thinner beam. Fortunately, the
non-gaussian shape of the laser is actually a bonus in this setup, and
the effect of the lens allows the stripe to be analyzed as a gausian
in each dimension separately, if desired.
- The Laser projected onto a
white wall about 100cm away. The power source is the weaker
(2.4v total) NiMH rechargeables which were the only batteries I
had laying around when the alkalines finall died.
- The Laser projected onto
a highly reflective white background at the back of the
turntable. Note the multi-disc post on the turntable (before it
was sawed off). All that spread is easily thresholded away.
- The Laser as
above with the Susan Ivanova (B5) model on the
turntable. Fortunately actual data isn't this messy.
Camera:
The camera is a midrange consumer digital camera
(~$425 including NiMH rechargeables, charger, and additional 16MB
compact-flash card in the fall of 2000) which has a standard 1/4"
tripod mounting sleeve in the bottom. To optimize image coverage and
vertical resolution, the camera is mounted in a portrait
orientation. The change in orientation is unwrapped in software
automatically from the calibration output. Still images on the compact
flash card can be transferred to the computer via serial cable, but
this camera conveniently supports a dumb-operation mode where it just
outputs NTSC 640x480 full-motion video on an RCA jack. This runs
directly to the image acquisition hardware on the computer.
Communication:
I built a custom electrics box into a plastic floppy disk case which
is screwed to the wooden scanning platform. It has a short-circuit
turntable timing line to time turntable rotations. Outputs are 3v from
two internal AAA bateries to power the laser, and a 9pin serial port
to the computer. The box has a power switch which turns on the laser
and connects the turntable detection line to the serial port. A
temporary switch tells the computer to take a scan images. All
communication takes place over the serial port control lines.
- The Electrics box with the
lid open. The batteries power the Laser (wires running out to
the right), the unconnected RCA plug is for the turntable timing
switch, and the serial port runs the control lines to the
computer. The Power switch connects the serial port to the
wiring and powers on the laser. The red button in the upper left
corner is the scanning button. The Blue stuff is Sculpy,
unbaked, since I didn't have a good solution for mounting the
switches. The Sculpy along with the cut-outs in the lid hold the
switches quite securely. Clearly this is a high-precision operation.
The wiring was performed by a robotic manipulator in a cleanroom.
Turntable:
The turntable is a slightly modified Garraud model from the Salvation
Army. The multi-disc armature and center post have been removed. The
audio pickup has been outfitted with a spring-loaded temporary switch
which is positioned near the edge of the table within range of a
longish extension which toggles the switch for several centimeters of
each rotation for the purposes of timing the rotation speed. It turrns
out that under the hardware and scanning condition constraints the
turntable actually moves too fast, so I now manually position the
turntable in 5-degree increments (inscribed on a positioning overlay
intersected w/ the laser plane) for slow low-resolution, but more
accurate scans. This is currently the bottleneck to further system
development.
- The Turntable with
the calibration pattern
- The Turntable with
the 5-degree manual scan overlay
- The Armature with
the audio cartridge modified to handle a temporary switch which
is activated by the timing toggle attached to the turntable. The
battery on top of the arm is for weight. The blue goo is more
unbaked Sculpy which holds the armature in place - high
precision positioning.
Platform Calibration:
Camera/Laser calibration is performed by running Tsai's calibration
code against a set of manually selected correspondances in a
full-light, no-object test image of the scanning platform with a
calibration checkerboard overlay. Since Tsai's coplaner code assumes
an X/Y plane, the y/z input data coordinates must be swapped. Tsai's
algorithm takes a set of basic camera parameters, including CCD pixel
dimensions and resolution. The output is the XYZ rotation matrix and
translation vector of the camera relative to the calibration plane,
along with the focal length of the camera in a pinhole model. These
output parameters are entered into the appropriate scan-processing
config files.
The calibration of the laser plane is achieved by
aligning the x-axis of the calibration checkerboard with the projected
laser line. The resulting Y-rotation of the camera is the angular
difference between the camera and the laser. This is picked out in
software. This little trick VASTLY simplified the scanning platform
setup as you don't need to measure anything.
- A Calibration photo from the
Nikon. This is an image from which correspondances for input to
Tsai's algorithm are taken
Scanning Process:
- Turn on the scanner and Invoke the scan-acquisition script,
specifying either the number of frames or the scanning time in
seconds, depending on the hardware/software configuration.
- The object is placed on the scanning table w/ the laser on
for a single full-color sanity-check image. Push the scan button
once, wait for 3 beeps.
[sanity
photo]
- Remove the object and place the beam-calibration post/panel
on the axis of roation to take a clean image of the entire laser
beam. Turn the lights off. Push the scan button once, wait for 2
beeps.
[laser calib color]
[laser calib grayscale]
[laser calib segmented]
- Remove the beam-calibration post and position the object to
be scanned on the turntable surface. With the lights off, press
the scanning button one more time. For an automatic scan, the
computer/scanner will measure the rotational speed of the
turntable (which must be on at this point) and then take a
series of images. For a manual scan, the scan button must be
pressed to take each image (wait for the beep) and the turntable
manually rotated the appropriate number of degrees. I use a
5-degree radial scanning overlay for the manual scans.
[sample gray scan image]
- The output images are converted to PGM format automatically,
if necessary. The scan time and RPM parameters are appended to
the default scan config file (60sec and 1rpm for a manual scan)
and then the beam-calibration image is displayed so you can add
the start and stop coordinates of the beam on the calibration
post for the purposes of segmenting the beam to characterize
it. This bit is only partially used right now.
- Run the scan-image post-processing software on the resulting
data to output a point cloud.
- find/create a good way of culling unwanted points from the
clouds so the turntable and other artifacts can be segmented
out. Using evalview from the Alias suite now. An ideal
point-cloud editor would zero-out the deleted points instead of
removing them entirely. This would preserve the cylindrical
rectilinear grid structure of the data.
- slow down the turntable effectively ans consistantlyso I
don't have to manually set up every shot. A manual scan takes
about 15 minutes (72 images)
- Generalize the system and make it portable: I would like to
generalize the software a little more and write
image-acquisition scripts for a variety of video inputs. I
already own a parallel port quickcam and would like to test
some other cheap cameras that operate over standard hardware
like USB, obviating the need for a special video input card in
the computer and allowing the system to run on most
laptops.
- Rebuild the laser mounting into a more robust housing
- Automate the camera calibration step like the Eclipse team
has done, but this puts constraints on the contents of the
calibration image if edge-detection is to be used.
- Build a tcl/tk UI to the scanning process (which is already
pretty straightforward) to allow the user to choose inputs and
scan parameters without editing the per-scan configuration text
files directly.