Introduction: DIY 3D Scanner Based on Structured Light and Stereo Vision in Python Language
This 3D scanner was made using low cost conventional items like video projector and webcams. A structured-light 3D scanner is a 3D scanning device for measuring the three-dimensional shape of an object using projected light patterns and a camera system. Software was developed based on structured light and stereo vision with python language.
Projecting a narrow band of light onto a three-dimensional shaped surface produces a line of illumination that appears distorted from other perspectives than that of the projector, and can be used for an exact geometric reconstruction of the surface shape. Horizontal and vertical light bands are projected on object surface and then captured by two webcams.
Step 1: Introduction
Automatic 3D acquisition devices (often called 3D scanners) allow to build highly accurate models of real 3D objects in a cost- and time-effective manner. We have experimented this technology in scanning a toy to prove performance. Specific needs are: medium-high accuracy, easy of use, affordable cost of the scanning device, self-registered acquisition of shape and color data, and finally operational safety for both the operator and the scanned objects. According to these requirements, we designed a low-cost 3D scanner based on structured light which adopts a versatile colored stripe pattern approach. We present the scanner architecture, the software technologies adopted, and the first results of its use in a project regarding the 3D acquisition of a toy.
In the design of our low-cost scanner, we chose to implement the emitter unit by using a video projector. The reason was the flexibility of this device(which allows to experiment any type of light pattern) and its wide availability. The sensor can be either a custom device, a standard digital still camera or a webcam. it must support high quality color capture (i.e. acquisition of high dynamic range) and possibly with high resolution.
Step 2: Software
Python language was used for programming for three reasons, one it is easy to learn and implement, two we can use OPENCV for image related routines and three it is portable among different operating system so you can use this program in windows, MAC and Linux. You can also configure the software to use with any kind of camera (webcams, SLRs or industrial cameras) or projector with native 1024X768 resolution. It is better to use cameras with more than two times resolution. I personally tested the performance in three different configuration, first one was with two parallel Microsoft webcam cinema and a small portable projector, second one was with two lifecam cinema webcameras that rotated 15 degrees toward each other and Infocus projector, last configuration was with logitech webcameras and Infocus projector. To capture point cloud of object surface we should go trough five steps:
1. Projecting gray patterns and capturing images from two cameras "SL3DS1.projcapt.py"
2. Processing the 42 images of each camera and capture points codes " SL3DS2.procimages.py"
2. Adjusting threshold to select masking for areas to be processed "SL3DS3.adjustthresh.py"
4. Find and save similar points in each camera "SL3DS4.calcpxpy.py"
5 Calculate X,Y and Z coordinates of point cloud "SL3DS5.calcxyz.py"
The output is a PLY file with coordinate and color information of points on object surface. You can open PLY files with CAD software like Autodesk products or an open source sofware like Meshlab.
http://www.autodesk.com/products/personal-design-a...
Python 2.7, OPENCV module and NUMPY should be installed to run these Python programs. I have also developed a GUI for this software in TKINTER that you can find in step six with two sample data sets . You can find additional information on this subject on the following websites:
http://docs.opencv.org/modules/calib3d/doc/camera_...
http://docs.opencv.org/modules/highgui/doc/reading...
http://www.3dunderworld.org/software/
http://arxiv.org/pdf/1406.6595v1.pdf
http://mesh.brown.edu/byo3d/index.html
Step 3: Hardware Setup
Hardware consists of :
1. Two webcameras (Logitech C920C)
2. Infocus LP330 projector
3. Camera and projector stand (made from 3 mm Acrylic plates and 6 mm HDF wood cut with a laser cutter)
Two cameras and projector should be connected to a computer with two video output like a notebook computer and the projector screen should be configured as an extension to main windows desktop. Here you can see images of cameras, projector and stand. The drawing file ready for cut are attached in SVG format.
The projector is an Infocus LP330 (Native resolution 1024X768) with following specs.
Brightness:650 Lumens Color Light Output:**Contrast (Full On/Off):400:1 Auto Iris:No Native Resolution:1024x768 Aspect Ratio:4:3 (XGA) Video Modes:**Data Modes:MAX 1024x768 Max Power:200 Watts Voltage:100V - 240V Size(cm) (HxWxD):6 x 22 x 25 Weight:2.2 kg Lamp Life(Full Power):1,000 hours Lamp Type:UHPLamp Wattage:120 Watts Lamp Quantity:1 Display Type:2 cm DLP (1) Standard Zoom Lens:1.25:1 Focus:Manual Throw Dist (m): 1.5 - 30.5 Image Size(cm):76 - 1971
This video projector is used to project structured light patterns on the object to be scanned. The structured pattern consists of vertical and horizontal white light strips that are saved on a data file and webcams capture those distorted strips.
Preferably use those cameras that are software controllable because you need to adjust focus, brightness, resolution and image quality. It is possible to use DSLR cameras with SDKs that are provided by each brand.
Assembly and tests were conducted in Copenhagen Fablab with its support.
Attachments
Step 4: Experimenting With Scanner
For testing the system a fish toy was used and you can see the captured image. All captured file and also the output point cloud is included in attached file,
you can open the PLY point cloud file with Meshlab:
Attachments
Step 5: Some Other Scan Results
Here you can see some human face scans and 3d scan of a wall. There are always some outlier points due to reflections or inaccurate image results.
Step 6: 3D Scanner GUI
For testing the 3d scan software in this step I add two data sets one is scan of a fish and another is just a plane wall to see the accuracy of it. Open ZIP files and run SL3DGUI.py. For installation check step 2. Send message to my inbox here for all source codes.
For using 3d scan part you need to install two cameras and projector but for other parts just click on the button. For testing the sample data first click on process then threshold, stereo match and finally point cloud. Install Meshlab to see the point cloud.

