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

import ac.essex.gp.multiclass.PCM;
import ac.essex.gp.multiclass.BetterDRS;
import ac.essex.ooechs.imaging.commons.fast.HaarlikeFeatures;
import ac.essex.ooechs.imaging.commons.HaarRegions;
import ac.essex.ooechs.imaging.commons.PixelLoader;
import ac.essex.ooechs.adaboost.AdaBoostSolution;
import ac.essex.ooechs.adaboost.AdaBoostSample;
import ac.essex.ooechs.facedetection.singlestage.nodes.FeatureUtils;

import java.io.File;

/**
 * <p/>
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version,
 * provided that any use properly credits the author.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details at http://www.gnu.org
 * </p>
 *
 * @author Olly Oechsle, University of Essex, Date: 03-Jul-2008
 * @version 1.0
 */
public class EyeDetector extends ObjectDetector {

    protected AdaBoostSolution s;

    public EyeDetector() {
        try {
            s = AdaBoostSolution.load(new File(System.getProperty("user.dir") + System.getProperty("file.separator") + "eyedetector.solution"));
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("Cannot load eye detector");
        }
    }

    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;
            return s.classify(new AdaBoostSample(img.getIntegralImage()), null);
        } catch (ArrayIndexOutOfBoundsException e) {
            return ObjectDetector.NOT_OBJECT;
        }
    }



}
