Java 类edu.wpi.first.wpilibj.image.NIVision.MeasurementType 实例源码

项目:Aerial-Assist    文件:AxisCameraM1101.java   
/**
 * Computes a score (0-100) comparing the aspect ratio to the ideal aspect
 * ratio for the target. This method uses the equivalent rectangle sides to
 * determine aspect ratio as it performs better as the target gets skewed by
 * moving to the left or right. The equivalent rectangle is the rectangle
 * with sides x and y where particle area, xy and particle perimeter, 2x+2y
 *
 * @param image The image containing the particle to score, needed to
 * perform additional measurements
 * @param report The Particle Analysis Report for the particle, used for the
 * width, height, and particle number
 * @param outer Indicates whether the particle aspect ratio should be
 * compared to the ratio for the inner target or the outer
 * @return The aspect ratio score (0-100)
 */
private double scoreAspectRatio(BinaryImage image, ParticleAnalysisReport 
        report, int particleNumber, boolean vertical) throws 
        NIVisionException {

    double rectLong, rectShort, aspectRatio, idealAspectRatio;

    rectLong = NIVision.MeasureParticle(image.image, particleNumber, false, 
            MeasurementType.IMAQ_MT_EQUIVALENT_RECT_LONG_SIDE);
    rectShort = NIVision.MeasureParticle(image.image, particleNumber, false, 
            MeasurementType.IMAQ_MT_EQUIVALENT_RECT_SHORT_SIDE);
    idealAspectRatio = vertical ? (4.0 / 32) : (23.5 / 4);

    if (report.boundingRectWidth > report.boundingRectHeight) {
        aspectRatio = ratioToScore((rectLong / rectShort)/idealAspectRatio);
    } else {
        aspectRatio = ratioToScore((rectShort / rectLong)/idealAspectRatio);
    }
    return aspectRatio;
}
项目:2014VisionSample    文件:VisionSampleProject2014.java   
/**
    * Computes a score (0-100) comparing the aspect ratio to the ideal aspect ratio for the target. This method uses
    * the equivalent rectangle sides to determine aspect ratio as it performs better as the target gets skewed by moving
    * to the left or right. The equivalent rectangle is the rectangle with sides x and y where particle area= x*y
    * and particle perimeter= 2x+2y
    * 
    * @param image The image containing the particle to score, needed to perform additional measurements
    * @param report The Particle Analysis Report for the particle, used for the width, height, and particle number
    * @param outer  Indicates whether the particle aspect ratio should be compared to the ratio for the inner target or the outer
    * @return The aspect ratio score (0-100)
    */
   public double scoreAspectRatio(BinaryImage image, ParticleAnalysisReport report, int particleNumber, boolean vertical) throws NIVisionException
   {
       double rectLong, rectShort, aspectRatio, idealAspectRatio;

       rectLong = NIVision.MeasureParticle(image.image, particleNumber, false, MeasurementType.IMAQ_MT_EQUIVALENT_RECT_LONG_SIDE);
       rectShort = NIVision.MeasureParticle(image.image, particleNumber, false, MeasurementType.IMAQ_MT_EQUIVALENT_RECT_SHORT_SIDE);
       idealAspectRatio = vertical ? (4.0/32) : (23.5/4);   //Vertical reflector 4" wide x 32" tall, horizontal 23.5" wide x 4" tall

       //Divide width by height to measure aspect ratio
       if(report.boundingRectWidth > report.boundingRectHeight){
           //particle is wider than it is tall, divide long by short
           aspectRatio = ratioToScore((rectLong/rectShort)/idealAspectRatio);
       } else {
           //particle is taller than it is wide, divide short by long
           aspectRatio = ratioToScore((rectShort/rectLong)/idealAspectRatio);
       }
return aspectRatio;
   }
项目:2014Robot-    文件:ShooterComputer.java   
/**
 * Computes a score (0-100) comparing the aspect ratio to the ideal aspect
 * ratio for the target. This method uses the equivalent rectangle sides to
 * determine aspect ratio as it performs better as the target gets skewed by
 * moving to the left or right. The equivalent rectangle is the rectangle
 * with sides x and y where particle area= x*y and particle perimeter= 2x+2y
 *
 * @param image The image containing the particle to score, needed to
 * performa additional measurements
 * @param report The Particle Analysis Report for the particle, used for the
 * width, height, and particle number
 * @param outer Indicates whether the particle aspect ratio should be
 * compared to the ratio for the inner target or the outer
 * @return The aspect ratio score (0-100)
 */
