コード例 #1
0
  /**
   * 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 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
  }
コード例 #2
0
  /**
   * Computes the distance away from the target
   *
   * @param image The image containing the particle to score
   * @param report The Particle Analysis Report for the particle
   * @param particleNumber Particle number in the analysis
   * @param outer Indicates whether the particle aspect ratio should be compared to the ratio for
   *     the inner target or the outer
   * @return Approximate distance from the target
   * @throws NIVisionException
   */
  double computeDistance(
      BinaryImage image, ParticleAnalysisReport report, int particleNumber, boolean outer)
      throws NIVisionException {
    double rectShort, height;
    int targetHeight;
    angle = CommandBase.shooterPitch.getPosition();

    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(angle * Math.PI / (180 * 2)));
  }
コード例 #3
0
  public double getDistance(Target t) {
    boolean debugMyProc = true;
    double result;

    if (debugMyProc) {
      writeDebug("t.rawBboxHeight=" + t.rawBboxHeight);
      writeDebug("Center x, y (" + t.centerX + "," + t.centerY + ")");
      writeDebug("Cornerr x, y (" + t.rawBboxCornerX + "," + t.rawBboxCornerY + ")");
    }
    result = 3185.6 / (t.rawBboxHeight * Math.tan(0.4101));
    return (result * 1.0125);
  }