private static void loadGifsAtDirectoryIntoVector(Vector<IntegralImage> images, File directory) { for (File file : directory.listFiles()) { String fileName = file.getName(); String extension = ""; String firstTwoChars = fileName.substring(0, 2); int i = fileName.lastIndexOf('.'); if (i > 0) { extension = fileName.substring(i + 1); } if (!firstTwoChars.equals("._") && extension.equals("gif")) { BufferedImage img = null; try { // System.out.println("file = " + file); img = ImageIO.read(file); ImageProcessor imageProcessor = new ByteProcessor(img); IntegralImage ii = new IntegralImage(imageProcessor); ii.name = fileName; images.add(ii); } catch (IOException e) { } } } }
public static void testTargetFeaturesAgainstImages( Vector<HaarFeature> features, Vector<IntegralImage> images) { int numberOfTrue = 0; int numberOfFalse = 0; for (IntegralImage ii : images) { float weightSum = 0.0f; float sum = 0.0f; for (HaarFeature hf : features) { // HaarFeature hf = allFeatures.get(slimFeature.featureNumber); // hf.threshold = slimFeature.threshold; float v = hf.weight * ii.evaluateAsClassifier(hf); sum += v; weightSum += hf.weight; } boolean success = (sum >= weightSum * 0.5f); // System.out.println("image " + ii.name + " is a " + success + " : " + sum + " > " + // weightSum*0.5f); if (success) { numberOfTrue++; } else { numberOfFalse++; } } System.out.println("*************"); System.out.println("true: " + numberOfTrue); System.out.println("false: " + numberOfFalse); int min = Math.min(numberOfFalse, numberOfTrue); int max = Math.max(numberOfFalse, numberOfTrue); float percentError = min * 100.0f / max; System.out.println("percentError = " + percentError); }