From 4847a348ee80c6a71039b94aa75cc2d5de582512 Mon Sep 17 00:00:00 2001 From: bepo23 Date: Wed, 1 Jul 2009 11:01:51 +0000 Subject: [PATCH] Fixed some bugs with focus on State-Events: Removed State Event and added a 'valid'-boolean to a Gesture object, to validate if the gesture detected is a valid gesture. git-svn-id: svn://svn.code.sf.net/p/wiigee/code/trunk@98 c7eff9ee-dd40-0410-8832-91a4d88773cf --- src/org/wiigee/event/GestureEvent.java | 61 +++++----- src/org/wiigee/event/StateEvent.java | 66 ----------- src/org/wiigee/event/StateListener.java | 48 -------- src/org/wiigee/logic/ProcessingUnit.java | 111 +++++++----------- .../wiigee/logic/TriggeredProcessingUnit.java | 11 +- 5 files changed, 82 insertions(+), 215 deletions(-) delete mode 100755 src/org/wiigee/event/StateEvent.java delete mode 100755 src/org/wiigee/event/StateListener.java diff --git a/src/org/wiigee/event/GestureEvent.java b/src/org/wiigee/event/GestureEvent.java index d8e0d3b..e3465a7 100755 --- a/src/org/wiigee/event/GestureEvent.java +++ b/src/org/wiigee/event/GestureEvent.java @@ -21,7 +21,6 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - package org.wiigee.event; import org.wiigee.logic.ProcessingUnit; @@ -36,31 +35,37 @@ import org.wiigee.logic.ProcessingUnit; */ public class GestureEvent { - int id; - double probability; - ProcessingUnit analyzer; - - /** Create a GestureEvent - * - * @param source The Source, which detected the gesture. - * @param id A gesture ID for identifying a gesture. - * @param probability The Bayes-Classifier calculated probability. - */ - public GestureEvent(ProcessingUnit source, int id, double probability) { - this.analyzer=source; - this.id=id; - this.probability=probability; - } - - public int getId() { - return this.id; - } - - public double getProbability() { - return this.probability; - } - - public ProcessingUnit getSource() { - return this.analyzer; - } + int id; + boolean valid; + double probability; + ProcessingUnit analyzer; + + /** Create a GestureEvent + * + * @param source The Source, which detected the gesture. + * @param id A gesture ID for identifying a gesture. + * @param probability The Bayes-Classifier calculated probability. + */ + public GestureEvent(ProcessingUnit source, boolean valid, int id, double probability) { + this.analyzer = source; + this.valid = valid; + this.id = id; + this.probability = probability; + } + + public int getId() { + return this.id; + } + + public boolean isValid() { + return this.valid; + } + + public double getProbability() { + return this.probability; + } + + public ProcessingUnit getSource() { + return this.analyzer; + } } diff --git a/src/org/wiigee/event/StateEvent.java b/src/org/wiigee/event/StateEvent.java deleted file mode 100755 index 090aa8c..0000000 --- a/src/org/wiigee/event/StateEvent.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * wiigee - accelerometerbased gesture recognition - * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga - * - * Developed at University of Oldenburg - * Contact: wiigee@benjaminpoppinga.de - * - * This file is part of wiigee. - * - * wiigee is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.wiigee.event; - -import java.util.EventObject; -import org.wiigee.logic.ProcessingUnit; - -/** - * This is a StateEvent, telling the listeners in which state of recognition - * the tool is: - * 1 = training, - * 2 = recognition - * - * @author Benjamin 'BePo' Poppinga - */ -public class StateEvent extends EventObject { - - public final int STATE_LEARNING=1; - public final int STATE_RECOGNIZING=2; - - int state; - ProcessingUnit analyzer; - - /** - * Create a StateEvent. - * - * @param source The source of which the state has changed. - * @param state The state the source has switched to. - */ - public StateEvent(ProcessingUnit source, int state) { - super(source); - this.analyzer=source; - this.state=state; - } - - public int getState() { - return this.state; - } - - public ProcessingUnit getSource() { - return this.analyzer; - } - -} diff --git a/src/org/wiigee/event/StateListener.java b/src/org/wiigee/event/StateListener.java deleted file mode 100755 index 1639a22..0000000 --- a/src/org/wiigee/event/StateListener.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * wiigee - accelerometerbased gesture recognition - * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga - * - * Developed at University of Oldenburg - * Contact: wiigee@benjaminpoppinga.de - * - * This file is part of wiigee. - * - * wiigee is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.wiigee.event; - -import java.util.EventListener; - -/** - * This is the StateListener interface which has to be implemented - * by any application which should receive recognized statechanges. - * - * @author Benjamin 'BePo' Poppinga - * - */ -public interface StateListener extends EventListener { - - /** - * This method would be called if the gesture-recognizing system - * switched the state from recognition to training or otherwise. - * - * @param event The StateEvent containing information about the - * state-change. - */ - public abstract void stateReceived(StateEvent event); - - -} diff --git a/src/org/wiigee/logic/ProcessingUnit.java b/src/org/wiigee/logic/ProcessingUnit.java index baa612a..8a3adfa 100644 --- a/src/org/wiigee/logic/ProcessingUnit.java +++ b/src/org/wiigee/logic/ProcessingUnit.java @@ -11,83 +11,62 @@ import org.wiigee.event.GestureEvent; import org.wiigee.event.GestureListener; import org.wiigee.event.MotionStartEvent; import org.wiigee.event.MotionStopEvent; -import org.wiigee.event.StateEvent; -import org.wiigee.event.StateListener; import org.wiigee.util.Log; public abstract class ProcessingUnit implements AccelerationListener, ButtonListener { - // Classifier - protected Classifier classifier; - - // Listener - private Vector gesturelistener = new Vector(); - private Vector statelistener = new Vector(); - - - public ProcessingUnit() { - this.classifier = new Classifier(); - } - - /** - * Add an GestureListener to receive GestureEvents. - * - * @param g - * Class which implements GestureListener interface. - */ - public void addGestureListener(GestureListener g) { - this.gesturelistener.add(g); - } + // Classifier + protected Classifier classifier; + + // Listener + private Vector gesturelistener = new Vector(); + + public ProcessingUnit() { + this.classifier = new Classifier(); + } /** - * Adds a StateListener to receive StateEvents. + * Add an GestureListener to receive GestureEvents. * - * @param s Class which implements the StateListener interface. + * @param g + * Class which implements GestureListener interface. */ - public void addStateListener(StateListener s) { - this.statelistener.add(s); + public void addGestureListener(GestureListener g) { + this.gesturelistener.add(g); } - - protected void fireGestureEvent(int id, double probability) { - GestureEvent w = new GestureEvent(this, id, probability); - for(int i=0; i0) { - this.classifier.clear(); - Log.write("### Model reset ###"); - } else { - Log.write("There doesn't exist any data to reset."); - } - } - - // File IO - public abstract void loadGesture(String filename); - - public abstract void saveGesture(int id, String filename); - + public abstract void buttonReleaseReceived(ButtonReleasedEvent event); + + public abstract void motionStartReceived(MotionStartEvent event); + + public abstract void motionStopReceived(MotionStopEvent event); + + /** + * Resets the complete gesturemodel. After reset no gesture is known + * to the system. + */ + public void reset() { + if (this.classifier.getCountOfGestures() > 0) { + this.classifier.clear(); + Log.write("### Model reset ###"); + } else { + Log.write("There doesn't exist any data to reset."); + } + } + + // File IO + public abstract void loadGesture(String filename); + + public abstract void saveGesture(int id, String filename); } diff --git a/src/org/wiigee/logic/TriggeredProcessingUnit.java b/src/org/wiigee/logic/TriggeredProcessingUnit.java index 2385acc..5a68344 100644 --- a/src/org/wiigee/logic/TriggeredProcessingUnit.java +++ b/src/org/wiigee/logic/TriggeredProcessingUnit.java @@ -83,11 +83,11 @@ public class TriggeredProcessingUnit extends ProcessingUnit { } public void motionStartReceived(MotionStartEvent event) { - this.handleStartEvent(event); + // this.handleStartEvent(event); } public void motionStopReceived(MotionStopEvent event) { - this.handleStopEvent(event); + // this.handleStopEvent(event); } public void handleStartEvent(ActionStartEvent event) { @@ -97,7 +97,6 @@ public class TriggeredProcessingUnit extends ProcessingUnit { event.isTrainInitEvent()) { Log.write("Training started!"); this.learning=true; - this.fireStateEvent(1); } // RecognitionButton = record a gesture for recognition @@ -105,7 +104,6 @@ public class TriggeredProcessingUnit extends ProcessingUnit { event.isRecognitionInitEvent()) { Log.write("Recognition started!"); this.analyzing=true; - this.fireStateEvent(2); } // CloseGestureButton = starts the training of the model with multiple @@ -115,7 +113,6 @@ public class TriggeredProcessingUnit extends ProcessingUnit { if(this.trainsequence.size()>0) { Log.write("Training the model with "+this.trainsequence.size()+" gestures..."); - this.fireStateEvent(1); this.learning=true; GestureModel m = new GestureModel(); @@ -156,12 +153,12 @@ public class TriggeredProcessingUnit extends ProcessingUnit { int recognized = this.classifier.classifyGesture(gesture); if(recognized!=-1) { double recogprob = this.classifier.getLastProbability(); - this.fireGestureEvent(recognized, recogprob); + this.fireGestureEvent(true, recognized, recogprob); Log.write("######"); Log.write("Gesture No. "+recognized+" recognized: "+recogprob); Log.write("######"); } else { - this.fireStateEvent(0); + this.fireGestureEvent(false, 0, 0.0); Log.write("######"); Log.write("No gesture recognized."); Log.write("######");