1 import Benchmarks.SSJava.EyeTrackingInfer.EyePosition;
4 * Copyright 2009 (c) Florian Frankenberger (darkblue.de)
6 * This file is part of LEA.
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
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
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/>.
23 * This is the main class of LEA.
25 * It uses a face detection algorithm to find an a face within the provided image(s). Then it
26 * searches for the eye in a region where it most likely located and traces its position relative to
27 * the face and to the last known position. The movements are estimated by comparing more than one
28 * movement. If a movement is distinctly pointing to a direction it is recognized and all listeners
31 * The notification is designed as observer pattern. You simply call
32 * <code>addEyeMovementListener(IEyeMovementListener)</code> to add an implementation of
33 * <code>IEyeMovementListener</code> to LEA. When a face is recognized/lost or whenever an eye
34 * movement is detected LEA will call the appropriate methods of the listener
36 * LEA also needs an image source implementing the <code>ICaptureDevice</code>. One image source
37 * proxy to the <code>Java Media Framework</code> is included ( <code>JMFCaptureDevice</code>).
39 * Example (for using LEA with <code>Java Media Framework</code>):
42 * LEA lea = new LEA(new JMFCaptureDevice(), true);
45 * This will start LEA with the first available JMF datasource with an extra status window showing
46 * if face/eye has been detected successfully. Please note that face detection needs about 2 seconds
47 * to find a face. After detection the following face detection is much faster.
49 * @author Florian Frankenberger
51 @LATTICE("LAST<DEV,DEV<E,E<POS,POS<IMPL")
52 @METHODDEFAULT("OUT<THIS,THIS<IN,THISLOC=THIS,RETURNLOC=OUT")
56 private LEAImplementation implementation;
58 private DeviationScanner deviationScanner = new DeviationScanner();
61 // this.imageProcessor = new
62 // ImageProcessor(this.captureDevice.getFrameRate());
63 implementation = new LEAImplementation();
67 * Clears the internal movement buffer. If you just capture some of the eye movements you should
68 * call this every time you start recording the movements. Otherwise you may get notified for
69 * movements that took place BEFORE you started recording.
72 // this.imageProcessor.clearDeviationScanner();
76 * @METHOD To test LEA with the first capture device from the <code>Java Media Framework</code>
77 * just start from here.
82 public static void main(String[] args) throws Exception {
87 @LATTICE("THIS<IMG,IMG<C,C*,THISLOC=THIS")
92 SSJAVA: while (true) {
93 @LOC("IMG") Image image = ImageReader.getImage();
100 System.out.println("Done.");
104 private void processImage(@LOC("IN") Image image) {
105 @LOC("THIS,LEA.POS") FaceAndEyePosition positions = implementation.getEyePosition(image);
106 deviationScanner.addEyePosition(positions.getEyePosition().getX(), positions.getEyePosition()
108 @LOC("THIS,LEA.DEV,DeviationScanner.DEV") int deviation =
109 deviationScanner.scanForDeviation(positions.getFacePosition());// positions.getEyePosition().getDeviation(lastPositions.getEyePosition());
110 if (deviation != DeviationScanner.NONE) {
111 System.out.println("deviation=" + deviationScanner.toStringDeviation(deviation));
112 // notifyEyeMovementListenerEyeMoved(deviation);