Eduan du Plessis
Posts: 3
Joined: Thu Apr 11, 2019 6:01 pm

How to measure distance with the raspberry pi camera

Sun Jun 09, 2019 3:39 pm

Hi, I want to measure long distance with a sensor, the ultrasonic sensor will not work because I want to measure distances longer than 10 meters. Does anybody know how to do this?

Posts: 7719
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: How to measure distance with the raspberry pi camera

Sun Jun 09, 2019 4:10 pm

How to measure distance with the raspberry pi camera

The Raspberry Pi Foundation camera module has a fixed focal length and a fixed point of focus. I can't think of any trivial way of using it to directly measure distance.

Perhaps you could work backwards by measuring the width of the field of view?

Posts: 2864
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: How to measure distance with the raspberry pi camera

Sun Jun 09, 2019 4:49 pm

Depth of field measuring is a major pain and can be erratic at best. Even using two in controlled situations can have some level of error that you may find unacceptable - have a look at this paper from 2017

Some ultrasonic modules (e.g. this one) can reach about 1m depending on the weather BUT thats about as far as I would trust them. Ultrasonic ones are very very dependant on weather / atmosphere conditions - I've been looking at wind speed / direction detection using them recently - but not yet tried it.

You can use laser range finder / LIDAR modules (see this tear down) but these can be very expensive outside pre-built units. Even the pre-built ones are not cheap - $130 for 40m

When you say 'long distance' how far do you mean? I've seen lasers bounce from the moon (mind blowing to say the least) and planet distance estimates done by 'hobby' astronomers - can you describe your use case a bit more please.
Need Pi spray - these things are breeding in my house...

Posts: 152
Joined: Fri Jan 25, 2013 1:55 pm

Re: How to measure distance with the raspberry pi camera

Wed Jun 12, 2019 9:45 am

It is possible to measure the distance to a target approximately using the camera, if you have a calibration sign attached to the target and use machine vision to identify it and measure the angular size.

I have done this. It won't work for a unlabelled target whose size isn't known precisely ahead of time.

So you can attach a large, high-contrast marker sign to the target and take high resolution photos using the camera. This works at any distance, provided the sign is large enough (obviously at some point the sign would become prohibitively large).

Obviously this method also has caveats, it won't work if there isn't enough light, fog, etc.

If that's not what you wanted, the laser time of flight sensors VL531X can measure distances to essentially any object, under the right conditions, to about 4 metres, they work best in the dark, and work particularly badly outdoors on a sunny day. Mouser have breakout boards.

Posts: 153
Joined: Mon Jan 26, 2015 5:56 pm
Location: Florida, USA

Re: How to measure distance with the raspberry pi camera

Thu Jun 13, 2019 7:02 pm

For a PiCamera fixed to a bot with a fixed/known pointing angle, the distance to the bottom line of the image is a known, fixed number.

I have a PiCam v1.3 on my bot:
5MP 1080p30 2592 x 1944 pixels
35mm focal length equiv.
focus 1 m to inf.
H 53 deg x V 41 deg
(Use 1296 x 976 and 2x2 binning for better low light SNR)

Let's use 2 feet at 30 degrees from horizontal as the lowest/closest visible point at the center of the bottom of the image, and the camera mounted 6" off the floor, with a fictional image size of 410 pixels. Each 10 pixels above the bottom of the image is one degree less angle with two known angles (for triangle with x,y,h sides - angle y-h and 90 degree angle x-y.) With two angles and the included side y=6", we learned in school how to compute that, but I don't remember how, only that it was possible when I was a teenager!

Today we use the internet: ... ngles.html

Return to “Automation, sensing and robotics”