Go to Post To find something they are so passionate about that it oozes into everything they do, and others can't help but want to follow them into this Counter-Culture where good is not good enough, Great is all they strive for. - Kims Robot [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

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 02-04-2016, 16:57
simon-andrews's Avatar
simon-andrews simon-andrews is offline
Registered User
FRC #4761 (Robockets)
Team Role: Programmer
 
Join Date: Feb 2015
Rookie Year: 2015
Location: Reading, MA
Posts: 16
simon-andrews is an unknown quantity at this point
How can angle offset of a shooter be calculated from pixel offset?

My team's robot has a high goal shooter on a turntable. Using our vision system, I need to figure out how far off-target the shooter is in degrees. I've been working on this for most of today without much luck.

Things I know:
The camera is in the middle of the shooter.

I'm using OpenCV with Python, if that's useful.
__________________

GitHub | StackOverflow
Reply With Quote
  #2   Spotlight this post!  
Unread 02-04-2016, 17:01
Oblarg Oblarg is offline
Registered User
AKA: Eli Barnett
FRC #0449 (The Blair Robot Project)
Team Role: Mentor
 
Join Date: Mar 2009
Rookie Year: 2008
Location: Philadelphia, PA
Posts: 1,047
Oblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond repute
Re: How can angle offset of a shooter be calculated from pixel offset?

Quote:
Originally Posted by simon-andrews View Post
My team's robot has a high goal shooter on a turntable. Using our vision system, I need to figure out how far off-target the shooter is in degrees. I've been working on this for most of today without much luck.

Things I know:
The camera is in the middle of the shooter.

I'm using OpenCV with Python, if that's useful.
Pixel displacement should be strictly proportional to angular error, since the camera is effectively a point. To convince yourself of this, draw a picture of the shooter and the target (top view, camera at the origin).

Figure out the lateral FOV of the camera in degrees, and calculate proportional to that using the known width of the image in pixels.
__________________
"Mmmmm, chain grease and aluminum shavings..."
"The breakfast of champions!"

Member, FRC Team 449: 2007-2010
Drive Mechanics Lead, FRC Team 449: 2009-2010
Alumnus/Technical Mentor, FRC Team 449: 2010-Present
Lead Technical Mentor, FRC Team 4464: 2012-2015
Technical Mentor, FRC Team 5830: 2015-2016

Last edited by Oblarg : 02-04-2016 at 17:04.
Reply With Quote
  #3   Spotlight this post!  
Unread 02-04-2016, 17:03
lethc's Avatar
lethc lethc is offline
#gkccurse
AKA: Becker Lethcoe
FRC #1806 (S.W.A.T.)
Team Role: Alumni
 
Join Date: Nov 2012
Rookie Year: 2013
Location: Smithville, MO
Posts: 118
lethc will become famous soon enough
Re: How can angle offset of a shooter be calculated from pixel offset?

Quote:
Originally Posted by simon-andrews View Post
My team's robot has a high goal shooter on a turntable. Using our vision system, I need to figure out how far off-target the shooter is in degrees. I've been working on this for most of today without much luck.

Things I know:
The camera is in the middle of the shooter.

I'm using OpenCV with Python, if that's useful.
If your camera is mounted solidly then you should be able to interpolate the offset angle of your shooter by using the first option (how many pixels away from the middle the goal is). This isn't necessarily the best way to solve the problem but it works and it's really easy. Is that all you're asking?
__________________
2016: Greater Kansas City Regional Finalists, Oklahoma Regional Winners, Tesla Semifinalists, IRI Quarterfinalists
2015: Greater Kansas City Regional Finalists, Oklahoma Regional Winners, Tesla Quarterfinalists, IRI Winners
2014: Central Illinois Regional Quarterfinalists, Greater Kansas City Regional Finalists, Newton Semifinalists
2013: Greater Kansas City Regional Winners, Oklahoma Regional Winners, Galileo Quarterfinalists
Reply With Quote
  #4   Spotlight this post!  
Unread 02-04-2016, 18:56
kylelanman's Avatar
kylelanman kylelanman is offline
Programming Mentor
AKA: Kyle
FRC #2481 (Roboteers)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2007
Location: Tremont Il
Posts: 185
kylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to all
Re: How can angle offset of a shooter be calculated from pixel offset?

Screen steps live 2016 explains how to do this. https://wpilib.screenstepslive.com/s...ng-the-targets
__________________
"May the coms be with you"

Is this a "programming error" or a "programmer error"?

Reply With Quote
  #5   Spotlight this post!  
