changes: 1) fixes problems in the original EyeTracking benchmark 2) fix a bug in...
[IRC.git] / Robust / src / Benchmarks / SSJava / EyeTrackingInfer / LEAImplementation.java
1 /*
2  * Copyright 2009 (c) Florian Frankenberger (darkblue.de)
3  * 
4  * This file is part of LEA.
5  * 
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
9  * later version.
10  * 
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
14  * details.
15  * 
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/>.
18  */
19
20 /**
21  * No description given.
22  * 
23  * @author Florian Frankenberger
24  */
25
26
27 public class LEAImplementation {
28
29   
30   private ClassifierTree classifierTree;
31
32
33   public LEAImplementation() {
34     this.loadFaceData();
35   }
36
37   
38   
39   public FaceAndEyePosition getEyePosition( Image image) {
40     return classifierTree.getEyePosition(image);
41   }
42
43   public boolean needsCalibration() {
44     return false;
45   }
46
47   /**
48    * This method loads the faceData from a file called facedata.dat which should be within the
49    * jar-file
50    */
51   private void loadFaceData() {
52
53     FileInputStream inputFile = new FileInputStream("facedata.dat");
54
55     int numClassifier = Integer.parseInt(inputFile.readLine());
56     classifierTree = new ClassifierTree(numClassifier);
57     for (int c = 0; c < numClassifier; c++) {
58
59       int numArea = Integer.parseInt(inputFile.readLine());
60       Classifier classifier = new Classifier(numArea);
61       // parsing areas
62       for (int idx = 0; idx < numArea; idx++) {
63         // 54,54,91,62,296.0
64         Point fromPoint = new Point();
65         Point toPoint = new Point();
66         fromPoint.x = Integer.parseInt(inputFile.readLine());
67         fromPoint.y = Integer.parseInt(inputFile.readLine());
68         toPoint.x = Integer.parseInt(inputFile.readLine());
69         toPoint.y = Integer.parseInt(inputFile.readLine());
70         float size = Float.parseFloat(inputFile.readLine());
71         ScanArea area = new ScanArea(fromPoint, toPoint, size);
72         classifier.setScanArea(idx, area);
73       }
74
75       // parsing possibilities face yes
76       float array[] = new float[numArea];
77       for (int idx = 0; idx < numArea; idx++) {
78         array[idx] = Float.parseFloat(inputFile.readLine());
79       }
80       classifier.setPossibilitiesFaceYes(array);
81
82       // parsing possibilities face no
83       array = new float[numArea];
84       for (int idx = 0; idx < numArea; idx++) {
85         array[idx] = Float.parseFloat(inputFile.readLine());
86       }
87       classifier.setPossibilitiesFaceNo(array);
88
89       classifier.setPossibilityFaceYes(Integer.parseInt(inputFile.readLine()));
90       classifier.setPossibilityFaceNo(Integer.parseInt(inputFile.readLine()));
91
92       classifierTree.addClassifier(c, classifier);
93     }
94   }
95
96 }