add eye tracking benchmark.
[IRC.git] / Robust / src / Benchmarks / SSJava / EyeTracking / LEA.java
1 import Benchmarks.oooJava.barneshut.FileInputStream;
2
3 /*
4  * Copyright 2009 (c) Florian Frankenberger (darkblue.de)
5  * 
6  * This file is part of LEA.
7  * 
8  * LEA is free software: you can redistribute it and/or modify it under the
9  * terms of the GNU Lesser General Public License as published by the Free
10  * Software Foundation, either version 3 of the License, or (at your option) any
11  * later version.
12  * 
13  * LEA is distributed in the hope that it will be useful, but WITHOUT ANY
14  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15  * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with LEA. If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 /**
23  * This is the main class of LEA.
24  * <p>
25  * It uses a face detection algorithm to find an a face within the provided
26  * image(s). Then it searches for the eye in a region where it most likely
27  * located and traces its position relative to the face and to the last known
28  * position. The movements are estimated by comparing more than one movement. If
29  * a movement is distinctly pointing to a direction it is recognized and all
30  * listeners get notified.
31  * <p>
32  * The notification is designed as observer pattern. You simply call
33  * <code>addEyeMovementListener(IEyeMovementListener)</code> to add an
34  * implementation of <code>IEyeMovementListener</code> to LEA. When a face is
35  * recognized/lost or whenever an eye movement is detected LEA will call the
36  * appropriate methods of the listener
37  * <p>
38  * LEA also needs an image source implementing the <code>ICaptureDevice</code>.
39  * One image source proxy to the <code>Java Media Framework</code> is included (
40  * <code>JMFCaptureDevice</code>).
41  * <p>
42  * Example (for using LEA with <code>Java Media Framework</code>):
43  * <p>
44  * <code>
45  * LEA lea = new LEA(new JMFCaptureDevice(), true);
46  * </code>
47  * <p>
48  * This will start LEA with the first available JMF datasource with an extra
49  * status window showing if face/eye has been detected successfully. Please note
50  * that face detection needs about 2 seconds to find a face. After detection the
51  * following face detection is much faster.
52  * 
53  * @author Florian Frankenberger
54  */
55 public class LEA {
56
57   private boolean showStatusWindow;
58
59   private boolean shutdown = false;
60
61   // private LEAImplementation implementation = new LEAImplementation();
62
63   // private ImageProcessor imageProcessor;
64   //
65   // private class ImageProcessor extends TimedThread {
66   //
67   // private FaceAndEyePosition lastPositions = new FaceAndEyePosition(null,
68   // null);
69   // private DeviationScanner deviationScanner = new DeviationScanner();
70   // private int counter = 0;
71   //
72   // private int fps;
73   //
74   // public ImageProcessor(int fps) {
75   // super(fps);
76   // this.fps = fps;
77   // }
78   //
79   // @Override
80   // public void doRun() {
81   //
82   // BufferedImage image = captureDevice.getImage();
83   // if (image == null)
84   // return;
85   //
86   // try {
87   // FaceAndEyePosition positions = implementation.getEyePosition(image);
88   //
89   // if (((lastPositions.getFacePosition() == null &&
90   // positions.getFacePosition() != null) || (lastPositions
91   // .getFacePosition() != null && positions.getFacePosition() == null)) ||
92   // counter++ > fps) {
93   //
94   // if ((lastPositions.getFacePosition() == null && positions.getFacePosition()
95   // != null)
96   // || (lastPositions.getFacePosition() != null && positions.getFacePosition()
97   // == null)) {
98   // if (positions.getFacePosition() != null) {
99   // notifyEyeMovementListenerFaceDetected();
100   // } else {
101   // notifyEyeMovementListenerFaceLost();
102   // }
103   // }
104   // counter = 0;
105   // if (statusWindow != null)
106   // statusWindow.getFaceInfoPanel().setFace(image,
107   // positions.getFacePosition());
108   // }
109   //
110   // if (positions.getEyePosition() != null) {
111   // if (statusWindow != null) {
112   // statusWindow.getEyeInfoPanel().setEyePosition(image,
113   // positions.getFacePosition(),
114   // positions.getEyePosition());
115   // }
116   // deviationScanner.addEyePosition(positions.getEyePosition());
117   // Deviation deviation =
118   // deviationScanner.scanForDeviation(positions.getFacePosition());//
119   // positions.getEyePosition().getDeviation(lastPositions.getEyePosition());
120   //
121   // if (deviation != Deviation.NONE) {
122   // notifyEyeMovementListenerEyeMoved(deviation);
123   // }
124   //
125   // } else {
126   // if (statusWindow != null)
127   // statusWindow.getEyeInfoPanel().setDeviation(null);
128   // }
129   //
130   // lastPositions = positions;
131   // } catch (Exception e) {
132   // e.printStackTrace();
133   // try {
134   // close();
135   // } catch (Exception e2) {
136   // }
137   // }
138   // }
139   //
140   // public synchronized void clearDeviationScanner() {
141   // this.deviationScanner.clear();
142   // }
143   //
144   // }
145
146   public LEA() {
147     // this.imageProcessor = new
148     // ImageProcessor(this.captureDevice.getFrameRate());
149     // this.imageProcessor.start();
150     LEAImplementation impl = new LEAImplementation();
151     System.out.println("Done.");
152   }
153
154   /**
155    * Clears the internal movement buffer. If you just capture some of the eye
156    * movements you should call this every time you start recording the
157    * movements. Otherwise you may get notified for movements that took place
158    * BEFORE you started recording.
159    */
160   public void clear() {
161     // this.imageProcessor.clearDeviationScanner();
162   }
163
164   /**
165    * To test LEA with the first capture device from the
166    * <code>Java Media Framework</code> just start from here.
167    * 
168    * @param args
169    * @throws Exception
170    */
171   public static void main(String[] args) throws Exception {
172     LEA lea = new LEA();
173
174   }
175
176 }