bf5c4978bac0829dcd371d34950c97d5f802f992
[IRC.git] / Robust / src / Benchmarks / SSJava / EyeTracking / 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 @LATTICE("R<CT,R*")
26 @METHODDEFAULT("OUT<THIS,THIS<IN,THISLOC=THIS,RETURNLOC=OUT")
27 public class LEAImplementation {
28
29   @LOC("CT")
30   private ClassifierTree classifierTree;
31
32   public LEAImplementation() {
33     this.loadFaceData();
34   }
35
36   @LATTICE("OUT<V,V<THIS,THIS<IN,V*,THISLOC=THIS,RETURNLOC=OUT")
37   @PCLOC("THIS")
38   public FaceAndEyePosition getEyePosition(@LOC("IN") Image image) {
39     return classifierTree.getEyePosition(image);
40   }
41
42   public boolean needsCalibration() {
43     return false;
44   }
45
46   /**
47    * This method loads the faceData from a file called facedata.dat which should be within the
48    * jar-file
49    */
50   private void loadFaceData() {
51
52     FileInputStream inputFile = new FileInputStream("facedata.dat");
53
54     int numClassifier = Integer.parseInt(inputFile.readLine());
55     classifierTree = new ClassifierTree(numClassifier);
56     for (int c = 0; c < numClassifier; c++) {
57
58       int numArea = Integer.parseInt(inputFile.readLine());
59       Classifier classifier = new Classifier(numArea);
60       // parsing areas
61       for (int idx = 0; idx < numArea; idx++) {
62         // 54,54,91,62,296.0
63         Point fromPoint = new Point();
64         Point toPoint = new Point();
65         fromPoint.x = Integer.parseInt(inputFile.readLine());
66         fromPoint.y = Integer.parseInt(inputFile.readLine());
67         toPoint.x = Integer.parseInt(inputFile.readLine());
68         toPoint.y = Integer.parseInt(inputFile.readLine());
69         float size = Float.parseFloat(inputFile.readLine());
70         ScanArea area = new ScanArea(fromPoint, toPoint, size);
71         classifier.setScanArea(idx, area);
72       }
73
74       // parsing possibilities face yes
75       float array[] = new float[numArea];
76       for (int idx = 0; idx < numArea; idx++) {
77         array[idx] = Float.parseFloat(inputFile.readLine());
78       }
79       classifier.setPossibilitiesFaceYes(array);
80
81       // parsing possibilities face no
82       array = new float[numArea];
83       for (int idx = 0; idx < numArea; idx++) {
84         array[idx] = Float.parseFloat(inputFile.readLine());
85       }
86       classifier.setPossibilitiesFaceNo(array);
87
88       classifier.setPossibilityFaceYes(Integer.parseInt(inputFile.readLine()));
89       classifier.setPossibilityFaceNo(Integer.parseInt(inputFile.readLine()));
90
91       classifierTree.addClassifier(c, classifier);
92     }
93   }
94
95 }