Introduction: DIY: How to Make a Low Cost 3D Scanner
For this tutorial I am assuming you have both math and coding knowledge!
Also for this tutorial you will need Mat Lab computer vision toolbox, an Arduino, a laser line and a webcam.
UPDATE:
Due to popular demand I bring you the official publication: https://www.researchgate.net/publication/321668948...
HUGE thanks to my great friend Bryer C. Sousa for making this possible. I hope this helps everyone who is interested in computer vision projects!
Step 1: Building the Turn Table
The first difficulty I had making this 3D laser scanner was finding a rotating platform I could control with MatLab. Instead of spending lots of money or time I went to eBay and bought 5v Stepper Motor 28byj-48 With Drive Test Module Board Uln2003 @ http://www.ebay.com/itm/like/371474310734?lpid=82&chn=ps&ul_noapp=true For almost no money at all. I included the 3D models of the turn table I created using the stepper motor and marbles i bought at the dollar store. Just hot glue the platform to the shaft of the stepper motor and place the stepper motor in the slot within the holder. The platform should be level with marbles but be aware the cheaper the marbles the more inconsistent the diameters which may make things not level.
Step 2: Onerot() Function
The function onerot(Arduino, PauseTime, #of loops) does a basic full step sequence. If you are using the platform and stepper motor within this tutorial use a pause time of 0.005 for smooth rotation.
Code for the stepper motor found at : http://pastebin.com/7KVBUrvK
Step 3: Finishing the Setup
Once you have a method of getting an accurate rotation that can be controlled within Mat Lab set up a camera at any distance and height away from the turn table and a laser line to either the left or right of the camera at a similar distance away from the turn table. The angle of the laser should be placed optimally to cover as much of the turntable as possible but nothing has to be exact we will handle model scale difference within the code.
Step 4: Calibrate the Camera
The most important part to make this work accurately is to calibrate the camera properly. Using the MatLab computer vision toolbox I was able to obtain a accurate focal length and optical center of my camera within 0.14px accuracy. Keep in mind changing the the resolution of the camera will change the values of the calibration process.
The main values we are looking for are focal length measured in pixel units and the pixel coordinates of the optical center of the image plane.
Step 5: First Equation
Lets see how if this is true
Step 6: Converting to Camera Coordinates
In MatLab an image is represented as a matrix starting from 1,1 to max resolution. However we need to represent points in terms of camera coordinates with the optical center points at [0,0]
Step 7: Using the Basic Pinhole Equation
As we can see it works well and can be very useful if we do not know the initial value of the laser angle.
Step 8: How the Scanner Model Is Represented
As we can see lots of triangles to analyize
Step 9: Using the Law of Sin
Step 10: Equations
xiaomaxiao:
Ao=90 - atan(xo' / F) = 90 - atan( -225/919) = 90 - (-13.75) = 103.757
not 90-(-15.508) .
Thank you for catching that Xiaomaxiao!
Step 11: Main Algorithm
Step 12:
Step 13:
Step 14: NewFilter Function
Probably the hardest part of this scanner and the one thing i hope continues to work but this filter will do the trick to get a nice single laser line in most conditions regardless of light. The less ambient light the better.
Attachments
Step 15: Variables to Change
Modify these variables in the top of the calibration script to get the script to work accurately for you
Calibration code : http://pastebin.com/CCD6bdt7
Attachments
Step 16: OutPut of the Last Script
The last script generates the 2D points cloud of the scene in the steps in the image.
Step 17: Adjust the Y Axis Values
Step 18: Adjust the Y Axis Values
Step 19: Transforming the Points
Step 20: Determine Your Turntable Platform Center
Step 21: Determine How Many Loops for 360 Degrees
Step 22: Main Laser Scanner Code
Modify the top line of the code to fit your model and adjustments.
Attachments
Step 23: Scan Your First Object
At this point you should be scanning models
Step 24: Creating Mesh From Point Cloud Step 1
Step 25: Creating Mesh From Point Cloud Step 2
Step 26: Creating Mesh From Point Cloud Step 3
Step 27: Creating Mesh From Point Cloud Step 4
Step 28: Creating Mesh From Point Cloud Step 5
Step 29: Creating Mesh From Point Cloud Step 6
Step 30: Congratulations You Have Successfully Created Your Own 3D Scanner!

Participated in the
Beyond the Comfort Zone Contest
49 Comments
2 years ago
I am trying to do something similar with a laser that projects a cross (instead of a line). Essentially, I have laser mounted on a board a fixed distance from a camera (also mounted on a board) and scan stationary object by moving the laser-camera mount up/down and left/right. I get decent depth measurements along the vertical line, but not along the horizontal laser line. The depth measurements get worse the farther away the horizontal laser line gets from where it crosses with the vertical line (at each end of the horizontal line). Do you have any insight as to what's going on/how I can fix this problem.
Reply 1 year ago
2 years very late but for those with the same question.. How well were are you correcting for optical distortion?
Question 1 year ago on Step 19
Bonjour et félicitation pour votre travail. Je n'ai pas compris les valeurs y_trans=14 et z_trans=-315 !
Cordialement
Answer 1 year ago
Used for rotation transform of the points around the center of the rotation stage.. See Step 20 for calculation (for that test I got y_trans = 26.24mm and z_trans = -263.9mm).. because my rotation stage wasn't fixed I recalibrated that value each use, using the step 20 process.
Question 3 years ago
you mentioned about getting the Y and Z translation values (14 and -315), which was quite intuitive, my question is that can't I get it directly from the calibration of camera in Matlab? (extrinsic parameter-translation vector)
Thanks......
Answer 3 years ago
Yes, if you calibrate it correctly that would work. I opted to manually select the pixel at the center of the platform instead of programming it in because I'm lazy =) (I also manually determined my camera parameters with like a single image. I didn't even use the matlab camera calibrator because I couldn't get it to work accurately enough).
4 years ago
Hey,
Thanks for sharing your project.
Can you please show how the camera and dot laser are connected. I want to see the hardware setup if possible.
Thanks again
Reply 4 years ago
Web Camera is direct USB into computer.. Laser is Arduino Pin D22. Stepper is also attached to same Arduino Mega Per Amazon instructions.
4 years ago
Hi! Nice one! I cant understand two things.
y_trans = 14; % Transform value for Y
z_trans = -315; % Transform value for Z
Can you explain me this two? Why -315? Why 14? How did you calculate that?
Reply 4 years ago
Step 20... Sorry for the long wait.
So, when i first did the calculation, when I thought, "I GOT IT!".. It looked weird but, kinda familiar at the same time. What i noticed was I was calculating the points with respect to the camera ( camera at 0,0,0) and not the center of the platform. So when I did the first calculation it was as if I was inside of the mesh and the mesh was also inverted.. Very strange.. To fix the problem I first translated the points so they were in respect to the center of the platform ( center of platform is now 0,0,0) then I rotated my translated points.
To get the translation matrix values I placed a flat wall on my platform and took a picture of my laser line. Did the depth calculation without any translation and manually selected the lowest point on the wall I could detect and used the inverse of that position to zero my calculations.. The Ty & Tz to be correct... Tx was used for calculation and thus only Ty & Tz are needed for transformation and x was calculated with rotation of y & z points.... Lol Y is just scaled for ease of calculation with decent accuracy if you scale y properly.. Problem is when Y is scaled, when it's non perpendicular to the laser plane, because it assumes depth is constant as a flat check board calibration would be the measurement can become distorted... All improvements that can be made by someone who is a non-hobbyist :)
5 years ago
Hello, thank you for publishing this project. I wanted to ask you if you could suggest a book where I can learn more about the concepts you have described in this wonderful project.
Thank you
Reply 5 years ago
I found documentation on this very difficult to find. I wrote this tutorial because I wanted to add what I could to help those trying to learn.
6 years ago
Hi John, I am having some project in university about building microscope and optical instrument. Now that we have further goal to make a whole system using 3D scanner Structured light, Laser depth scanning. Can you send me more detail about your files? Wish I can more contact with you:") thanks.
Call me Hacker, thanks. hacker0722@gmail.com
Reply 5 years ago
Offical publication:
https://www.researchgate.net/publication/321668948...
My friend was able to get my project published!
Reply 6 years ago
I sent you an email
Reply 6 years ago
thanks for your reply
6 years ago
Hello John.
Great job! really inspired me.
I am doing a graduation project. İt is 3D foot laser scanner.And i need your help. Can you send me the specific documents on your 3D scanner. I would be very grateful. Thanks!
mail; jakhongir.mamadov@gmail.com
Reply 5 years ago
Offical publication:
https://www.researchgate.net/publication/321668948...
6 years ago
Hello, how are you? I am doing a similar project in the university and I would serve yours as a reference, if you are kind enough to send me the documents to my email byronkuzco@hotmail.com. Thank you
Reply 5 years ago
Offical publication:
https://www.researchgate.net/publication/321668948...