Ejemplo n.º 1
0
  /**
   * Find mathes.
   *
   * @param ipts1 the ipts1
   * @param ipts2 the ipts2
   * @return the map
   */
  public static Map<InterestPoint, InterestPoint> findMathes(
      List<InterestPoint> ipts1, List<InterestPoint> ipts2) {
    Map<InterestPoint, InterestPoint> res = new HashMap<InterestPoint, InterestPoint>();

    int descSize = 64;

    for (InterestPoint p1 : ipts1) {
      float secondBest;
      float bestDistance = secondBest = 3.4028235E+38F;
      InterestPoint bestMatch = null;

      for (InterestPoint p2 : ipts2) {
        if (p1.sign != p2.sign) {
          continue;
        }
        float distance = 0.0F;
        float[] v1 = p1.descriptor;
        float[] v2 = p2.descriptor;
        float delta;
        int i = 0;
        while (i < v1.length && i < v2.length) {
          delta = v1[i] - v2[i];
          distance += delta * delta;
          if (distance >= secondBest) break;
          i++;
          if (i < descSize) {
            continue;
          }

          if (distance < bestDistance) {
            secondBest = bestDistance;
            bestDistance = distance;
            bestMatch = p2;
          } else {
            secondBest = distance;
          }
        }
      }

      if (bestDistance >= 0.5F * secondBest) {
        continue;
      }
      res.put(p1, bestMatch);

      bestMatch.dx = (bestMatch.xpos - p1.xpos);
      bestMatch.dy = (bestMatch.ypos - p1.ypos);
    }

    return res;
  }