package ac.essex.ooechs.facedetection.util.evaluation;

import ac.essex.ooechs.adaboost.AdaBoostSolution;
import ac.essex.ooechs.adaboost.AdaBoostSample;
import ac.essex.ooechs.imaging.commons.PixelLoader;
import ac.essex.ooechs.imaging.commons.fast.IntegralImage;
import ac.essex.ooechs.facedetection.singlestage.nodes.FeatureUtils;

import java.io.File;

/**
 * Object detector implementation using an adaboosted solution instead of java code.
 *
 * @author Olly Oechsle, University of Essex, Date: 10-Jul-2008
 * @version 1.0
 */
public class BoostedObjectDetector extends ObjectDetector {

    protected AdaBoostSolution s;

    public BoostedObjectDetector(AdaBoostSolution s)  {
        this.s = s;
    }

    public double calculate(int x, int y, int windowWidth, int windowHeight, PixelLoader img) {
        try {
            FeatureUtils.windowX = x;
            FeatureUtils.windowY = y;
            FeatureUtils.windowWidth = windowWidth;
            FeatureUtils.windowHeight = windowHeight;
            IntegralImage image = img.getIntegralImage();
            return s.classify(new AdaBoostSample(image), null);
        } catch (ArrayIndexOutOfBoundsException e) {
            return ObjectDetector.NOT_OBJECT;
        }
    }

}