Unread 02-04-2016, 19:16
simon-andrews's Avatar
simon-andrews simon-andrews is offline
Registered User
FRC #4761 (Robockets)
Team Role: Programmer
 
Join Date: Feb 2015
Rookie Year: 2015
Location: Reading, MA
Posts: 16
simon-andrews is an unknown quantity at this point
Re: How can angle offset of a shooter be calculated from pixel offset?

Quote:
Originally Posted by Oblarg View Post
Pixel displacement should be strictly proportional to angular error, since the camera is effectively a point. To convince yourself of this, draw a picture of the shooter and the target (top view, camera at the origin).

Figure out the lateral FOV of the camera in degrees, and calculate proportional to that using the known width of the image in pixels.
Quote:
Originally Posted by lethc View Post
If your camera is mounted solidly then you should be able to interpolate the offset angle of your shooter by using the first option (how many pixels away from the middle the goal is). This isn't necessarily the best way to solve the problem but it works and it's really easy. Is that all you're asking?
Sorry, I worded my original post poorly and wasn't clear. This method actually is what I was doing originally, with this code:

Code:
def get_offsets(bb_leftside_x, bb_width, img_width):
	middle = bb_leftside_x + (bb_width / 2)
	pixel_offset = middle - img_width / 2
	angle_offset = pixel_offset * (26.5 / (img_width / 2)) # Raspberry Pi camera module FOV is 53 degrees
	ret = {
		"pixel_offset": pixel_offset,
		"angle_offset": angle_offset,
	}
	return ret
What I need to get is an angle that can be fed directly into the turntable as an amount to turn.

https://imgur.com/RelZro4
__________________

GitHub | StackOverflow
Reply With Quote
  #6   Spotlight this post!  
Unread 02-04-2016, 19:30
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: How can angle offset of a shooter be calculated from pixel offset?

You clearly calculate angle_offset right in that code...

Are you asking how to make a PID loop to turn the robot?
__________________
FRC Team 1684 - Head Programmer (2013-2016)
FRC Team 5460 - Programming Mentor (2015-2016)

FIRST in Michigan - Technical Crew (2015-continuing)
Reply With Quote
  #7   Spotlight this post!  
Unread 02-04-2016, 20:19
simon-andrews's Avatar
simon-andrews simon-andrews is offline
Registered User
FRC #4761 (Robockets)
Team Role: Programmer
 
Join Date: Feb 2015
Rookie Year: 2015
Location: Reading, MA
Posts: 16
simon-andrews is an unknown quantity at this point
Re: How can angle offset of a shooter be calculated from pixel offset?

Quote:
Originally Posted by Arhowk View Post
You clearly calculate angle_offset right in that code...

Are you asking how to make a PID loop to turn the robot?
No. That function isn't what I need because it doesn't return an angle that can be plugged into the turntable. The program I'm supposed to write should be able to look at an image and figure out "Alright, turntable. You need to turn 45 degrees if you want to be on-target."

If we look at this drawing from an earlier post, both lines (which represent pixel offsets) are 100px long. With the function from before, both would return the same angle offset since the function doesn't account for distance away from the target.
__________________

GitHub | StackOverflow
Reply With Quote
  #8   Spotlight this post!  
Unread 02-04-2016, 20:26
Oblarg Oblarg is offline
Registered User
AKA: Eli Barnett
FRC #0449 (The Blair Robot Project)
Team Role: Mentor
 
Join Date: Mar 2009
Rookie Year: 2008
Location: Philadelphia, PA
Posts: 1,047
Oblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond repute
Re: How can angle offset of a shooter be calculated from pixel offset?

Quote:
Originally Posted by simon-andrews View Post
No. That function isn't what I need because it doesn't return an angle that can be plugged into the turntable. The program I'm supposed to write should be able to look at an image and figure out "Alright, turntable. You need to turn 45 degrees if you want to be on-target."

If we look at this drawing from an earlier post, both lines (which represent pixel offsets) are 100px long. With the function from before, both would return the same angle offset since the function doesn't account for distance away from the target.
You're slightly confused.

Distance away from the target doesn't matter, that's precisely why you're measuring in angle (a dimensionless quantity) and not in distance.

Imagine the camera at the origin, pointing in the +y direction. Place your target off to the side somewhere. How far off-center your target will appear in pixels is proportional to the angle between the line from the origin to the target and the y axis, not to the distance from the point to the y axis. To see this, place one target at (1,1). Place another target at (1,2). These are the same distance from the y-axis, which is the centerline of the camera's FOV, but they will clearly appear at different distances from the center when viewed from the camera, because the camera is a point at the origin and only sees along rays that pass through it.

