Log in

View Full Version : Problem with distance calculation


Dan252
05-02-2014, 04:37
Hey,
We are using RoboRealm for vision processing this year but we are having problems with the distance calculation.

This is the code we have as of now: (the output distances are way off)


def IsVertical(n):
return rr.GetArrayVariable("WIDTH")[n] < rr.GetArrayVariable("HEIGHT")[n]
width = 0
if IsVertical(i):
width = VtargetWidth_in
Hot[i] = False
else:
width = VtargetWidth_in
distance = width/(2*math.tan(cameraFieldOfView*(rr.GetArrayVariable ("WIDTH")[i]/rr.GetVariable("IMAGE_WIDTH"))*math.pi/360.0))

[written in python]

Another one tried (better results, but still atleast 3ft errors): [this is only for vertical targets]

if IsVertical(i):
d = VtargetRheight_in*imageHeight_px / (2*math.tan(cameraFieldOfView*math.pi/360.0)*rr.GetArrayVariable("HEIGHT")[i])


Any help would be welcome! :confused:

Alan Anderson
05-02-2014, 08:22
Is the number for the camera field of view set correctly?

Dan252
05-02-2014, 08:45
Is the number for the camera field of view set correctly?
Yes, it is 47 degrees.

We are using the labview sample images though (with the real distance in their filename) and I'm not entirely sure what camera they used but we tried all of the fov angle options and still had no luck getting close enough results

Jerry Ballard
05-02-2014, 16:22
Hey,
We are using RoboRealm for vision processing this year but we are having problems with the distance calculation.

This is the code we have as of now: (the output distances are way off)


def IsVertical(n):
return rr.GetArrayVariable("WIDTH")[n] < rr.GetArrayVariable("HEIGHT")[n]
width = 0
if IsVertical(i):
width = VtargetWidth_in
Hot[i] = False
else:
width = VtargetWidth_in
distance = width/(2*math.tan(cameraFieldOfView*(rr.GetArrayVariable ("WIDTH")[i]/rr.GetVariable("IMAGE_WIDTH"))*math.pi/360.0))

[written in python]

Another one tried (better results, but still atleast 3ft errors): [this is only for vertical targets]

if IsVertical(i):
d = VtargetRheight_in*imageHeight_px / (2*math.tan(cameraFieldOfView*math.pi/360.0)*rr.GetArrayVariable("HEIGHT")[i])


Any help would be welcome! :confused:


I'm not sure I understand all your variable names, but here's one way to do it

distance = ( targ_width_in / 2.0 ) / tan( 0.01745 * ( ( ( targ_width_pixels / cam_width_pixels) * cam_fov_deg ) / 2.0 ) ) ;

The 0.01745 is the degree to radian conversion. With typically only 640 or 720 horizontal pixels, additional precision isn't required.

If you precompute the individual camera pixel field of view (IFOV = cam_horizontal_fov / cam_horizontal_pixels), then it is a bit more easier to read:

distance = (target_width_in / 2.0 ) / tan( 0.01745 * (IFOV * target_width_pixels / 2.0 ));

The IFOV * target_width_pixels provides the angular width of the target.

Hope this helps.