public double scoreAspectRatio(BinaryImage image, ParticleAnalysisReport report, int particleNumber, boolean outer) throws NIVisionException {
    double rectLong, rectShort, aspectRatio, idealAspectRatio;

    rectLong = NIVision.MeasureParticle(image.image, particleNumber, false, MeasurementType.IMAQ_MT_EQUIVALENT_RECT_LONG_SIDE);
    rectShort = NIVision.MeasureParticle(image.image, particleNumber, false, MeasurementType.IMAQ_MT_EQUIVALENT_RECT_SHORT_SIDE);
    idealAspectRatio = outer ? (62 / 29) : (62 / 20);   //Dimensions of goal opening + 4 inches on all 4 sides for reflective tape

    //Divide width by height to measure aspect ratio
    if (report.boundingRectWidth > report.boundingRectHeight) {
        //particle is wider than it is tall, divide long by short
        aspectRatio = 100 * (1 - Math.abs((1 - ((rectLong / rectShort) / idealAspectRatio))));
    } else {
        //particle is taller than it is wide, divide short by long
        aspectRatio = 100 * (1 - Math.abs((1 - ((rectShort / rectLong) / idealAspectRatio))));
    }
    return (Math.max(0, Math.min(aspectRatio, 100.0)));     //force to be in range 0-100
}
项目:2014CameraTracking    文件:VisionSampleProject2014.java   
/**
 * Computes a score (0-100) comparing the aspect ratio to the ideal aspect
 * ratio for the target. This method uses the equivalent rectangle sides to
 * determine aspect ratio as it performs better as the target gets skewed by
 * moving to the left or right. The equivalent rectangle is the rectangle
 * with sides x and y where particle area= x*y and particle perimeter= 2x+2y
 *
 * @param image The image containing the particle to score, needed to
 * perform additional measurements
 * @param report The Particle Analysis Report for the particle, used for the
 * width, height, and particle number
 * @param outer Indicates whether the particle aspect ratio should be
 * compared to the ratio for the inner target or the outer
 * @return The aspect ratio score (0-100)
 */
public double scoreAspectRatio(BinaryImage image, ParticleAnalysisReport report, int particleNumber, boolean vertical) throws NIVisionException {
    double rectLong, rectShort, aspectRatio, idealAspectRatio;

    rectLong = NIVision.MeasureParticle(image.image, particleNumber, false, MeasurementType.IMAQ_MT_EQUIVALENT_RECT_LONG_SIDE);
    rectShort = NIVision.MeasureParticle(image.image, particleNumber, false, MeasurementType.IMAQ_MT_EQUIVALENT_RECT_SHORT_SIDE);
    idealAspectRatio = vertical ? (4.0 / 32) : (23.5 / 4);  //Vertical reflector 4" wide x 32" tall, horizontal 23.5" wide x 4" tall

    //Divide width by height to measure aspect ratio
    if (report.boundingRectWidth > report.boundingRectHeight) {
        //particle is wider than it is tall, divide long by short
        aspectRatio = ratioToScore((rectLong / rectShort) / idealAspectRatio);
    } else {
        //particle is taller than it is wide, divide short by long
        aspectRatio = ratioToScore((rectShort / rectLong) / idealAspectRatio);
    }
    return aspectRatio;
}
项目:PillowBot    文件:VisionTracker.java   
/**
    * Computes a score (0-100) comparing the aspect ratio to the ideal aspect ratio for the target. This method uses
    * the equivalent rectangle sides to determine aspect ratio as it performs better as the target gets skewed by moving
    * to the left or right. The equivalent rectangle is the rectangle with sides x and y where particle area= x*y
    * and particle perimeter= 2x+2y
    * 
    * @param image The image containing the particle to score, needed to perform additional measurements
    * @param report The Particle Analysis Report for the particle, used for the width, height, and particle number
    * @param outer  Indicates whether the particle aspect ratio should be compared to the ratio for the inner target or the outer
    * @return The aspect ratio score (0-100)
    */
   public double scoreAspectRatio(BinaryImage image, ParticleAnalysisReport report, int particleNumber, boolean vertical) throws NIVisionException
   {
       double rectLong, rectShort, aspectRatio, idealAspectRatio;

       rectLong = NIVision.MeasureParticle(image.image, particleNumber, false, MeasurementType.IMAQ_MT_EQUIVALENT_RECT_LONG_SIDE);
       rectShort = NIVision.MeasureParticle(image.image, particleNumber, false, MeasurementType.IMAQ_MT_EQUIVALENT_RECT_SHORT_SIDE);
       idealAspectRatio = vertical ? (4.0/32) : (23.5/4);   //Vertical reflector 4" wide x 32" tall, horizontal 23.5" wide x 4" tall

       //Divide width by height to measure aspect ratio
       if(report.boundingRectWidth > report.boundingRectHeight){
           //particle is wider than it is tall, divide long by short
           aspectRatio = ratioToScore((rectLong/rectShort)/idealAspectRatio);
       } else {
           //particle is taller than it is wide, divide short by long
           aspectRatio = ratioToScore((rectShort/rectLong)/idealAspectRatio);
       }
return aspectRatio;
   }
