/** * Loads the Interestpoints from file. * * @param fileName the file name * @return the list */ public static List<InterestPoint> loadFromFile(String fileName) { try { Scanner in = new Scanner(new File(fileName)); int iptsSize = in.nextInt(); List ipts = new ArrayList(iptsSize); for (int i = 0; i < iptsSize; i++) { float x = in.nextFloat(); float y = in.nextFloat(); float strength = in.nextFloat(); float trace = in.nextFloat(); float scale = in.nextFloat(); float ori = in.nextFloat(); int descSize = in.nextInt(); InterestPoint ipt = new InterestPoint(x, y, strength, trace, scale); ipt.orientation = ori; if (descSize > 0) { ipt.descriptor = new float[descSize]; for (int j = 0; j < descSize; j++) ipt.descriptor[j] = in.nextFloat(); } ipts.add(ipt); } in.close(); return ipts; } catch (FileNotFoundException e) { } return null; }
/** * 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; }
/** * Save to Interesting points to a file. This will help us in reducing the computation time while * comparing images. * * @param ipts the ipts * @param fileName the file name * @param inclDescriptor the incl descriptor */ public static void saveToFile(List<InterestPoint> ipts, String fileName, boolean inclDescriptor) { try { PrintWriter out = new PrintWriter(fileName); if ((ipts != null) && (ipts.size() > 0)) { for (InterestPoint ipt : ipts) { if (inclDescriptor) { out.println(ipt); } else { float[] temp = ipt.descriptor; ipt.descriptor = null; out.println(ipt); ipt.descriptor = temp; } } } out.close(); } catch (FileNotFoundException e) { } }