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
This commit is contained in:
bepo23
2009-07-01 11:01:51 +00:00
parent 496a6262ea
commit 4847a348ee
5 changed files with 82 additions and 215 deletions

View File

@@ -21,7 +21,6 @@
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
package org.wiigee.event; package org.wiigee.event;
import org.wiigee.logic.ProcessingUnit; import org.wiigee.logic.ProcessingUnit;
@@ -36,31 +35,37 @@ import org.wiigee.logic.ProcessingUnit;
*/ */
public class GestureEvent { public class GestureEvent {
int id; int id;
double probability; boolean valid;
ProcessingUnit analyzer; double probability;
ProcessingUnit analyzer;
/** Create a GestureEvent
* /** Create a GestureEvent
* @param source The Source, which detected the gesture. *
* @param id A gesture ID for identifying a gesture. * @param source The Source, which detected the gesture.
* @param probability The Bayes-Classifier calculated probability. * @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; public GestureEvent(ProcessingUnit source, boolean valid, int id, double probability) {
this.id=id; this.analyzer = source;
this.probability=probability; this.valid = valid;
} this.id = id;
this.probability = probability;
public int getId() { }
return this.id;
} public int getId() {
return this.id;
public double getProbability() { }
return this.probability;
} public boolean isValid() {
return this.valid;
public ProcessingUnit getSource() { }
return this.analyzer;
} public double getProbability() {
return this.probability;
}
public ProcessingUnit getSource() {
return this.analyzer;
}
} }

View File

@@ -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;
}
}

View File

@@ -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);
}

View File

@@ -11,83 +11,62 @@ import org.wiigee.event.GestureEvent;
import org.wiigee.event.GestureListener; import org.wiigee.event.GestureListener;
import org.wiigee.event.MotionStartEvent; import org.wiigee.event.MotionStartEvent;
import org.wiigee.event.MotionStopEvent; import org.wiigee.event.MotionStopEvent;
import org.wiigee.event.StateEvent;
import org.wiigee.event.StateListener;
import org.wiigee.util.Log; import org.wiigee.util.Log;
public abstract class ProcessingUnit implements AccelerationListener, ButtonListener { public abstract class ProcessingUnit implements AccelerationListener, ButtonListener {
// Classifier // Classifier
protected Classifier classifier; protected Classifier classifier;
// Listener // Listener
private Vector<GestureListener> gesturelistener = new Vector<GestureListener>(); private Vector<GestureListener> gesturelistener = new Vector<GestureListener>();
private Vector<StateListener> statelistener = new Vector<StateListener>();
public ProcessingUnit() {
this.classifier = new Classifier();
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);
}
/** /**
* 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) { public void addGestureListener(GestureListener g) {
this.statelistener.add(s); this.gesturelistener.add(g);
} }
protected void fireGestureEvent(int id, double probability) {
GestureEvent w = new GestureEvent(this, id, probability);
for(int i=0; i<this.gesturelistener.size(); i++) {
this.gesturelistener.get(i).gestureReceived(w);
}
}
protected void fireStateEvent(int state) {
StateEvent w = new StateEvent(this, state);
for(int i=0; i<this.statelistener.size(); i++) {
this.statelistener.get(i).stateReceived(w);
}
}
public abstract void accelerationReceived(AccelerationEvent event);
public abstract void buttonPressReceived(ButtonPressedEvent event); protected void fireGestureEvent(boolean valid, int id, double probability) {
GestureEvent w = new GestureEvent(this, valid, id, probability);
for (int i = 0; i < this.gesturelistener.size(); i++) {
this.gesturelistener.get(i).gestureReceived(w);
}
}
public abstract void buttonReleaseReceived(ButtonReleasedEvent event); public abstract void accelerationReceived(AccelerationEvent event);
public abstract void motionStartReceived(MotionStartEvent event); public abstract void buttonPressReceived(ButtonPressedEvent event);
public abstract void motionStopReceived(MotionStopEvent event); public abstract void buttonReleaseReceived(ButtonReleasedEvent event);
/** public abstract void motionStartReceived(MotionStartEvent event);
* Resets the complete gesturemodel. After reset no gesture is known
* to the system. public abstract void motionStopReceived(MotionStopEvent event);
*/
public void reset() { /**
if(this.classifier.getCountOfGestures()>0) { * Resets the complete gesturemodel. After reset no gesture is known
this.classifier.clear(); * to the system.
Log.write("### Model reset ###"); */
} else { public void reset() {
Log.write("There doesn't exist any data to reset."); if (this.classifier.getCountOfGestures() > 0) {
} this.classifier.clear();
} Log.write("### Model reset ###");
} else {
// File IO Log.write("There doesn't exist any data to reset.");
public abstract void loadGesture(String filename); }
}
public abstract void saveGesture(int id, String filename);
// File IO
public abstract void loadGesture(String filename);
public abstract void saveGesture(int id, String filename);
} }