项目:RobotBlueTwilight2013    文件:VisionSampleProject2013.java   
/**
    * Computes a score (0-100) comparing the aspect ratio to the ideal aspect ratio for the target. This method uses
    * the equivalent rectangle sides to determine aspect ratio as it performs better as the target gets skewed by moving
    * to the left or right. The equivalent rectangle is the rectangle with sides x and y where particle area= x*y
    * and particle perimeter= 2x+2y
    * 
    * @param image The image containing the particle to score, needed to performa additional measurements
    * @param report The Particle Analysis Report for the particle, used for the width, height, and particle number
    * @param outer  Indicates whether the particle aspect ratio should be compared to the ratio for the inner target or the outer
    * @return The aspect ratio score (0-100)
    */
   public double scoreAspectRatio(BinaryImage image, ParticleAnalysisReport report, int particleNumber, boolean outer) throws NIVisionException
   {
       double rectLong, rectShort, aspectRatio, idealAspectRatio;

       rectLong = NIVision.MeasureParticle(image.image, particleNumber, false, MeasurementType.IMAQ_MT_EQUIVALENT_RECT_LONG_SIDE);
       rectShort = NIVision.MeasureParticle(image.image, particleNumber, false, MeasurementType.IMAQ_MT_EQUIVALENT_RECT_SHORT_SIDE);
       idealAspectRatio = outer ? (62/29) : (62/20);    //Dimensions of goal opening + 4 inches on all 4 sides for reflective tape

       //Divide width by height to measure aspect ratio
       if(report.boundingRectWidth > report.boundingRectHeight){
           //particle is wider than it is tall, divide long by short
           aspectRatio = 100*(1-Math.abs((1-((rectLong/rectShort)/idealAspectRatio))));
       } else {
           //particle is taller than it is wide, divide short by long
               aspectRatio = 100*(1-Math.abs((1-((rectShort/rectLong)/idealAspectRatio))));
       }
return (Math.max(0, Math.min(aspectRatio, 100.0)));     //force to be in range 0-100
   }
项目:Aerial-Assist    文件:AxisCameraM1101.java   
/**
 * Computes the estimated distance to a target using the height of the
 * particle in the image. For more information and graphics showing the math
 * behind this approach see the Vision Processing section of the
 * ScreenStepsLive documentation.
 *
 * @param image The image to use for measuring the particle estimated
 * rectangle.
 * @param report The particle analysis report for the particle.
 * @param outer True if the particle should be treated as an outer target,
 * false to treat it as a center target.
 * @return The estimated distance to the target in inches.
 */
