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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
@@ -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> gesturelistener = new Vector<GestureListener>();
|
||||
private Vector<StateListener> statelistener = new Vector<StateListener>();
|
||||
|
||||
|
||||
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> gesturelistener = new Vector<GestureListener>();
|
||||
|
||||
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; 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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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("######");
|
||||
|
||||
Reference in New Issue
Block a user