For an even better demonstration: Cover one of your eyes, align your other (open) eye with the center of your computer screen. Place your finger between your face and your computer screen, so that it overlaps with the edge of the screen in your vision. Notice that your finger is closer to the centerline between your eye and the center of the screen than the edge of the monitor is, despite the fact that they appear the same "distance" away in the 2d image that you see.

The fundamental confusion here is that you're thinking in terms of rays parallel to the center-line of the camera. But that's incorrect, because those rays never reach the camera. Think of the camera as a point, not as a screen. All the rays that the camera sees must pass through the point. Thinking this way, it is clear that "distance" in the image the camera sees corresponds to *angular* distance. To preserve apparent "distance" between two objects from the point of view of the camera, you must preserve their relative angular positions.
__________________
"Mmmmm, chain grease and aluminum shavings..."
"The breakfast of champions!"

Member, FRC Team 449: 2007-2010
Drive Mechanics Lead, FRC Team 449: 2009-2010
Alumnus/Technical Mentor, FRC Team 449: 2010-Present
Lead Technical Mentor, FRC Team 4464: 2012-2015
Technical Mentor, FRC Team 5830: 2015-2016

Last edited by Oblarg : 02-04-2016 at 20:51.
Reply With Quote
  #9   Spotlight this post!  
Unread 02-04-2016, 20:55
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,532
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: How can angle offset of a shooter be calculated from pixel offset?

If your method described above doesn't seem to give you quite the right answer, perhaps you really want to know what the proportionality constant (pixels to degrees) is for small angles (rather than the full image width). To do this, I suggest:
  1. Position the robot so that the target is reasonably close to the center of the image.
  2. Note exactly where the target center is located.
  3. Rotate by a known small number of degrees (perhaps 5 or 10)
  4. Note where the center of the target is now.
  5. Divide the number of pixels moved from step 2 to 4 by the number of degrees rotated in step 3

This will give you the number of pixels per degree for small angles near the center of the camera image.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #10   Spotlight this post!  
Unread 02-04-2016, 21:00
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: How can angle offset of a shooter be calculated from pixel offset?

If you want to aim to the center of the target than obtain the center x of the target and rotate to it using the formulas postEd.

In the photo posted, the left edge of the target is roughly at x=0 (assuming a graph is overlayed) and the right boundary is at x=x for the "far" target and x=2x for the "near" target, meaning the centers would be at x=1/2x and x=x respectively. The "near" target will request twice as much turning.

Also please stop using the word turntable
__________________
FRC Team 1684 - Head Programmer (2013-2016)
FRC Team 5460 - Programming Mentor (2015-2016)

FIRST in Michigan - Technical Crew (2015-continuing)
Reply With Quote
  #11   Spotlight this post!  
Unread 04-04-2016, 14:48
GreyingJay GreyingJay is offline
Robonut
AKA: Mr. Lam
FRC #2706 (Merge Robotics)
Team Role: Mentor
 
Join Date: Mar 2015
Rookie Year: 2015
Location: Ottawa, Canada
Posts: 737
GreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond repute
Re: How can angle offset of a shooter be calculated from pixel offset?

Quote:
Originally Posted by Arhowk View Post
Also please stop using the word turntable
It's a Lazy Susan!
Reply With Quote
  #12   Spotlight this post!  
Unread 04-04-2016, 21:06
Chris Hibner's Avatar Unsung FIRST Hero
Chris Hibner Chris Hibner is offline
Eschewing Obfuscation Since 1990
AKA: Lars Kamen's Roadie
FRC #0051 (Wings of Fire)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1997
Location: Canton, MI
Posts: 1,488
Chris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond repute
Re: How can angle offset of a shooter be calculated from pixel offset?

It's fairly simple. It's (pixels from center) / (camera pixel width) * FOV
For example, your camera has a field of view (FOV) of 45 degrees, your camera width is 320 pixels, and your image is 16 pixels off center. Then the angle to aim is:

(320 pixles/16 pixels) * 45 degrees = 2.25 degrees

You can calibrate your exact camera FOV by pointing your camera at a white board and marking two points on the white board at the left and right edge of the camera image. Then measure the distance between the two points on the white board, and the distance between the white board and the camera. Then a little trig will give you the FOV.
__________________
-
An ounce of perception is worth a pound of obscure.
Reply With Quote
Reply


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 08:56.

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