1 import Benchmarks.oooJava.barneshut.FileInputStream;
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
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.
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
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>).
42 * Example (for using LEA with <code>Java Media Framework</code>):
45 * LEA lea = new LEA(new JMFCaptureDevice(), true);
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.
53 * @author Florian Frankenberger
57 private boolean showStatusWindow;
59 private boolean shutdown = false;
61 // private LEAImplementation implementation = new LEAImplementation();
63 // private ImageProcessor imageProcessor;
65 // private class ImageProcessor extends TimedThread {
67 // private FaceAndEyePosition lastPositions = new FaceAndEyePosition(null,
69 // private DeviationScanner deviationScanner = new DeviationScanner();
70 // private int counter = 0;
74 // public ImageProcessor(int fps) {
80 // public void doRun() {
82 // BufferedImage image = captureDevice.getImage();
87 // FaceAndEyePosition positions = implementation.getEyePosition(image);
89 // if (((lastPositions.getFacePosition() == null &&
90 // positions.getFacePosition() != null) || (lastPositions
91 // .getFacePosition() != null && positions.getFacePosition() == null)) ||
94 // if ((lastPositions.getFacePosition() == null && positions.getFacePosition()
96 // || (lastPositions.getFacePosition() != null && positions.getFacePosition()
98 // if (positions.getFacePosition() != null) {
99 // notifyEyeMovementListenerFaceDetected();
101 // notifyEyeMovementListenerFaceLost();
105 // if (statusWindow != null)
106 // statusWindow.getFaceInfoPanel().setFace(image,
107 // positions.getFacePosition());
110 // if (positions.getEyePosition() != null) {
111 // if (statusWindow != null) {
112 // statusWindow.getEyeInfoPanel().setEyePosition(image,
113 // positions.getFacePosition(),
114 // positions.getEyePosition());
116 // deviationScanner.addEyePosition(positions.getEyePosition());
117 // Deviation deviation =
118 // deviationScanner.scanForDeviation(positions.getFacePosition());//
119 // positions.getEyePosition().getDeviation(lastPositions.getEyePosition());
121 // if (deviation != Deviation.NONE) {
122 // notifyEyeMovementListenerEyeMoved(deviation);
126 // if (statusWindow != null)
127 // statusWindow.getEyeInfoPanel().setDeviation(null);
130 // lastPositions = positions;
131 // } catch (Exception e) {
132 // e.printStackTrace();
135 // } catch (Exception e2) {
140 // public synchronized void clearDeviationScanner() {
141 // this.deviationScanner.clear();
147 // this.imageProcessor = new
148 // ImageProcessor(this.captureDevice.getFrameRate());
149 // this.imageProcessor.start();
150 LEAImplementation impl = new LEAImplementation();
151 System.out.println("Done.");
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.
160 public void clear() {
161 // this.imageProcessor.clearDeviationScanner();
165 * To test LEA with the first capture device from the
166 * <code>Java Media Framework</code> just start from here.
171 public static void main(String[] args) throws Exception {