zondag 23 januari 2011

Building a 3D scanner part 1

An idea that has been floating around in my head for a while after I graduated is to build a 3D scanner. Mainly because I know how to make one and because it will make for some very interesting blog posts, but also because it will allow me to import objects from the real world into 3D games. Now you might think that something like a 3D scanner needs a whole array of gizmos and doodads, but the principle is surprisingly simple. All you really need is a camera, a line laser and some way to move either the laser or the object to be scanned. Oh, and of course software to calculate the coordinates of the object from the camera images. This image from Wikipedia sums it up pretty nicely.


In the image you can see that there is an angle between the camera and the line laser. This way the further a point on the object is away from the camera, the further to the right the laser line will appear on that point. So the software can analyze each horizontal line of the image and calculate on which pixel position the laser line appears. Note that right will become left if the camera and laser are swapped. Also be aware that this setup with the camera and the line laser is just one way to make a 3D scan of an object, there exist other methods as well such as using two cameras right next to each other and comparing the two images they produce.

So now we know that there is some way to calculate the position on the object where the laser line intersects it by analyzing an image from the camera. I think that the simplest way to calculate the position on the object is to view the line laser as a mathematical (infinite) plane, the pixels on the image of the camera as mathematical rays and calculating the intersection point between the two.

The plane equation in algebraic form is:

         n ∙ p - d = 0

Where:
-          n is the normal of the plane facing away from the center of the coordinate system.
-          p is a point on the plane.
-          d is the smallest distance from the center of the coordinate system to the plane.


The ray equation is:

         pt = u t + p0

Where:
-          pt is the position on the ray at distance t.
-          u is the (normalized) direction the ray is traveling in.
-          t is the distance from the starting point.
-          p0 is the starting point of the ray.

So we solve p = pt by substituting the ray equation in the plane equation and solving for t.

         t = ( dp0 ∙ n ) / ( u ∙ n )

t can then be inserted in the ray equation to obtain the actual intersection point.

So now that we know that how to calculate the intersection point the problem becomes finding out all the values in those equations. The values of the plane equation isn’t such a problem, you can just throw some high school trigonometry at it and calculate the values of d and the components of the plane normal. This is all assuming that you choose the center of the rotating platform in the image of the duck to be the center of the coordinate system. The real challenge lies with the ray equations, or the camera really. The starting position of the rays lie in the center of the lens of the camera and measuring this is rather tricky. Maybe you could get away with a slightly inaccurate position since it only appears once in the total calculation of the intersection point. The direction of the ray however appears twice. Once in the calculation of t and once when inserting t into the ray equation. So we accurately need to know the direction of the ray that each pixel corresponds to. To do that we need to calibrate the camera, also known as camera resectioning, so we know its geometrical properties that transforms a point from 3D Euclidian space to image space. This is what my next blog post will be about. After that I will describe how to build the setup required for the 3D scanner and after that how the software works and processes the images from the camera. Lastly I will test the accuracy and precision of the scanner.


Geen opmerkingen:

Een reactie posten