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) {
43 @LOC("THIS,LEAImplementation.R") Rectangle2D faceRect =
44 classifierTree.locateFaceRadial(image, lastRectangle);
45 if (faceRect.getWidth() > image.getWidth() || faceRect.getHeight() > image.getHeight()) {
48 @LOC("V") EyePosition eyePosition = null;
49 if (faceRect != null) {
50 lastRectangle = faceRect;
52 @LOC("V") Point point = readEyes(image, lastRectangle);
54 eyePosition = new EyePosition(point, lastRectangle);
59 System.out.println("eyePosition=" + eyePosition);
61 return new FaceAndEyePosition(lastRectangle, eyePosition);
64 @LATTICE("OUT<IN,OUT<THIS,THISLOC=THIS,RETURNLOC=OUT")
65 private Point readEyes(@LOC("IN") Image image, @LOC("IN") Rectangle2D rect) {
66 @LOC("OUT") EyeDetector ed = new EyeDetector(image, rect);
67 return ed.detectEye();
70 public boolean needsCalibration() {
75 * This method loads the faceData from a file called facedata.dat which should
76 * be within the jar-file
78 private void loadFaceData() {
80 FileInputStream inputFile = new FileInputStream("facedata.dat");
82 int numClassifier = Integer.parseInt(inputFile.readLine());
83 classifierTree = new ClassifierTree(numClassifier);
84 for (int c = 0; c < numClassifier; c++) {
86 int numArea = Integer.parseInt(inputFile.readLine());
87 Classifier classifier = new Classifier(numArea);
89 for (int idx = 0; idx < numArea; idx++) {
91 Point fromPoint = new Point();
92 Point toPoint = new Point();
93 fromPoint.x = Integer.parseInt(inputFile.readLine());
94 fromPoint.y = Integer.parseInt(inputFile.readLine());
95 toPoint.x = Integer.parseInt(inputFile.readLine());
96 toPoint.y = Integer.parseInt(inputFile.readLine());
97 float size = Float.parseFloat(inputFile.readLine());
98 ScanArea area = new ScanArea(fromPoint, toPoint, size);
99 classifier.setScanArea(idx, area);
102 // parsing possibilities face yes
103 float array[] = new float[numArea];
104 for (int idx = 0; idx < numArea; idx++) {
105 array[idx] = Float.parseFloat(inputFile.readLine());
107 classifier.setPossibilitiesFaceYes(array);
109 // parsing possibilities face no
110 array = new float[numArea];
111 for (int idx = 0; idx < numArea; idx++) {
112 array[idx] = Float.parseFloat(inputFile.readLine());
114 classifier.setPossibilitiesFaceNo(array);
116 classifier.setPossibilityFaceYes(Integer.parseInt(inputFile.readLine()));
117 classifier.setPossibilityFaceNo(Integer.parseInt(inputFile.readLine()));
119 classifierTree.addClassifier(c, classifier);