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 * This is the main class of LEA.
23 * It uses a face detection algorithm to find an a face within the provided image(s). Then it
24 * searches for the eye in a region where it most likely located and traces its position relative to
25 * the face and to the last known position. The movements are estimated by comparing more than one
26 * movement. If a movement is distinctly pointing to a direction it is recognized and all listeners
29 * The notification is designed as observer pattern. You simply call
30 * <code>addEyeMovementListener(IEyeMovementListener)</code> to add an implementation of
31 * <code>IEyeMovementListener</code> to LEA. When a face is recognized/lost or whenever an eye
32 * movement is detected LEA will call the appropriate methods of the listener
34 * LEA also needs an image source implementing the <code>ICaptureDevice</code>. One image source
35 * proxy to the <code>Java Media Framework</code> is included ( <code>JMFCaptureDevice</code>).
37 * Example (for using LEA with <code>Java Media Framework</code>):
40 * LEA lea = new LEA(new JMFCaptureDevice(), true);
43 * This will start LEA with the first available JMF datasource with an extra status window showing
44 * if face/eye has been detected successfully. Please note that face detection needs about 2 seconds
45 * to find a face. After detection the following face detection is much faster.
47 * @author Florian Frankenberger
52 private LEAImplementation implementation;
54 private FaceAndEyePosition lastPositions = new FaceAndEyePosition(null, null);
56 private DeviationScanner deviationScanner = new DeviationScanner();
59 // this.imageProcessor = new
60 // ImageProcessor(this.captureDevice.getFrameRate());
61 implementation = new LEAImplementation();
65 * Clears the internal movement buffer. If you just capture some of the eye movements you should
66 * call this every time you start recording the movements. Otherwise you may get notified for
67 * movements that took place BEFORE you started recording.
70 // this.imageProcessor.clearDeviationScanner();
74 * @METHOD To test LEA with the first capture device from the <code>Java Media Framework</code>
75 * just start from here.
80 public static void main(String[] args) throws Exception {
89 SSJAVA: while (true) {
90 Image image = ImageReader.getImage();
97 System.out.println("Done.");
101 private void processImage(Image image) {
102 FaceAndEyePosition positions = implementation.getEyePosition(image);
103 // if (positions.getEyePosition() != null) {
104 deviationScanner.addEyePosition(positions.getEyePosition());
105 int deviation = deviationScanner.scanForDeviation(positions.getFacePosition());// positions.getEyePosition().getDeviation(lastPositions.getEyePosition());
106 if (deviation != DeviationScanner.NONE) {
107 System.out.println("deviation=" + deviationScanner.toStringDeviation(deviation));
108 // notifyEyeMovementListenerEyeMoved(deviation);
111 lastPositions = positions;