Determining distance with laser and camera

140 Views Asked by At

I'm designing a device that measures distance using a laser and a camera. The device has the camera and laser separated by 100mm and they both point in the exact same direction. This is done so the camera can determine how far an object is depending on the distance between the center of the camera and the laser light is. So if the device is pointing towards a far object the light from the laser is closer to the center of the camera but on the contrary, if the object is very close, the distance between the laser light and the center is about 100mm. In my head it seems possible but how would I do this?

I was thinking of posting this to StackOverflow but I decided this was more of a math question rather than a code question.

Edit: I found a video of this method being used here.

2

There are 2 best solutions below

4
On

See this Wikipedia page about the pinhole camera model.

Assuming that the central target point of the camera and the point $P$ projected by the laser beam lay on a plane parallel to the image plane, you have a situation like in the picture:

enter image description here

You want to compute $x_3$ based on $y_1$, the distance from the center on the image, $f$ the focal length, and $x_1$, the distance between the laser light and the camera aperture $O$:

$$x_3=\frac{f}{y_1}x_1$$

In practice, you don't have $y_1$ on the image sensor but a distance in pixels, so you need to compute a value of $f$ adapted to your image file and you can compute it through a calibration at a known distance $x_{3c}$:

$$f=x_{3c}\frac{y_{1c}}{x_1}$$

You will have errors due to the target not on a plane perfectly parallel to the image plane, $X3$ axis not perfectly parallel to the laser beam, and radial distortion.

2
On

The thin lens formulae are fairly simple. Depending on your camera, the lens may be rather complex and they may not work for you. You can consider the object to be a line segment from the center of the frame to the laser spot, so the size of the object is $100$ mm

We define
$d_o$ as the distance from the lens to the object. This is what you are trying to measure
$d_i$ as the distance from the lens to the image
$f$ as the focal length of the lens
$s_o$ as the size of the object. You have said this is $100$ mm
$s_i$ as the size of the image.
You want to measure all the variables in the same units, presumably mm.

The formulas are $$\frac 1f=\frac 1{d_o}+\frac 1{d_i}\\ \frac {s_o}{d_o}=\frac {s_i}{d_i}$$ You measure $s_i$, which is the distance on your image plane from the center to the laser spot. You will have to convert the number of pixels to mm based on the characteristics of your sensor. You know $s_o$, which I will leave as a variable in case you change it sometime. Then $$\frac{s_i}{s_o}=\frac {d_i}{d_o}\\ d_i=\frac {s_id_o}{s_o}\\ \frac 1f=\frac 1{d_o}+\frac {s_o}{s_id_o}=\frac 1{d_o}\left(1+\frac {s_o}{s_i}\right)\\ d_o=f\left(1+\frac {s_o}{s_i}\right)$$ It will be crucial to have the lens aligned so its center is the correct distance from the laser spot. Given that, you will get best accuracy if the focal length is chosen so the laser spot is barely in the frame.