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
26 public class DeviationScanner {
\r
31 // LEFT_UP(+1, -1), UP(0, -1), RIGHT_UP(-1, -1), LEFT(+1, 0), NONE(0, 0),
\r
32 // RIGHT(-1, 0), LEFT_DOWN(
\r
33 // +1, +1), DOWN(0, +1), RIGHT_DOWN(-1, +1);
\r
35 public static final int LEFT_UP = 0;
\r
36 public static final int UP = 1;
\r
37 public static final int RIGHT_UP = 2;
\r
38 public static final int LEFT = 3;
\r
39 public static final int NONE = 4;
\r
40 public static final int RIGHT = 5;
\r
41 public static final int LEFT_DOWN = 6;
\r
42 public static final int DOWN = 7;
\r
43 public static final int RIGHT_DOWN = 8;
\r
45 public DeviationScanner() {
\r
48 SSJAVA.arrayinit(x, -1);
\r
49 SSJAVA.arrayinit(y, -1);
\r
52 public void addEyePosition(int inx, int iny) {
\r
53 SSJAVA.append(x, inx);
\r
54 SSJAVA.append(y, iny);
\r
57 public int scanForDeviation(Rectangle2D faceRect) {
\r
59 int deviation = NONE;
\r
61 for (int i = 0; i < 3; i++) {
\r
67 double deviationX = 0;
\r
68 double deviationY = 0;
\r
71 for (int i = 0; i < 3; ++i) {
\r
72 if (lastIdx != -1) {
\r
73 deviationX += (x[i] - x[lastIdx]);
\r
74 deviationY += (y[i] - y[lastIdx]);
\r
79 final double deviationPercentX = 0.04;
\r
80 final double deviationPercentY = 0.04;
\r
82 deviationX /= faceRect.getWidth();
\r
83 deviationY /= faceRect.getWidth();
\r
85 int deviationAbsoluteX = 0;
\r
86 int deviationAbsoluteY = 0;
\r
87 if (deviationX > deviationPercentX)
\r
88 deviationAbsoluteX = 1;
\r
89 if (deviationX < -deviationPercentX)
\r
90 deviationAbsoluteX = -1;
\r
91 if (deviationY > deviationPercentY)
\r
92 deviationAbsoluteY = 1;
\r
93 if (deviationY < -deviationPercentY)
\r
94 deviationAbsoluteY = -1;
\r
96 deviation = getDirectionFor(deviationAbsoluteX, deviationAbsoluteY);
\r
98 if (deviation != NONE) {
\r
99 SSJAVA.arrayinit(x, -1);
\r
100 SSJAVA.arrayinit(y, -1);
\r
106 public int getDirectionFor(int directionX, int directionY) {
\r
108 if (directionX == +1 && directionY == -1) {
\r
110 } else if (directionX == 0 && directionY == -1) {
\r
112 } else if (directionX == -1 && directionY == -1) {
\r
114 } else if (directionX == +1 && directionY == 0) {
\r
116 } else if (directionX == 0 && directionY == 0) {
\r
118 } else if (directionX == -1 && directionY == 0) {
\r
120 } else if (directionX == +1 && directionY == +1) {
\r
122 } else if (directionX == 0 && directionY == +1) {
\r
124 } else if (directionX == -1 && directionY == +1) {
\r
131 public String toStringDeviation(int dev) {
\r
132 if (dev == LEFT_UP) {
\r
134 } else if (dev == UP) {
\r
136 } else if (dev == RIGHT_UP) {
\r
138 } else if (dev == LEFT) {
\r
140 } else if (dev == NONE) {
\r
142 } else if (dev == RIGHT) {
\r
144 } else if (dev == LEFT_DOWN) {
\r
145 return "LEFT_DOWN";
\r
146 } else if (dev == DOWN) {
\r
148 } else if (dev == RIGHT_DOWN) {
\r
149 return "RIGHT_DOWN";
\r