A Simple 3D Scanner
There are many ways to scan a three dimensional object into the computer. The system described here is not perfect for every application - but is cheap, easy to implement and works for most small-ish objects.
This is a 'HOW TO' - but it assumes that you have some basic construction skills, and that you are reasonably familiar with computer software and image editing. PLEASE DO NOT EMAIL THE AUTHOR ASKING FOR MORE HELP WITH GETTING THIS GOING BECAUSE YOU DO NOT HAVE THOSE SKILLS. If this document doesn't answer all your questions - then look elsewhere, I don't have the time to build the software for specific people, to improve the software or to build scanners for people.
- 1 BEWARE!!!
- 2 Parts.
- 3 How it works.
- 4 Limitations.
- 5 Important Details.
- 6 Other key measurements.
- 7 Scanning.
- 8 Video Editing
- 9 The Scan_Extract Tool.
- 10 Scanning Faces.
- 11 Extracting Textures
Playing with lasers (even low powered ones such as laser pointers) is DANGEROUS. Pointing the laser towards people's faces is risky and pointing it into their eyes can easily cause permenant damage to their vision.
- When using a laser, pay CAREFUL attention to mirrored surfaces, lenses and other optical apparatus because those can send laser light off in unexpected directions or increase it's power to a damaging degree.
- Use only RED laser pointers. The GREEN ones are much more powerful - and hence damaging. That extra power does nothing to improve the scanner - so please stick with red light.
- Make sure that the laser is a low powered one. Some red laser pointers are imported illegally and are too bright. Approved lasers have a laser safety sticker indicating that they are class 1 or (at most) 1M. Avoid class 2 lasers and above since even as little as a quarter second of exposure is enough to damage your vision.
- The laser line generator spreads the light out and thereby lessen the power at any one point - which is helpful for safety. Make sure the laser line generator is working and in place.
- If you absolutely must scan someone's face or body, make sure that the person has their eyes firmly shut throughout the process and make sure the scanner runs fast enough to minimise the amount of time that the persons eyes are in path of the laser beam.
No matter what, please take every precaution and remember that you are doing this at your own risk.
- A digital movie camera (or a digital still camera that can capture short movies).
- A personal computer with basic video editing software. (The OpenSourced 'mplayer' and 'mencoder' worked well for me).
- A red laser pointer of class 1 or 1M.
- A 'line generator' lens.
- Some kind of turntable to rotate the object...or...
- Some means to move the camera and laser pointer in a smooth, circular path around the object.
- A straight edge, a protractor and a large sheet of paper.
How it works.
The laser pointer is aimed through the line generator lens to make a vertical line of laser light. The object is rotated on the turntable so that the line of laser light passes slowly across its surface. The camera films the action from a position off to the side of the laser so that the line of light appears to move to the left and right as it passes over the uneven surface of the object.
The resulting video appears as a wiggly line of laser light that can then be analysed by a computer to extract the distance of each point on the object from the center of rotation. This 'point cloud' can in turn be converted into a mesh of triangles that can be displayed or otherwise manipulated in three dimensions using conventional 3D rendering or CAD tools.
An AVI (10Mb) produced by my setup while scanning a model of Tux the Linux Penguin.</A>.
By taking two videos of the object:
- With the laser on and the room lights off.
- With the laser off and the object illuminated by a white light from behind the camera.
...you may also capture a texture map which when applied to the object reproduces it's surface colouration.
- Objects which are very shiney don't scan well.
- Objects which are 'fuzzy' with fur or very fine spikes don't work well.
- Objects with holes or deep 'undercuts' (such as the handle on a teapot) probably won't be completely scanned. However, offsetting the object on the turntable can sometimes help.
- Large or immobile object that can't be placed on a turntable require different techniques.
- Translucent objects cannot be scanned.
- The object must stay still throughout the scan - so don't even think about scanning your cat.
The computer needs to know all the parameters of your camera and it's ESSENTIAL that these things don't change.
- Be sure to keep your camera at the exact same zoom settings throughout your experiments.
- Turn off the auto-focus, auto-black level and auto anything else you can find! Don't use electronic zoom.
- If you are setting up the camera close to the subject, you may have to put it into a 'macro lens' mode. Read the manual for your camera carefully.
- Pick the highest quality setting you can find. If you are using a digital still camera that can grab short videos, trade higher resolution for slower frame rates if you have to. You can always make your turntable spin slower. However, sometimes these cameras can only store 15 to 30 seconds of video - so make sure the turntable rotates at least once within that amount of time!
Room lighting and reflections.
The darker the room when you do the scanning, the better. Reflections of the laser either from the room - or from one part of the object to another - are very bad. Remove anything shiney from the vecinity of the scanner - if necessary, drape a black velvet curtain around the whole setup, cut a small hole for the camera lens and the laser. If the object is shiney, then there may be problems. If you don't care too much about the object, spray it with flat grey primer paint.
Having said that though, I've had good success without doing anything other than to turn off the room lighting.
The laser line generator lens.
The laser pointer produces a single dot of light, but we need a long, thin, line of laser light. You can generate a line of laser light by shining the laser through a glass or acrylic cylinder (try the stem of a wine glass for example) - but low quality lenses tend to disperse the laser sideways as well as vertically which makes it harder for the computer to find the exact point where the laser hit the object. You want a sharp, thin line - not a fat, fuzzy one.
I also tried the 'laser level' tools now available from home maintenance shops. The two cheap ones I tried were poor - but you may have more luck than me.
If possible, try to find a high quality 'line generator' lens. I found a holographic lens of the kind used in supermarket barcode scanners. I also played with a number of Fresnel lenses that worked acceptably. One word: "eBay"!
It didn't seem to matter whether I used a cheap laser pointer or an expensive one - so go cheap!
The position of the camera and the laser.
Both the camera and the laser should be aimed at the exact center of the turntable. The laser must be far enough back that the 'fan' of laser light completely covers the vertical height of the object. The camera must be far enough back to see the whole vertical height of the object - and to catch all the areas of the object that the laser may shine onto.
The angle between the centerline of the camera and the laser light is also significant. My own experimentation - suggests that an angle of about 15 degrees between the center-line of the camera lens and the laser beam is best - but for some shiney objects, you may need to change that in order to get the best results.
Whatever angle you choose, it's essential that this number is carefully measured and that the camera, turntable and lens don't move from these positions as you scan.
<A HREF="scanner2.jpg"><IMG SRC="scanner2_small.jpg"></A>
It is quite important that the turntable rotate at a constant speed throughout the scan. Turn the thing on well before you start the video camera - that way it's speed will stabilise.
You also need a way to see when the turntable has made a complete revolution so you can crop the video down to a single revolution of the turntable. I used a small blue LED shining through a tube taped to the underside of the turntable.
This produces a brief flash of blue light at the beginning and end of one revolution of the turntable.
I built a turntable out of Lego - gearing down a 9v Lego motor until it turned the turntable at about one revolution every 30 seconds.
If you spin the object faster, you'll have fewer data points, but if you make it too slow, the amount of video data you have to process will choke your poor computer!
Other key measurements.
You are going need to know the distance from the cameras tripod mount to the center of the turntable and the angle of the camera lens.
Camera lens angle.
The easiest way to work out the lens angle is to set up the camera on a large piece of paper. Make sure you have the camera zoomed to it's "normal" setting - and always use it in that setting when scanning.
Then, looking though the LCD viewfinder (not the direct view eyepiece), place a long straight edge in front of the lens, moving it so that appears to be lying exactly along the left edge of the viewfinder. Draw a line along that straight edge. Without moving the camera, repeat the process with the straight edge on the right edge of the viewfinder.
Finally, draw as far around the 'foot' of the camera (where it would attach to a tripod) as you can reach without moving it. Now remove the camera and extend those two straight lines until they cross.
Use a protractor to measure the angle between those two lines. In most cameras, they'll cross roughly in the middle of the 'foot' - but if not, note how far from that point they cross.
Now remove the camera and measure the angle between the two lines - that's the lens angle. In many cameras, the angle is 50 degrees - so if you measure the angle and it comes out close to 50 - then it probably is exactly 50.
Distance from camera to turntable.
Measure the distance from the center of the cameras 'foot' to the center of the turntable. If the two lines didn't cross at the center of the foot, adjust your measurement to get the distance from the center of the turntable to where those lines would cross.
Here is the scan checklist:
- Now you should have everything set up just right, check all distances and angles one more time.
- Make sure the camera is at the correct zoom setting with auto-everything turned off, make sure it's focussed, etc.
- Set the turntable running and let it get up to a steady speed.
- Make sure your object is roughly centered on the turntable and not moving or shaking.
- Turn on the laser, turn off the room lights.
- Now carefully turn on the camera (if your camera has a remote, use it to avoid jiggling the camera.
- Wait for the turntable to undergo one complete 360 degree revolution.
- Turn off the camera first, then the laser, then the turntable.
- Download the video onto your computer and get to work!
You'll need to get the video edited down to as close to one whole exact revolution of the turntable as possible. This will mean that you have to pick a point in the revolution of the turntable and cut out the frames before that point is in the exact center of the screen - keep one complete revolution and then delete everything after that point appears back in the center of the screen. The more accurately you can do this the better.
(If your final scan of a roughly cylindrical object comes out 'heart shaped' or 'teardrop' shaped with an inward or outward 'seam' - then you probably didn't edit the video exactly right.)
Now, use your software to chop the video up into single frames, named something line '00000000.jpg', '00000001.jpg' and so on. If you have 30 seconds of video, you'll get either 900 or 1800 files which will consume VAST amounts of disk space. (A typical 30 second scan with a 640x480 resolution camera produced 6 megabytes of data - but this can vary considerably depending on the software, camera and room lighting).
Now comes the software magic.
The Scan_Extract Tool.
This is where you'll need some software skills.
The program I used to extract 3D images is included here and the 'Makefile' for it is here. No, I do not provide binaries of these programs - nor will I do so, no matter how much you beg and plead. The program is released to you under the GPL license.
The program expects the input frames to be numbered from 00000000.jpg upwards.
The program has to be hand-edited to set the various parameters of your scanner. This could be improved upon - but you'll probably want to change the program anyway.
(All angles are in degrees, all distances are in meters).
- CAMERA_HFOV - Set this to the camera lens angle that you worked out above.
- CAMERA_VFOV - Leave this alone, unless you are working with an unusual kind of camera such as an HDTV camera which doesn't have the usual aspect ratios.
- LASER_OFFSET - The angle between the centerline of the camera and the laser.
- CAMERA_DISTANCE - The distance from the camera 'foot' to the center of the turntable.
Additionally, you might want to change:
- HORIZ_AVG - The number of consecutive horizontal points to average together to smooth out the surface.
- VERT_AVG - The number of consecutive vertical points to average together to smooth out the surface.
Increasing these numbers gets rid of odd spikes and other small errors - but reduces the number of polygons making up the final model and thereby reduces the precision of the final model.
If you are scanning something like a human face, it may be impractical to rotate the person being scanned. In this case, you should probably consider rotating the laser and the camera in a circle around the persons head rather than spinning the person.
PLEASE re-read the warnings at the top of this page about the dangers of laser light to people's eyesight.
In order to extract a surface colouration texture for the object, it will be necessary to shoot two videos - one with the laser and one in natural light. You'll need to modify the Scan_Extract program to read BOTH videos - frame-by-frame in sync and whenever it finds a spot of laser light in the laser video, take the colour from that same location in the daylight video and apply it to that point on the 3D model.