private double computeDistance(BinaryImage image, ParticleAnalysisReport 
        report, int particleNumber) throws NIVisionException {
    double rectLong, height;
    int targetHeight;

    rectLong = NIVision.MeasureParticle(image.image, particleNumber, false, 
            MeasurementType.IMAQ_MT_EQUIVALENT_RECT_LONG_SIDE);
    height = Math.min(report.boundingRectHeight, rectLong);
    targetHeight = 32;

    return Y_IMAGE_RES * targetHeight / (height * 12 * 2 
            * Math.tan(VIEW_ANGLE * Math.PI / (180 * 2)));
}
项目:2014VisionSample    文件:VisionSampleProject2014.java   
public void robotInit() {

    System.out.println("-- 2014 Target Test --");

    camera = AxisCamera.getInstance();  // get an instance of the camera
    cc = new CriteriaCollection();      // create the criteria for the particle filter
    cc.addCriteria(MeasurementType.IMAQ_MT_AREA, AREA_MINIMUM, 65535, false);
}
项目:2014VisionSample    文件:VisionSampleProject2014.java   
/**
 * Computes the estimated distance to a target using the height of the particle in the image. For more information and graphics
 * showing the math behind this approach see the Vision Processing section of the ScreenStepsLive documentation.
 * 
 * @param image The image to use for measuring the particle estimated rectangle
 * @param report The Particle Analysis Report for the particle
 * @param outer True if the particle should be treated as an outer target, false to treat it as a center target
 * @return The estimated distance to the target in Inches.
 */
double computeDistance (BinaryImage image, ParticleAnalysisReport report, int particleNumber) throws NIVisionException {
        double rectLong, height;
        int targetHeight;

        rectLong = NIVision.MeasureParticle(image.image, particleNumber, false, MeasurementType.IMAQ_MT_EQUIVALENT_RECT_LONG_SIDE);
        //using the smaller of the estimated rectangle long side and the bounding rectangle height results in better performance
        //on skewed rectangles
        height = Math.min(report.boundingRectHeight, rectLong);
        targetHeight = 32;

        return Y_IMAGE_RES * targetHeight / (height * 12 * 2 * Math.tan(VIEW_ANGLE*Math.PI/(180*2)));
}
项目:PillowBot    文件:PillowCam.java   
public PillowCam() {
    camera = AxisCamera.getInstance();

    cc = new CriteriaCollection();
    cc.addCriteria(MeasurementType.IMAQ_MT_AREA, AREA_MIN, AREA_MAX, false);

    ccLeft = new CriteriaCollection();
    ccLeft.addCriteria(MeasurementType.IMAQ_MT_FIRST_PIXEL_X, 0, 120, false);

    ccRight = new CriteriaCollection();
    ccRight.addCriteria(MeasurementType.IMAQ_MT_FIRST_PIXEL_X, 200, 320, false);
}
项目:PillowBot    文件:VisionTracker.java   
/**
 * Computes the estimated distance to a target using the height of the particle in the image. For more information and graphics
 * showing the math behind this approach see the Vision Processing section of the ScreenStepsLive documentation.
 * 
 * @param image The image to use for measuring the particle estimated rectangle
 * @param report The Particle Analysis Report for the particle
 * @param outer True if the particle should be treated as an outer target, false to treat it as a center target
 * @return The estimated distance to the target in Inches.
 */
