# Sub-Pixel Laser Line Detection

A project log for ImportWorld

A 3D scanner project

This post will describe the method I use to detect the center of the laser line for each row in the image. We can divide the process into two steps:

1. Capturing an image of the laser line
2. Calculating the center of the laser line.

## Capturing an image of the laser line

The basic idea for capturing an image of the laser line is to take two images of the object, one image will have the laser turned off and the other one will have the laser turned on. If these images are taken in a short time span the the difference between them should only be the laser line. For this to work a background with no movement is required, otherwise the movement will show up in the final image. The images are also captured in greyscale for easier computing.

## Calculating the center of the laser line

The center of the laser line can be approximated with sub-pixel accuracy by using the method for calculating the weighted mean, this works since the intensity of the laser line will be highest at the middle and lower at the edges as illustrated here:

By giving each pixel a number based on the number of pixel distance from the left side of the image. The first pixel will be 0, the second 1, third 2 and so on. Each pixel will also have an intensity value from 0 to 255 that will be used as the weights. The following equation can then be used to approximate distance from the left side to the center of the laser line:

We then calculate this for each row of the image and store it in a vector so that we can use it to triangulate the position i 3D space.

There are some downsides to this method and that is that the timing between the camera and the lasers needs to be quite good to not miss the laser line. My solution for this is to wait a couple of frames before capturing the images.

-- FilleK