2 * Copyright 2009 (c) Florian Frankenberger (darkblue.de)
\r
4 * This file is part of LEA.
\r
6 * LEA is free software: you can redistribute it and/or modify it under the
\r
7 * terms of the GNU Lesser General Public License as published by the Free
\r
8 * Software Foundation, either version 3 of the License, or (at your option) any
\r
11 * LEA is distributed in the hope that it will be useful, but WITHOUT ANY
\r
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
\r
13 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
\r
16 * You should have received a copy of the GNU Lesser General Public License
\r
17 * along with LEA. If not, see <http://www.gnu.org/licenses/>.
\r
21 * No description given.
\r
23 * @author Florian Frankenberger
\r
25 public class DeviationScanner {
\r
27 private EyePosition eyePositions[];
\r
29 private static final Deviation NONE = new Deviation("NONE", 0, 0);
\r
31 public DeviationScanner() {
\r
32 eyePositions = new EyePosition[3];
\r
35 public void addEyePosition(EyePosition eyePosition) {
\r
37 for (int i = eyePositions.length - 2; i >= 0; i--) {
\r
38 eyePositions[i + 1] = eyePositions[i];
\r
40 eyePositions[0] = eyePosition;
\r
43 public Deviation scanForDeviation(Rectangle2D faceRect) {
\r
44 Deviation deviation = NONE;
\r
45 if (eyePositions.length >= 3) {
\r
46 double deviationX = 0;
\r
47 double deviationY = 0;
\r
49 EyePosition lastEyePosition = null;
\r
50 for (int i = 0; i < 3; ++i) {
\r
51 EyePosition eyePosition = this.eyePositions[i];
\r
52 if (lastEyePosition != null) {
\r
53 deviationX += (eyePosition.getX() - lastEyePosition.getX());
\r
54 deviationY += (eyePosition.getY() - lastEyePosition.getY());
\r
56 lastEyePosition = eyePosition;
\r
59 final double deviationPercentX = 0.04;
\r
60 final double deviationPercentY = 0.04;
\r
62 deviationX /= faceRect.getWidth();
\r
63 deviationY /= faceRect.getWidth();
\r
65 int deviationAbsoluteX = 0;
\r
66 int deviationAbsoluteY = 0;
\r
67 if (deviationX > deviationPercentX)
\r
68 deviationAbsoluteX = 1;
\r
69 if (deviationX < -deviationPercentX)
\r
70 deviationAbsoluteX = -1;
\r
71 if (deviationY > deviationPercentY)
\r
72 deviationAbsoluteY = 1;
\r
73 if (deviationY < -deviationPercentY)
\r
74 deviationAbsoluteY = -1;
\r
76 deviation = getDirectionFor(deviationAbsoluteX, deviationAbsoluteY);
\r
77 if (deviation != NONE) {
\r
78 eyePositions = new EyePosition[3];
\r
80 // System.out.println(String.format("%.2f%% | %.2f%% => %d and %d >>> %s",
\r
81 // deviationX*100, deviationY*100, deviationAbsoluteX, deviationAbsoluteY,
\r
82 // deviation.toString()));
\r
89 public static Deviation getDirectionFor(int directionX, int directionY) {
\r
91 // for (Deviation direction : Deviation.values()) {
\r
92 // if (direction.concurs(directionX, directionY)) {
\r
93 // return direction;
\r
99 public void clear() {
\r
100 System.out.println("CLEAR");
\r
101 // this.eyePositions.clear();
\r
104 // LEFT_UP(+1, -1), UP(0, -1), RIGHT_UP(-1, -1), LEFT(+1, 0), NONE(0, 0),
\r
105 // RIGHT(-1, 0), LEFT_DOWN(
\r
106 // +1, +1), DOWN(0, +1), RIGHT_DOWN(-1, +1);
\r