double computeDistance (BinaryImage image, ParticleAnalysisReport report, int particleNumber) throws NIVisionException {
        double rectLong, height;
        int targetHeight;

        rectLong = NIVision.MeasureParticle(image.image, particleNumber, false, MeasurementType.IMAQ_MT_EQUIVALENT_RECT_LONG_SIDE);
        //using the smaller of the estimated rectangle long side and the bounding rectangle height results in better performance
        //on skewed rectangles
        height = Math.min(report.boundingRectHeight, rectLong);
        targetHeight = 32;

        return Y_IMAGE_RES * targetHeight / (height * 12 * 2 * Math.tan(VIEW_ANGLE*Math.PI/(180*2)));
}
项目:2012    文件:CameraUnit.java   
public CameraUnit()
{
    camera = AxisCamera.getInstance(ReboundRumble.CAMERA_IP);
    camera.writeResolution(AxisCamera.ResolutionT.k320x240);
    camera.writeExposurePriority(AxisCamera.ExposurePriorityT.imageQuality);
    camera.writeExposureControl(AxisCamera.ExposureT.hold);
    camera.writeWhiteBalance(AxisCamera.WhiteBalanceT.fixedIndoor);
    cc = new CriteriaCollection();
    cc.addCriteria(MeasurementType.IMAQ_MT_BOUNDING_RECT_WIDTH, 15, 400, false);
    cc.addCriteria(MeasurementType.IMAQ_MT_BOUNDING_RECT_HEIGHT, 15, 400, false);
    cameraPan = new Servo(1, 6);
    cameraTilt = new Servo(1, 7);
}
项目:RobotCode2013    文件:Vision.java   
public Vision() {
    if (enableVision) camera = AxisCamera.getInstance("10.25.2.11");
    lastFrame = System.currentTimeMillis();
    frameProcess = 0;
    cc = new CriteriaCollection();
    cc.addCriteria(MeasurementType.IMAQ_MT_AREA, 3000, 6000, false);
    distanceReg = new Regression(0.0000086131992, -0.0893246981, 244.5414525); // a, b, c
    angleReg = new Regression(15.32142857, -565.2928571, 5720.678571); // a, b, c
    SmartDashboard.putNumber("Angle Regression Constant", angleReg.getConstant());
}
项目:Robotcode    文件:Team1482Robot.java   
public void robotInit() {
        camera = AxisCamera.getInstance();
        cc = new CriteriaCollection();
        cc.addCriteria(MeasurementType.IMAQ_MT_BOUNDING_RECT_WIDTH, 0, 0, false);
        cc.addCriteria(MeasurementType.IMAQ_MT_BOUNDING_RECT_HEIGHT, 0, 0, false); //todo: check WPILibJ documentation
        SmartDashboard.putBoolean("Grab state", false);
        SmartDashboard.putBoolean("Lift state", false);
        System.out.println("RobotInit() completed. \n");
}
项目:RobotBlueTwilight2013    文件:VisionSampleProject2013.java   
/**
 * Computes the estimated distance to a target using the height of the particle in the image. For more information and graphics
 * showing the math behind this approach see the Vision Processing section of the ScreenStepsLive documentation.
 * 
 * @param image The image to use for measuring the particle estimated rectangle
 * @param report The Particle Analysis Report for the particle
 * @param outer True if the particle should be treated as an outer target, false to treat it as a center target
 * @return The estimated distance to the target in Inches.
 */
