MATLAB Answers


Webcam Based Laser Rangefinder

Asked by Yogesh
on 19 Sep 2013
Latest activity Answered by ravi
on 20 Feb 2014
laser-beam is projected onto an object in the field of view of a camera. This laser beam is ideally parallel to the optical axis of the camera. The dot from the laser is captured along with the rest of the scene by the camera. A simple algorithm is run over the image looking for the brightest pixels. Assuming that the laser is the brightest area of the scene the dots position in the image frame is known. Then we need to calculate the range to the object based on where along the y axis of the image this laser dot falls. The closer to the center of the image, the farther away the object is D = h /tan (theta) where thefa = pfc * rpc + ro .

can anybody help me regarding this project?


on 25 Sep 2013

Simply put, you will need to determine the change in radius of the beam vs distance in order to build an algorithm for finding your z dimension. Keep in mind that the resolution of the webcam will most likely be the limiting factor for measurement. You may want to find the brightest pixels and attempt to build a square and with side length L where the center is L/sqrt(2) from the corner ( giving a radius for a circle estimate since you are working in square pixels) To the best of my knowledge MATLAB doesnt have a built in method for (x,y) -> (x,y,z) as you are asking for. Best of luck

on 26 Sep 2013

I had tried lots of time but not getting and I am very confused now can u please mail the code at

What is your current algorithm, taking into account the hint I gave you ?


No products are associated with this question.

2 Answers

Answer by Walter Roberson
on 25 Sep 2013

regionprops() can give you the equivalent-radius of a blob. But the actual radius is constant. So now what you need to consider is this: if you have two line segements of the same length, and one is N times further away than the other, then how will the angular size of the two line segments differ?

Hint: the spreading angle from the center of the beam (center of the optical axis) does not change with distance.


Answer by ravi
on 20 Feb 2014

this code is a part of rangefinder


hope this will help good luck


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!