# 2D Room Mapping With A Laser And A Webcam

[Shane Ormonde] recently learned how to measure distance using just a webcam, a laser, and everyone’s favorite math — trigonometry. Since then he’s thrown the device onto a stepper motor, and now has a clever 2D room mapping machine.

He learned how to create the webcam laser range finder from [Todd Danko], a project we featured 7 years ago! It’s a pretty simple concept. The camera and laser are placed parallel to each other at a known distance, axis-to-axis. On the computer, a python script (using the OpenCV library) searches the image for the brightest point (the laser). The closer the brightest point is to the center of the image, the farther the object. Counting pixels from the center of the image to the laser point allows you to calculate an angle, which can then be used to calculate the distance to the object — of course, this needs to be calibrated to be at all accurate. [Shane] does a great job explaining all of this in one of his past posts, building the webcam laser rangefinder.

From there it was just a matter of slapping the rangefinder onto a stepper motor, driving it with a small PIC, and running the calculations on the fly! His results are fairly impressive.

## 20 thoughts on “2D Room Mapping With A Laser And A Webcam”

1. T0x1c says:

You could add a dispersion lens to increase the dot size, this might yield greater resolution.

2. We’re all watching the red dot travelling along a wall in the dark. Congratulations Sir ! I am now officially a Cat !

1. lageos says:

3. Try replacing the laser pointer optics with line optics (or use a cheap laser level tool from economy hardware store). This will make a vertical line instead of a dot.
Now you can use your code to check all the pixels in an entire vertical stripe instead of a single dot. and get a lot more vertical res.

For fun and entertainment – the IR filter on your webcam could be removed but you could add a green laser instead – also shot through same optics (or directly adjacent to red line, or in same position but switched on and off on alternate frame times).
Or a blue laser or whatever – the point being that surfaces that don’t reflect red well might reflect another colour better.

Great work. and in Python too. Yay Python !

1. Thanks a lot man! Good ideas. I’ll definitely try out a vertical line instead of a dot when I get a chance.

1. Andrew says:

To get a line, shine the laser through a glass or plastic rod. For a quick test, use the stem of a wine glass.

4. justice099 says:

One step closer to those little balls in Prometheus that map out the caves.

The next step should be a script for Sketchup that builds the room from the data.

1. Using Sketchup is a great idea! Could mount it on a robot and map out buildings, like in Prometheus but less cool

2. Leithoa says:

There’s a bunch of n-Copters and wheeled vehicles that do this task. Sebastian Thrun made an ATV that maps derelict mines. the Simultaneous Location And Mapping(SLAM) problem has quite a following and decent funding as of late.

5. ftkalcevic says:

I did this with a atxmega and TSL1401-DB Linescan Camera Module. I’ve gotten over 500 measurements per second. The limiting factor is the scanners light sensitivity.

6. justice099 says:

I have always had this idea of some type of system that simply senses its surroundings. Have you ever noticed that you can feel when something is behind you? Even things you can’t see, you have a sense (as inaccurate as it is) of your surroundings. If you walk in the dark, you can sense that you are coming upon a wall. Or when someone is standing behind you suddenly.

The effect I think is changes in air pressure. Like the Archimede’s principle. Air is a fluid, and anything within it will displace it which creates a directional force. I believe we can sense this pressure change on our skin.

I haven’t quite figured out how to build something like this, but in my head I forsee something similar to an arrangement of speakers used as microphones. Obviously that should be able to sense pressure changes due to a disturbance in the fluid air, but if the measurement device is stationary and the objects in the room are stationary, it seems like it would measure nothing.

Don’t laugh, but I’ve always named it acoustical mass displacement sensing.

Any thoughts on this?

1. justice099 says:

Incomplete thought. In order to sense things, one of the parts in the system will have to move. I wonder if simply vibrating the sensing instrument (and then filtering that vibration out) would be enough.

7. the gambler says:

“NSA caught snooping on building mapping robots”

8. vonskippy says:

It’d be cooler if he used a laser and a shark.

9. Matthew says:

I’d like to point out another cool hack in this picture: The use of zip ties and metal scrap to prevent a pair of helping hands from tipping over. Why didn’t I think of that?

1. Agreed! It’s the little things that make all the difference. My magic hands, before and after:

10. Jrd says:

Very cool!
And good idea with the verical line,eventualy,you may end up with the kinect:-)

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.