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 EyePosition eyePosition = null;
41 if (faceRect != null) {
42 lastRectangle = faceRect;
44 Point point = readEyes(image, lastRectangle);
46 eyePosition = new EyePosition(point, lastRectangle);
49 System.out.println("eyePosition=" + eyePosition);
51 return new FaceAndEyePosition(lastRectangle, eyePosition);
54 private Point readEyes(Image image, Rectangle2D rect) {
55 EyeDetector ed = new EyeDetector(image, rect);
56 return ed.detectEye();
59 public boolean needsCalibration() {
64 * This method loads the faceData from a file called facedata.dat which should
65 * be within the jar-file
67 private void loadFaceData() {
69 FileInputStream inputFile = new FileInputStream("facedata.dat");
71 int numClassifier = Integer.parseInt(inputFile.readLine());
72 classifierTree = new ClassifierTree(numClassifier);
73 for (int c = 0; c < numClassifier; c++) {
75 int numArea = Integer.parseInt(inputFile.readLine());
76 Classifier classifier = new Classifier(numArea);
78 for (int idx = 0; idx < numArea; idx++) {
80 Point fromPoint = new Point();
81 Point toPoint = new Point();
82 fromPoint.x = Integer.parseInt(inputFile.readLine());
83 fromPoint.y = Integer.parseInt(inputFile.readLine());
84 toPoint.x = Integer.parseInt(inputFile.readLine());
85 toPoint.y = Integer.parseInt(inputFile.readLine());
86 float size = Float.parseFloat(inputFile.readLine());
87 ScanArea area = new ScanArea(fromPoint, toPoint, size);
88 classifier.setScanArea(idx, area);
91 // parsing possibilities face yes
92 float array[] = new float[numArea];
93 for (int idx = 0; idx < numArea; idx++) {
94 array[idx] = Float.parseFloat(inputFile.readLine());
96 classifier.setPossibilitiesFaceYes(array);
98 // parsing possibilities face no
99 array = new float[numArea];
100 for (int idx = 0; idx < numArea; idx++) {
101 array[idx] = Float.parseFloat(inputFile.readLine());
103 classifier.setPossibilitiesFaceNo(array);
105 classifier.setPossibilityFaceYes(Integer.parseInt(inputFile.readLine()));
106 classifier.setPossibilityFaceNo(Integer.parseInt(inputFile.readLine()));
108 classifierTree.addClassifier(c, classifier);