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")
41 public FaceAndEyePosition getEyePosition(@LOC("IN") Image image) {
44 @LOC("THIS,LEAImplementation.R") Rectangle2D faceRect =
45 classifierTree.locateFaceRadial(image, lastRectangle);
46 if (faceRect.getWidth() > image.getWidth() || faceRect.getHeight() > image.getHeight()) {
49 @LOC("V") EyePosition eyePosition = null;
50 if (faceRect != null) {
51 lastRectangle = faceRect;
53 @LOC("V") Point point = readEyes(image, lastRectangle);
55 eyePosition = new EyePosition(point, lastRectangle);
60 System.out.println("eyePosition=" + eyePosition);
62 return new FaceAndEyePosition(lastRectangle, eyePosition);
65 @LATTICE("OUT<P,P<IN,OUT<THIS,THISLOC=THIS,RETURNLOC=OUT")
67 private Point readEyes(@LOC("IN") Image image, @LOC("IN") Rectangle2D rect) {
68 @LOC("OUT") EyeDetector ed = new EyeDetector(image, rect);
69 return ed.detectEye();
72 public boolean needsCalibration() {
77 * This method loads the faceData from a file called facedata.dat which should
78 * be within the jar-file
80 private void loadFaceData() {
82 FileInputStream inputFile = new FileInputStream("facedata.dat");
84 int numClassifier = Integer.parseInt(inputFile.readLine());
85 classifierTree = new ClassifierTree(numClassifier);
86 for (int c = 0; c < numClassifier; c++) {
88 int numArea = Integer.parseInt(inputFile.readLine());
89 Classifier classifier = new Classifier(numArea);
91 for (int idx = 0; idx < numArea; idx++) {
93 Point fromPoint = new Point();
94 Point toPoint = new Point();
95 fromPoint.x = Integer.parseInt(inputFile.readLine());
96 fromPoint.y = Integer.parseInt(inputFile.readLine());
97 toPoint.x = Integer.parseInt(inputFile.readLine());
98 toPoint.y = Integer.parseInt(inputFile.readLine());
99 float size = Float.parseFloat(inputFile.readLine());
100 ScanArea area = new ScanArea(fromPoint, toPoint, size);
101 classifier.setScanArea(idx, area);
104 // parsing possibilities face yes
105 float array[] = new float[numArea];
106 for (int idx = 0; idx < numArea; idx++) {
107 array[idx] = Float.parseFloat(inputFile.readLine());
109 classifier.setPossibilitiesFaceYes(array);
111 // parsing possibilities face no
112 array = new float[numArea];
113 for (int idx = 0; idx < numArea; idx++) {
114 array[idx] = Float.parseFloat(inputFile.readLine());
116 classifier.setPossibilitiesFaceNo(array);
118 classifier.setPossibilityFaceYes(Integer.parseInt(inputFile.readLine()));
119 classifier.setPossibilityFaceNo(Integer.parseInt(inputFile.readLine()));
121 classifierTree.addClassifier(c, classifier);