Example #1
0
  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);
  }
Example #2
0
  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 float BoxIntegral(IntegralImage img, int row, int col, int rows, int cols) {
    int height = img.getHeight();
    int width = img.getWidth();

    // The subtraction by one for row/col is because row/col is inclusive.
    int r1 = Math.min(row, height) - 1;
    int c1 = Math.min(col, width) - 1;
    int r2 = Math.min(row + rows, height) - 1;
    int c2 = Math.min(col + cols, width) - 1;

    float A = (r1 >= 0 && c1 >= 0) ? img.getValue(c1, r1) : 0;
    float B = (r1 >= 0 && c2 >= 0) ? img.getValue(c2, r1) : 0;
    float C = (r2 >= 0 && c1 >= 0) ? img.getValue(c1, r2) : 0;
    float D = (r2 >= 0 && c2 >= 0) ? img.getValue(c2, r2) : 0;

    //		System.out.println("height = " + height + ", width = " + width);
    //		System.out.println("c1 = " + c1 + ", c2 = " + c2 + ", r1 = " + r1 + ", r2 = " + r2);
    //		System.out.println("A = " + A + ", B = " + B + ", C = " + C + ", D = " + D);

    return Math.max(0F, A - B - C + D);
  }