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;
@@ -37,6 +36,7 @@ import org.wiigee.logic.ProcessingUnit;
public class GestureEvent { public class GestureEvent {
int id; int id;
boolean valid;
double probability; double probability;
ProcessingUnit analyzer; ProcessingUnit analyzer;
@@ -46,16 +46,21 @@ public class GestureEvent {
* @param id A gesture ID for identifying a gesture. * @param id A gesture ID for identifying a gesture.
* @param probability The Bayes-Classifier calculated probability. * @param probability The Bayes-Classifier calculated probability.
*/ */
public GestureEvent(ProcessingUnit source, int id, double probability) { public GestureEvent(ProcessingUnit source, boolean valid, int id, double probability) {
this.analyzer=source; this.analyzer = source;
this.id=id; this.valid = valid;
this.probability=probability; this.id = id;
this.probability = probability;
} }
public int getId() { public int getId() {
return this.id; return this.id;
} }
public boolean isValid() {
return this.valid;
}
public double getProbability() { public double getProbability() {
return this.probability; return this.probability;
} }

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,8 +11,6 @@ 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 {
@@ -22,8 +20,6 @@ public abstract class ProcessingUnit implements AccelerationListener, ButtonList
// 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() { public ProcessingUnit() {
this.classifier = new Classifier(); this.classifier = new Classifier();
@@ -39,29 +35,13 @@ public abstract class ProcessingUnit implements AccelerationListener, ButtonList
this.gesturelistener.add(g); this.gesturelistener.add(g);
} }
/** protected void fireGestureEvent(boolean valid, int id, double probability) {
* Adds a StateListener to receive StateEvents. GestureEvent w = new GestureEvent(this, valid, id, probability);
* for (int i = 0; i < this.gesturelistener.size(); i++) {
* @param s Class which implements the StateListener interface.
*/
public void addStateListener(StateListener s) {
this.statelistener.add(s);
}
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); 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 accelerationReceived(AccelerationEvent event);
public abstract void buttonPressReceived(ButtonPressedEvent event); public abstract void buttonPressReceived(ButtonPressedEvent event);
@@ -77,7 +57,7 @@ public abstract class ProcessingUnit implements AccelerationListener, ButtonList
* to the system. * to the system.
*/ */
public void reset() { public void reset() {
if(this.classifier.getCountOfGestures()>0) { if (this.classifier.getCountOfGestures() > 0) {
this.classifier.clear(); this.classifier.clear();
Log.write("### Model reset ###"); Log.write("### Model reset ###");
} else { } else {
@@ -89,5 +69,4 @@ public abstract class ProcessingUnit implements AccelerationListener, ButtonList
public abstract void loadGesture(String filename); public abstract void loadGesture(String filename);
public abstract void saveGesture(int id, 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("######");