Distance Measurements to Target

Hi, we are currently using the Microsoft Lifecam-3000 with a raspberry pi for vision tracking and distance measurements. We can find the pixel height of the bounding box of the two vision rectangles and are inputting it into the equation:

distance: 0.83 (actual height of bounding box (ft)) * 480 (y-pixel resolution) / 2 * pixelHeight * tan( 14.9 (vertical view angle in degrees) )

When testing this formula, we have found that distance measurements are within 2-3 in. when the target is 2-4 m. away; however, from 1- 2 m, the error is around 10 in. We were wondering if there is anyway to prevent this, or if there is another, more-robust method to calculate the distance to the target.

https://acroname.com/products/r93-srf04?sku=R93-SRF04

This is an ultrasonic distance sensor. It is great for this application

The easy method using the camera is an empirical curve.

That is, position the robot at a series of measured distances from the vision target, take pictures and measure the vertical height. Then, use you measured height during the match and interpolate into the curve you measured.

It will likely require re-measurement if you move the camera to a different location.

The distance estimation based on the optics of the camera is only valid if the camera sensor and the object you are measuring are in the same plane. When you tilt the camera up or down, you are introducing a perspective distortion dependent on the Y value where the size was measured.

This is a somewhat new wrinkle to FRC vision, as we have short robots and tall targets this year.

It is possible to calibrate this out of the system, and that was why the LV example had reference to a calibration file and a step to load it so that NIImaq could correct the distance with this info. But there are other approaches that will work as well.

Essentially, a 10px distance at the bottom of the camera image, in the middle, and at the top of the camera image are not supposed to give the same real-world distance estimate. I’d suggest making some empirical measurements and seeing how you can normalize this. Or look at the perspective distortion transform and figure out how to invert it (might not want to do this to all the pixels, however), or use some training utility.

With any of these, it is key to keep the camera height and angle pretty consistent or come up with a way to compensate based on some field element also in the image.

Greg McKaskle

First I would recommend doing the calculations found here in order to convert your pixels to actual angles, as the relationship between pixels and angles is not exactly linear.

From there what we did is we calculated the vertical angle taken up by the target and found this angle at various distances in .5 foot increments and using Excel found a curve that fit our points very well. This has worked extremely well and using the curve of best fit we are now able to measure distance to the target with less than an inch of error.

We had this problem too with our vision measurements. We solved it by adjusting the viewing angle in our algorithm.

Take measurements from varying distances and plot them on a graph (actual distance on x axis, measured distance of y axis). It should be fairly linear. Find the slope of the line. Our slope was about 0.91.

tan(theta)/tan(current viewing angle) = slope

Theta is the viewing angle you should use in your algorithm.

After calibrating the viewing angle, our measurements are consistently with in 1-3 inches of the actual distance. I hope this works for you too!