Participated in the
Automation Contest
38 Comments
Tip 2 years ago
Question 2 years ago
Now I am studying your code,but I don't know how to make a binary black and white image in this
old_settings = np.seterr(all='ignore') #set to ignore float pt errors
img1 = cv2.imread(img1, cv2.IMREAD_GRAYSCALE)
img2 = cv2.imread(img2, cv2.IMREAD_GRAYSCALE)
ret1,thr1 = cv2.threshold(img1, 10, 255, cv2.THRESH_TOZERO)
ret2,thr2 = cv2.threshold(img2, 10, 255, cv2.THRESH_TOZERO)
thresholdImg = (((thr1 // 2) + (thr2 // 2)))
afterImg = (np.divide(thr1, thresholdImg))
afterImg = np.nan_to_num(afterImg)
finalImg = (np.divide(afterImg, afterImg))
finalImg = np.nan_to_num(finalImg)
Could you please help me? Thank you
2 years ago
Hi,
How do i get the source codes that u have mentioned please
3 years ago
I think this is the source of this project:
https://github.com/CMU-dFabLab/CFA-CreativityFund?files=1
Reply 3 years ago
That source seems to have all the files (and more) except for the GUI mentioned in steps 2 and 6 from the file SL3DGUI.py
Question 3 years ago
I am also hoping to get this Python source code. Has anyone had any luck on where to find it?
4 years ago on Step 6
1.) Which Linux platform will work best?
2.) Are the cameras usb?
3.) Projector connected to hdmi?
Reply 3 years ago
Hi.
1. I used windows 7
2. Used two webcam
3. On vga output
3 years ago
Hi,
How do i get the source codes that u have mentioned
3 years ago on Step 6
hi hesamh
could i download this source code to still? If possible please send to me.
i hope get this source code.
Question 4 years ago on Step 1
You mention several Python files. Can I download these somewhere?
Question 4 years ago on Step 2
Have you taken the python code down, i cant find it on this website? =(
7 years ago
Hi hesamh,
I used your code to make a home made small scanner. It is a very good code. I did some modifications to run it faster. If you want I can share the code with you or if you have it on GitHub I can send it you there.
Best regards,
bdvd
Reply 4 years ago
Hi bdvd,
I have a strong interest in this project, can I get your code, thank you.
lchj
Reply 7 years ago
Hi, can you send the code link to me?
Reply 7 years ago
Hello bdvd,
I was planning to make something similar using hesamh's code. Could you please help me out by providing your code too? It would be very grateful.
Thank you,
Best Regards,
Shreyas
Question 5 years ago on Step 1
have you considered/tried using a turntable for the object to cover it in its entirety?
6 years ago
Hi, hesamh
Thanks for sharing.
In the step 2, you say that it is better to use cameras with more than two times resolution.
How did you get this result?
What are you comparing?
Best regards.
Peter
6 years ago
I am currently
comparing photographic, laser and structured light methods of producing point
clouds. Please can you explain the advantage of using your method over
automatic image correlation as two cameras are being used to give a stereo
view? Is it more difficult to match the imaged texture of the object than the
stripes?
Reply 6 years ago
By projecting patterns we produce feature point to make correlation accurate