View Single Post
  Spotlight this post!  
Unread 11-04-2016, 16:29
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: Angle Calculation from image of goal

Quote:
Originally Posted by TheOtherGuy View Post
For example, if the camera is 90° horizontal FoV and the resolution is 640 horizontally, then a simple equation would be

angle = (goalx - 640/2) * 90/640
This can be a decent enough approximation, but there is a more correct way to do this conversion:

Code:
horizontal_angle_to_goal = atan((goal_x - center_x) / focal_length_pixels)

where:
focal_length_pixels = 
.5 * image_width_pixels / tan(horizontal_field_of_view / 2)
The idea of a focal length is a little unintuitive at first, but is explained here: https://en.wikipedia.org/wiki/Angle_of_view

Typically, unless you calibrated your camera to compensate for manufacturing imperfections (total overkill for FRC):
Code:
center_x = (image_width_pixels / 2 - .5)
The -.5 compensates for the fact that if there are an even number of columns/rows in your image, the center is actually on the border between two of them (and we start counting rows/cols from 0 typically).

Note that these equations do give slightly different answers! (See attached image...red is the correct equation, blue is the approximate linear one)

Also note that this angle is relative to the camera...you need to whip out some more trig depending on the angle of the camera mount relative to its robot.
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2016-04-11 at 1.31.15 PM.png
Views:	250
Size:	52.5 KB
ID:	20578  
Reply With Quote