double computeDistance (BinaryImage image, ParticleAnalysisReport report, int particleNumber, boolean outer) throws NIVisionException {
        double rectShort, height;
        int targetHeight;

        rectShort = NIVision.MeasureParticle(image.image, particleNumber, false, MeasurementType.IMAQ_MT_EQUIVALENT_RECT_SHORT_SIDE);
        //using the smaller of the estimated rectangle short side and the bounding rectangle height results in better performance
        //on skewed rectangles
        height = Math.min(report.boundingRectHeight, rectShort);
        targetHeight = outer ? 29 : 21;

        return X_IMAGE_RES * targetHeight / (height * 12 * 2 * Math.tan(VIEW_ANGLE*Math.PI/(180*2)));
}
项目:wpilibj    文件:CriteriaCollection.java   
ParticleFilterCriteria(MeasurementType type, float lower, float upper, boolean outsideRange) {
    this.type = type;
    this.lower = lower;
    this.upper = upper;
    this.outsideRange = outsideRange;
}
项目:wpilibj    文件:CriteriaCollection.java   
public void addCriteria(MeasurementType type, float lower, float upper, boolean outsideRange) {
    criteria.addElement(new ParticleFilterCriteria(type, lower, upper, outsideRange));
}
项目:Aerial-Assist    文件:AxisCameraM1101.java   
public AxisCameraM1101() {
    camera = AxisCamera.getInstance();
    criteriaCollection = new CriteriaCollection();
    criteriaCollection.addCriteria(NIVision.MeasurementType.IMAQ_MT_AREA, 
            AREA_MINIMUM, 65535, true);
}
项目:2014Robot-    文件:ShooterComputer.java   
public ShooterComputer() {
    camera = AxisCamera.getInstance(RobotMap.CAMERA_IP);  // get an instance of the camera
    cc = new CriteriaCollection();      // create the criteria for the particle filter
    cc.addCriteria(MeasurementType.IMAQ_MT_AREA, 500, 65535, false);
    prefs = Preferences.getInstance();
}
项目:2014CameraTracking    文件:VisionSampleProject2014.java   
public void robotInit() {
    camera = AxisCamera.getInstance("10.35.28.11");  // get an instance of the camera
    cc = new CriteriaCollection();      // create the criteria for the particle filter
    cc.addCriteria(MeasurementType.IMAQ_MT_AREA, AREA_MINIMUM, 65535, false);
}
项目:PillowBot    文件:VisionTracker.java   
public VisionTracker(){
    this.camera = AxisCamera.getInstance();
    cc = new CriteriaCollection();      // create the criteria for the particle filter
    cc.addCriteria(MeasurementType.IMAQ_MT_AREA, AREA_MINIMUM, 65535, false);
}
项目:RobotBlueTwilight2013    文件:VisionSampleProject2013.java   
public void robotInit() {
    //camera = AxisCamera.getInstance();  // get an instance of the camera
    cc = new CriteriaCollection();      // create the criteria for the particle filter
    cc.addCriteria(MeasurementType.IMAQ_MT_AREA, 500, 65535, false);
}
项目:wpilib-java    文件:CriteriaCollection.java   
ParticleFilterCriteria(MeasurementType type, float lower, float upper, boolean outsideRange) {
    this.type = type;
    this.lower = lower;
    this.upper = upper;
    this.outsideRange = outsideRange;
}
项目:wpilib-java    文件:CriteriaCollection.java   
public void addCriteria(MeasurementType type, float lower, float upper, boolean outsideRange) {
    criteria.addElement(new ParticleFilterCriteria(type, lower, upper, outsideRange));
}
项目:2014Robot-    文件:ShooterComputer.java   
/**
 * Computes the estimated distance to a target using the height of the
 * particle in the image. For more information and graphics showing the math
 * behind this approach see the Vision Processing section of the
 * ScreenStepsLive documentation.
 *
 * @param image The image to use for measuring the particle estimated
 * rectangle
 * @param report The Particle Analysis Report for the particle
 * @param outer True if the particle should be treated as an outer target,
 * false to treat it as a center target
 * @return The estimated distance to the target in Inches.
 */
double computeDistance(BinaryImage image, ParticleAnalysisReport report, int particleNumber, boolean outer) throws NIVisionException {
    double rectShort, height;
    int targetHeight;

    rectShort = NIVision.MeasureParticle(image.image, particleNumber, false, MeasurementType.IMAQ_MT_EQUIVALENT_RECT_SHORT_SIDE);
    //using the smaller of the estimated rectangle short side and the bounding rectangle height results in better performance
    //on skewed rectangles
    height = Math.min(report.boundingRectHeight, rectShort);
    targetHeight = outer ? 29 : 21;

    return X_IMAGE_RES * targetHeight / (height * 12 * 2 * Math.tan(VIEW_ANGLE * Math.PI / (180 * 2)));
}
项目:2014CameraTracking    文件:VisionSampleProject2014.java   
/**
 * Computes the estimated distance to a target using the height of the
 * particle in the image. For more information and graphics showing the math
 * behind this approach see the Vision Processing section of the
 * ScreenStepsLive documentation.
 *
 * @param image The image to use for measuring the particle estimated
 * rectangle
 * @param report The Particle Analysis Report for the particle
 * @param outer True if the particle should be treated as an outer target,
 * false to treat it as a center target
 * @return The estimated distance to the target in Inches.
 */
double computeDistance(BinaryImage image, ParticleAnalysisReport report, int particleNumber) throws NIVisionException {
    double rectLong, height;
    int targetHeight;

    rectLong = NIVision.MeasureParticle(image.image, particleNumber, false, MeasurementType.IMAQ_MT_EQUIVALENT_RECT_LONG_SIDE);
        //using the smaller of the estimated rectangle long side and the bounding rectangle height results in better performance
    //on skewed rectangles
    height = Math.min(report.boundingRectHeight, rectLong);
    targetHeight = 32;

    return Y_IMAGE_RES * targetHeight / (height * 12 * 2 * Math.tan(VIEW_ANGLE * Math.PI / (180 * 2)));
}