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 @METHODDEFAULT("OUT<THIS,THIS<IN,THISLOC=THIS,RETURNLOC=OUT")
27 public class LEAImplementation {
30 private ClassifierTree classifierTree;
33 private Rectangle2D lastRectangle;
35 public LEAImplementation() {
39 @LATTICE("OUT<V,V<THIS,THIS<IN,V*,THISLOC=THIS,RETURNLOC=OUT")
40 public FaceAndEyePosition getEyePosition(@LOC("IN") Image image) {
44 @LOC("THIS,LEAImplementation.R") Rectangle2D faceRect =
45 classifierTree.locateFaceRadial(image, lastRectangle);
46 @LOC("V") EyePosition eyePosition = null;
47 if (faceRect != null) {
48 lastRectangle = faceRect;
50 @LOC("V") Point point = readEyes(image, lastRectangle);
52 eyePosition = new EyePosition(point, lastRectangle);
57 System.out.println("eyePosition=" + eyePosition);
59 return new FaceAndEyePosition(lastRectangle, eyePosition);
62 @LATTICE("OUT<IN,OUT<THIS,THISLOC=THIS,RETURNLOC=OUT")
63 private Point readEyes(@LOC("IN") Image image, @LOC("IN") Rectangle2D rect) {
64 @LOC("OUT") EyeDetector ed = new EyeDetector(image, rect);
65 return ed.detectEye();
68 public boolean needsCalibration() {
73 * This method loads the faceData from a file called facedata.dat which should
74 * be within the jar-file
76 private void loadFaceData() {
78 FileInputStream inputFile = new FileInputStream("facedata.dat");
80 int numClassifier = Integer.parseInt(inputFile.readLine());
81 classifierTree = new ClassifierTree(numClassifier);
82 for (int c = 0; c < numClassifier; c++) {
84 int numArea = Integer.parseInt(inputFile.readLine());
85 Classifier classifier = new Classifier(numArea);
87 for (int idx = 0; idx < numArea; idx++) {
89 Point fromPoint = new Point();
90 Point toPoint = new Point();
91 fromPoint.x = Integer.parseInt(inputFile.readLine());
92 fromPoint.y = Integer.parseInt(inputFile.readLine());
93 toPoint.x = Integer.parseInt(inputFile.readLine());
94 toPoint.y = Integer.parseInt(inputFile.readLine());
95 float size = Float.parseFloat(inputFile.readLine());
96 ScanArea area = new ScanArea(fromPoint, toPoint, size);
97 classifier.setScanArea(idx, area);
100 // parsing possibilities face yes
101 float array[] = new float[numArea];
102 for (int idx = 0; idx < numArea; idx++) {
103 array[idx] = Float.parseFloat(inputFile.readLine());
105 classifier.setPossibilitiesFaceYes(array);
107 // parsing possibilities face no
108 array = new float[numArea];
109 for (int idx = 0; idx < numArea; idx++) {
110 array[idx] = Float.parseFloat(inputFile.readLine());
112 classifier.setPossibilitiesFaceNo(array);
114 classifier.setPossibilityFaceYes(Integer.parseInt(inputFile.readLine()));
115 classifier.setPossibilityFaceNo(Integer.parseInt(inputFile.readLine()));
117 classifierTree.addClassifier(c, classifier);