View File

@@ -83,11 +83,11 @@ public class TriggeredProcessingUnit extends ProcessingUnit {
} }
public void motionStartReceived(MotionStartEvent event) { public void motionStartReceived(MotionStartEvent event) {
this.handleStartEvent(event); // this.handleStartEvent(event);
} }
public void motionStopReceived(MotionStopEvent event) { public void motionStopReceived(MotionStopEvent event) {
this.handleStopEvent(event); // this.handleStopEvent(event);
} }
public void handleStartEvent(ActionStartEvent event) { public void handleStartEvent(ActionStartEvent event) {
@@ -97,7 +97,6 @@ public class TriggeredProcessingUnit extends ProcessingUnit {
event.isTrainInitEvent()) { event.isTrainInitEvent()) {
Log.write("Training started!"); Log.write("Training started!");
this.learning=true; this.learning=true;
this.fireStateEvent(1);
} }
// RecognitionButton = record a gesture for recognition // RecognitionButton = record a gesture for recognition
@@ -105,7 +104,6 @@ public class TriggeredProcessingUnit extends ProcessingUnit {
event.isRecognitionInitEvent()) { event.isRecognitionInitEvent()) {
Log.write("Recognition started!"); Log.write("Recognition started!");
this.analyzing=true; this.analyzing=true;
this.fireStateEvent(2);
} }
// CloseGestureButton = starts the training of the model with multiple // CloseGestureButton = starts the training of the model with multiple
@@ -115,7 +113,6 @@ public class TriggeredProcessingUnit extends ProcessingUnit {
if(this.trainsequence.size()>0) { if(this.trainsequence.size()>0) {
Log.write("Training the model with "+this.trainsequence.size()+" gestures..."); Log.write("Training the model with "+this.trainsequence.size()+" gestures...");
this.fireStateEvent(1);
this.learning=true; this.learning=true;
GestureModel m = new GestureModel(); GestureModel m = new GestureModel();
@@ -156,12 +153,12 @@ public class TriggeredProcessingUnit extends ProcessingUnit {
int recognized = this.classifier.classifyGesture(gesture); int recognized = this.classifier.classifyGesture(gesture);
if(recognized!=-1) { if(recognized!=-1) {
double recogprob = this.classifier.getLastProbability(); double recogprob = this.classifier.getLastProbability();
this.fireGestureEvent(recognized, recogprob); this.fireGestureEvent(true, recognized, recogprob);
Log.write("######"); Log.write("######");
Log.write("Gesture No. "+recognized+" recognized: "+recogprob); Log.write("Gesture No. "+recognized+" recognized: "+recogprob);
Log.write("######"); Log.write("######");
} else { } else {
this.fireStateEvent(0); this.fireGestureEvent(false, 0, 0.0);
Log.write("######"); Log.write("######");
Log.write("No gesture recognized."); Log.write("No gesture recognized.");
Log.write("######"); Log.write("######");