Go to Post I've come to the conclusion that the only way Pat's awesomeness can be explained is.... Pat Fairbank is a cookie. - Jonathan Norris [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 05-02-2014, 04:37
Dan252 Dan252 is offline
Registered User
FRC #3075 (HaDream Team #3075)
Team Role: Programmer
 
Join Date: Oct 2013
Rookie Year: 2011
Location: Israel
Posts: 12
Dan252 is on a distinguished road
Problem with distance calculation

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)

Code:
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]
Code:
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!

Last edited by Dan252 : 05-02-2014 at 13:13.
  #2   Spotlight this post!  
Unread 05-02-2014, 08:22
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Problem with distance calculation

Is the number for the camera field of view set correctly?
  #3   Spotlight this post!  
Unread 05-02-2014, 08:45
Dan252 Dan252 is offline
Registered User
FRC #3075 (HaDream Team #3075)
Team Role: Programmer
 
Join Date: Oct 2013
Rookie Year: 2011
Location: Israel
Posts: 12
Dan252 is on a distinguished road
Re: Problem with distance calculation

Quote:
Originally Posted by Alan Anderson View Post
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
  #4   Spotlight this post!  
Unread 05-02-2014, 16:22
Jerry Ballard's Avatar
Jerry Ballard Jerry Ballard is offline
Registered User
AKA: Jerry Ballard
FRC #0456 (Siege Robotics)
Team Role: Mentor
 
Join Date: Dec 2012
Rookie Year: 2011
Location: Vicksburg, MS, USA
Posts: 13
Jerry Ballard is a jewel in the roughJerry Ballard is a jewel in the roughJerry Ballard is a jewel in the rough
Re: Problem with distance calculation

Quote:
Originally Posted by Dan252 View Post
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)

Code:
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]
Code:
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!

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.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 02:35.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi