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
26 public class LEAImplementation {
28 private ClassifierTree classifierTree;
30 private Rectangle2D lastRectangle;
32 public LEAImplementation() {
36 public FaceAndEyePosition getEyePosition(Image image) {
39 Rectangle2D faceRect = classifierTree.locateFaceRadial(image, lastRectangle);
40 if (faceRect.getWidth() > image.getWidth() || faceRect.getHeight() > image.getHeight()) {
43 EyePosition eyePosition = null;
44 if (faceRect != null) {
45 lastRectangle = faceRect;
47 Point point = readEyes(image, lastRectangle);
49 eyePosition = new EyePosition(point, lastRectangle);
54 System.out.println("eyePosition=" + eyePosition);
56 return new FaceAndEyePosition(lastRectangle, eyePosition);
59 private Point readEyes(Image image, Rectangle2D rect) {
60 EyeDetector ed = new EyeDetector(image, rect);
61 return ed.detectEye();
64 public boolean needsCalibration() {
69 * This method loads the faceData from a file called facedata.dat which should be within the
72 private void loadFaceData() {
74 FileInputStream inputFile = new FileInputStream("facedata.dat");
76 int numClassifier = Integer.parseInt(inputFile.readLine());
77 classifierTree = new ClassifierTree(numClassifier);
78 for (int c = 0; c < numClassifier; c++) {
80 int numArea = Integer.parseInt(inputFile.readLine());
81 Classifier classifier = new Classifier(numArea);
83 for (int idx = 0; idx < numArea; idx++) {
85 Point fromPoint = new Point();
86 Point toPoint = new Point();
87 fromPoint.x = Integer.parseInt(inputFile.readLine());
88 fromPoint.y = Integer.parseInt(inputFile.readLine());
89 toPoint.x = Integer.parseInt(inputFile.readLine());
90 toPoint.y = Integer.parseInt(inputFile.readLine());
91 float size = Float.parseFloat(inputFile.readLine());
92 ScanArea area = new ScanArea(fromPoint, toPoint, size);
93 classifier.setScanArea(idx, area);
96 // parsing possibilities face yes
97 float array[] = new float[numArea];
98 for (int idx = 0; idx < numArea; idx++) {
99 array[idx] = Float.parseFloat(inputFile.readLine());
101 classifier.setPossibilitiesFaceYes(array);
103 // parsing possibilities face no
104 array = new float[numArea];
105 for (int idx = 0; idx < numArea; idx++) {
106 array[idx] = Float.parseFloat(inputFile.readLine());
108 classifier.setPossibilitiesFaceNo(array);
110 classifier.setPossibilityFaceYes(Integer.parseInt(inputFile.readLine()));
111 classifier.setPossibilityFaceNo(Integer.parseInt(inputFile.readLine()));
113 classifierTree.addClassifier(c, classifier);