Go to Post Don't bring a distraction to the field. - Al Skierkiewicz [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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 22-08-2013, 18:48
tuXguy15's Avatar
tuXguy15 tuXguy15 is offline
Team Mentor
AKA: Devin Kolarac
FRC #2559 (Normality Zero)
 
Join Date: Apr 2012
Rookie Year: 2012
Location: Harrisburg, PA
Posts: 127
tuXguy15 is an unknown quantity at this point
JavaCV Widget Questions

Before I attempt to knock out a javacv widget for the frc smart dashboard i have a couple of questions about some things. In many examples i look at there are many variables that are specified and i was wondering where these come from or what they mean. My next question is what are the x and y coordinates for and what do you do with them to adjust the robots position for lining up. What should the x and y be when lined up? How do you calculate distance with javacv and what else should I know about such an application.
__________________
Reply With Quote
  #2   Spotlight this post!  
Unread 23-08-2013, 11:15
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,077
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: JavaCV Widget Questions

"x" and "y" coordinates usually refer to the location of a pixel in the camera image. There are different systems for the coordinate system, but usually "x" is horizontal (so it counts the number of columns) and starts with 0 at the left edge, and (image width-1) at the right edge. "y" is vertical (so it counts the number of rows) and usually starts with 0 at the top, and (image height-1) at the bottom.

Thus the origin (0,0) is usually in the top left of the camera image for computer graphics and computer vision applications (though some times you'll find code with the origin in the lower left).

Let's say your camera is mounted on your shooter, and the shooter is amazingly well calibrated. It always shoots discs straight down the middle of the camera image. If your image has a resolution of 640x480 (width x height), then your shooter is aiming at about (320, 240) for (x,y).

Now, if you detect that the center of the goal is to the left of the shooter - say, (100, 240) - then you know you need to turn the robot to the left to aim. If you can get the detected center of the goal in (close to) the exact same spot that your shooter fires, you know you'll have a high chance of making the shot.

Calculating distance is a little bit tougher. It will involve doing some trigonometry, since a standard RGB camera does not give you distance information directly. One way to do it (which we did to great effect in 2012) is to use the "y" component of the center of the goal. If you know your camera's height off the ground, the camera's angle with respect to the ground, the height of the goal, and the "y" component of the goal center, you can set up an inverse trigonometry problem to obtain the missing sides of a triangle. There are other ways to do it too (multiple cameras for stereo vision, or using the size of the goal to figure out distance), but I contend that using trigonometry is the most robust way for FRC (short of using a Kinect). Luckily, most frisbee shooters have a pretty flat arc, so you may not need to do this at all!

For your questions on variables, it depends which examples you are looking at. Here is an example I posted last year (gee, maybe I should update it with some new features from our 2013 version?): http://www.chiefdelphi.com/media/papers/2676? Feel free to ask away about anything in particular.

Last edited by Jared Russell : 23-08-2013 at 11:18.
Reply With Quote
  #3   Spotlight this post!  
Unread 23-08-2013, 15:00
tuXguy15's Avatar
tuXguy15 tuXguy15 is offline
Team Mentor
AKA: Devin Kolarac
FRC #2559 (Normality Zero)
 
Join Date: Apr 2012
Rookie Year: 2012
Location: Harrisburg, PA
Posts: 127
tuXguy15 is an unknown quantity at this point
Re: JavaCV Widget Questions

Ok so in your code i see the part where you constructed constants. How would you tune them. What do they do because i see them in other codes as well.
__________________
Reply With Quote
  #4   Spotlight this post!  
Unread 27-08-2013, 17:31
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,077
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: JavaCV Widget Questions

Quote:
Originally Posted by tuXguy15 View Post
Ok so in your code i see the part where you constructed constants. How would you tune them. What do they do because i see them in other codes as well.
Sorry for the belated reply...

kNearlyHorizontalSlope and kNearlyVerticalSlope were limits we had on how oblique of an angle we would allow in order to count the edge of a target as a vertical or horizontal line. (We would of course expect a rectangular target to have 2 vertical lines and 2 horizontal lines). We tuned them by trial and error, allowing for some misalignment relative to the target, but still throwing out images that were clearly not the goal.

kMinWidth and kMaxWidth were the widths of the vision target from the closest and furthest ranges we would ever see based on our test images.

kRangeOffset is a global value that adds/subtracts to the desired RPM we are commanding (useful if we find that every single shot is too low, for example).

kHoleClosingIterations was found through trial and error on a test set of images. It is a parameter to the OpenCV function cvMorphologyEx.

kShooterOffsetDeg was found by firing our shooter and seeing where in the camera frame the shot went. As you can see, our shooter was consistently about a degree and a half to the left of center of the camera.

kHorizontalFOVDeg is the camera field of view, which is 47 degrees according to the manufacturer. kVerticalFOVDeg is the same.

kCameraHeightIn and kCameraPitchDeg are the height and angle of the camera relative to the floor, respectively. Measured based on our robot.

kTopTargetHeightIn is the height off the floor of the center of the top vision target.

In the constructor, you see a bunch of numbers put into a TreeMap. This map takes a range in inches (first number) and a desired RPM (second number) and basically lets us look up the best RPM for any given range. All of this was driven by shooting on a practice field and recording the optimal RPM for different ranges.

On lines 182-189, you see a few more magic numbers. These were all tweaked in order to find the right color (green) and saturation/value for the target. Driven by taking test images and using MS Paint (or similar) eyedropper to check the values of pixels on the target.

Line 216 is a ratio check...we expect a ratio of height/width between 0.5 and 1.0 (so wider than it is tall). On line 218, the "20" is a parameter to the approxPolygon function, which we found to work well when using test images.

I think that is all of the constants in there (other than things like "4" being the number of sides in a rectangle, and Pi, etc.). Hope this helps. Note that we DEFINITELY could have done a better job of reducing "magic numbers" in our code (and we did in 2013), but this is what you get in 6 weeks
Reply With Quote
  #5   Spotlight this post!  
Unread 25-08-2013, 02:19
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Re: JavaCV Widget Questions

Quote:
Originally Posted by Jared341 View Post
(gee, maybe I should update it with some new features from our 2013 version?)
Yes!
__________________
All opinions are my own.
Reply With Quote
  #6   Spotlight this post!  
Unread 06-10-2013, 09:58
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: JavaCV Widget Questions

Kinda what you are not looking for, but, do you know some resources where I can learn OpenCV/JavaCV?
Reply With Quote
  #7   Spotlight this post!  
Unread 06-10-2013, 19:35
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: JavaCV Widget Questions

Quote:
Originally Posted by team1165wins View Post
Kinda what you are not looking for, but, do you know some resources where I can learn OpenCV/JavaCV?
http://docs.opencv.org/ is an unparalleled resource for OpenCV.
__________________
I code stuff.
Reply With Quote
  #8   Spotlight this post!  
Unread 16-10-2013, 15:21
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 329
fovea1959 will become famous soon enough
Re: JavaCV Widget Questions

One of the best things to do to understand this is to look at Team 341's DaisyCV, and uncomment out where they display intermediate results. Seeing how the successive operations pull out the hue, saturation, and brightness, threshold them, find the contours, polygons, etc, was *very* instructional, especially when you read the docs while reading the code.
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 06:54.

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