2 * Copyright 2009 (c) Florian Frankenberger (darkblue.de)
4 * This file is part of LEA.
6 * LEA is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU Lesser General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option) any
11 * LEA is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with LEA. If not, see <http://www.gnu.org/licenses/>.
21 * No description given.
23 * @author Florian Frankenberger
25 public class LEAImplementation {
27 private ClassifierTree classifierTree;
29 private Rectangle2D lastRectangle;
31 public LEAImplementation() {
35 public FaceAndEyePosition getEyePosition(Image image) {
39 Rectangle2D faceRect = classifierTree.locateFaceRadial(image, lastRectangle);
40 System.out.println("FACE RECT=" + faceRect);
41 EyePosition eyePosition = null;
42 if (faceRect != null) {
44 lastRectangle = faceRect;
45 Point point = readEyes(image, faceRect);
47 eyePosition = new EyePosition(point, faceRect);
50 System.out.println("eyePosition="+eyePosition);
52 return new FaceAndEyePosition(faceRect, eyePosition);
55 private Point readEyes(Image image, Rectangle2D rect) {
56 EyeDetector ed = new EyeDetector(image, rect);
57 return ed.detectEye();
60 public boolean needsCalibration() {
65 * This method loads the faceData from a file called facedata.dat which should
66 * be within the jar-file
68 private void loadFaceData() {
70 FileInputStream inputFile = new FileInputStream("facedata.dat");
72 classifierTree = new ClassifierTree();
74 int numClassifier = Integer.parseInt(inputFile.readLine());
75 System.out.println("numClassifier=" + numClassifier);
76 for (int c = 0; c < numClassifier; c++) {
78 int numArea = Integer.parseInt(inputFile.readLine());
79 Classifier classifier = new Classifier(numArea);
81 for (int idx = 0; idx < numArea; idx++) {
83 Point fromPoint = new Point();
84 Point toPoint = new Point();
85 fromPoint.x = Integer.parseInt(inputFile.readLine());
86 fromPoint.y = Integer.parseInt(inputFile.readLine());
87 toPoint.x = Integer.parseInt(inputFile.readLine());
88 toPoint.y = Integer.parseInt(inputFile.readLine());
89 float size = Float.parseFloat(inputFile.readLine());
90 ScanArea area = new ScanArea(fromPoint, toPoint, size);
91 classifier.setScanArea(idx, area);
94 // parsing possibilities face yes
95 float array[] = new float[numArea];
96 for (int idx = 0; idx < numArea; idx++) {
97 array[idx] = Float.parseFloat(inputFile.readLine());
99 classifier.setPossibilitiesFaceYes(array);
101 // parsing possibilities face no
102 array = new float[numArea];
103 for (int idx = 0; idx < numArea; idx++) {
104 array[idx] = Float.parseFloat(inputFile.readLine());
106 classifier.setPossibilitiesFaceNo(array);
108 classifier.setPossibilityFaceYes(Integer.parseInt(inputFile.readLine()));
109 classifier.setPossibilityFaceNo(Integer.parseInt(inputFile.readLine()));
111 classifierTree.addClassifier(classifier);
114 // private Point readEyes(BufferedImage image, Rectangle2D rect) {
116 // // now we cluster the black image points and try to find the inner eye
118 // * BlackHoleDetector bhd = new BlackHoleDetector(image, rect);
121 // * return bhd.getPosition();
124 // EyeDetector ed = new EyeDetector(image, rect);
125 // return ed.detectEye();