DEV Community

Animesh Srivastava
Animesh Srivastava

Posted on

An Open Source 3-D Scanner


This project is about developing the hardware and the software for a 3D Scanner. The purpose of this project is to generate a 3D image of an object using a 2D camera, which could be opened and edited with a Third Party software like Blender or Meshlab. Two lasers have been deployed in the setup. At the centre, there is a platform where the object has to be kept for the purpose of scanning. The platform is rotated in steps by a stepper motor controlled by the software through a microcontroller. A line laser is used to set the reference axis for the camera and the other line laser is projected on the object in such a way that the beam takes the outline of the edge of the object. The code extracts only the contours of the laser beam and saves the coordinates for all the points in that contour and another piece of code integrates all the points into a single 3D image. For the convenience of the user, a complete GUI application has been developed. Although there are many technologies present for 3D Scanning, most of them use expensive hardware and software. Since the technologies used in the project are completely free and Open Source, the only cost of the project is due to its hardware. All efforts have been made to keep the project as affordable as possible and the User Interface as easy as possible.


1.Image Capture

The set up requires two laser modules to be oriented in such a way that one helps to determine the reference of the axis (L1) and the other laser (L2) allows the camera to capture edges of the object (to be scanned) being intensified by it(L2). The laser(L2) is set at an angle of about 40-45 degrees with respect to L1. The laser (L2) throws a vertical beam of red light on the object and the camera detects it. Since the light falls on the object from an angle, it takes the outline of the object. This helps to extract the outer outline of the object from each frame. The setup is so designed to rotate a total of 360⁰ in 48 steps and capture 48 such frames in total. All the frames that are captured are in 2D format.

2.Extraction of contours formed by the incident laser

The frame detected by the image is then processed using OpenCV in order to extract only those contours (regions) which come under the incident Laser beam, leaving other parts of the frame totally black (R=0, G=0, B=0). The frames are numbered from 0 to 47 and saved as ‘.png’ files. But, the most important thing that we require from those processed frames is the coordinates of the points that make the contour. Hence, the coordinates are stored in ‘.txt’ files numbered from 0 to 47.

3.Conversion of 2D coordinates to Spherical coordinates

This conversion requires the values of Radius (‘R’), Theta (‘Θ’) and Phi (‘ɸ’). It is so because the calculation of spherical coordinates of a point of the object is easy since we have the value of ɸ from the rotation of the stepper motor. The saved text files which contain the 2D coordinates of each frame are parsed to obtain X and Y coordinates of all the points associated with the contours and then used to calculate the values of (R, Θ,ɸ) of all the points collected during the 360⁰ rotation.

4.Formation of 3D object file (.ply)

Although the calculation of the coordinates in the spherical coordinate system is easy, finally the 3D format file contains the coordinates of the points in the Cartesian coordinate system. Hence the calculated (R,Θ,ɸ) coordinates are again converted to (X, Y, Z) coordinates. The coordinates so obtained are used to write a 3D image file. Polygon File Format (‘.ply’) is used to store the final 3D image data. These files can be used in various 3D image visualizing applications like Blender, which is also an Open Source Software. Various other 3D files can be created, for instance .obj, .stl, etc.

5.Plotting the 3D image

Either the final coordinates obtained can be used directly or the generated Polygon File Format(.ply) file can be used to display the 3D object. The function used for this purpose is the Matplotlib Scatter plot (a plotting library of Python). The Matplotlib window allows user to pan, tilt and zoom the obtained 3D image. Another application has also been developed which directly opens the created 3D file and displays it in a window. An available library ‘Trimesh’ was used to accomplish this.

Top comments (1)

tngeene profile image
Ted Ngeene

Is it available yet?