Go to Post So yeah, everyone please remember that lathes are one of the most dangerous machine tools you'll encounter. And keep your hand on the chuck key whenever it's in the chuck. If you never let it go till it's out of the chuck, it's stupendously less likely to take flight. - Kevin Sevcik [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #9   Spotlight this post!  
Unread 08-02-2013, 17:38
Justin m's Avatar
Justin m Justin m is offline
Registered User
FRC #2028 (Phantom Mentalists)
Team Role: Programmer
 
Join Date: Nov 2012
Rookie Year: 2012
Location: Hampton, va
Posts: 14
Justin m is an unknown quantity at this point
Re: Getting distance to the goal

What the you have to do is determine the width of the target in pixels, given a constant value w/ the target centered, and find the hypotenuse, which is your distance
EDIT: Use the height for distance, not the width.The width can vary with angle to the target.
Example:
Note, these are necessary constants
Code:
    public static final int IMAGE_WIDTH = 320;
    public static final int IMAGE_HEIGHT = 240;
    public static final double TARGET_WIDTH = 2.0;
    public static final double TARGET_HEIGHT = 1.5;
    public static final double RECTANGLE_QUALITY_THRESHOLD = 95.0;
    public static final double PARTICLE_TO_IMAGE_THRESHOLD = 0.05;
    public static final double PARTICLE_AREA_THRESHOLD = 250.0;
    protected double fieldOfViewWidth = 0.0;

    /**
     * Return distance to target in inches
     *
     * @param targetHeightInPixels
     * @return
     */
    public double GetDistanceToTarget(int targetHeightInPixels)
    {
        double fieldOfViewHeight = TARGET_HEIGHT / targetHeightInPixels * IMAGE_HEIGHT;
        distance = (fieldOfViewHeight / 2.0) / 
                /*
                 * tan 23.5 degrees
                 */
                  0.4348123749;
        return distance * 12.0 * 1.4;
    }
I am assuming you can figure out how to filter for targets.

Last edited by Justin m : 08-02-2013 at 19:53. Reason: forgot one important thing
 


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 21: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