protected override void OnLoad(EventArgs e) { base.OnLoad(e); GL.ClearColor(0.2f, 0.2f, 0.2f, 1.0f); GL.PointSize(8.0f); GL.Enable(EnableCap.DepthTest); CurrState = null; }
bool _IsNeutralStance(JointState js) { // TODO: punch stance float tolerance = 0.85f; float damping = mCurrSegmentSize / 175.0f; float final = tolerance - damping * damping * damping; var conf = AllFeatures.LearnedFrameFeatures["NeutralStance"].QueryFrame(js); Console.WriteLine("Neutral tolerance: {1} / {0}", final, conf); return conf > final; }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); GL.ClearColor(0.2f, 0.2f, 0.2f, 1.0f); GL.PointSize(8.0f); GL.Enable(EnableCap.DepthTest); mGesture = new InputGesture(new LogFileLoader(mLogFilename)); mCurrState = JointState.CloneFrom(mGesture.States[0]); }
bool _IsNeutralStance(JointState js) { // TODO: punch stance float tolerance = 0.85f; float damping = mCurrSegmentSize / 175.0f; float final = tolerance - damping * damping * damping; var conf = AllFeatures.LearnedFrameFeatures["NeutralStance"].QueryFrame(js); Console.WriteLine("Neutral tolerance: {1} / {0}", final, conf); return(conf > final); }
public InputGesture(IEnumerable <RawJointState> states) { States = new List <JointState>(); if (states != null) { foreach (var js in states) { States.Add(JointState.FromRawJointState(js)); } if (States.Count > 0) { StartTime = States[0].Timestamp; } } }
public void AddState (JointState js) { if ( _IsNeutralStance(js) ) { _CheckIfSegmented(); _AddToBuffer(js); if ( mCurrSegmentSize > 0 ) { mCurrGesture.Clear(); } mCurrSegmentSize = 0; } else { mCurrGesture.AddRange(mBuffer); mBuffer.Clear(); mCurrGesture.Add(js); mCurrSegmentSize++; } }
static public JointState FromRawJointState(RawJointState rjs) { JointState rel = new JointState(); rel.Timestamp = rjs.Timestamp; rel.NeckPos = rjs.Joints[0]; rel.RelativeJoints = rjs.Joints.Select(x => x - rel.NeckPos).ToArray(); rel.RelativeAngles = new float[rjs.Joints.Length]; for (int i = 1; i < rel.RelativeJoints.Length; i++) { Vector3 thisVec = rel.RelativeJoints[i] - rel.RelativeJoints[JointParents[i]]; Vector3 parentVec = (JointParents[JointParents[i]] == -1) ? Vector3.UnitY : rel.RelativeJoints[JointParents[i]] - rel.RelativeJoints[JointParents[JointParents[i]]]; rel.RelativeAngles[i] = Vector3.CalculateAngle(thisVec, parentVec); } return(rel); }
public void AddState(JointState js) { if (_IsNeutralStance(js)) { _CheckIfSegmented(); _AddToBuffer(js); if (mCurrSegmentSize > 0) { mCurrGesture.Clear(); } mCurrSegmentSize = 0; } else { mCurrGesture.AddRange(mBuffer); mBuffer.Clear(); mCurrGesture.Add(js); mCurrSegmentSize++; } }
public JointAmplitude(string jn, JointState.JointComponent jc, bool d) { JointName = jn; JointComponent = jc; Directional = d; }
public float QueryFrame(JointState js) { if (js.Pos("right-palm").X - js.Pos("neck").X < 0.0f) return 1.0f; else return 0.0f; }
void _AddToBuffer(JointState js) { mBuffer.Enqueue(js); if ( mBuffer.Count > _numBufferFrames ) mBuffer.Dequeue(); }
public float QueryFrame(JointState js) { if (js.Pos("right-palm").Z > 0.5f) return 1.0f; else return 0.0f; }
public RecognizerResult AddNewData(JointState js) { throw new NotImplementedException(); }
public ProportionChange(string jn, JointState.JointComponent jc) { JointName = jn; JointComponent = jc; }
public NeutralDeviation(string jn, JointState.JointComponent jc) { JointName = jn; JointComponent = jc; }
public float QueryFrame(JointState js) { if ((js.Pos("right-palm") - js.Pos("left-palm")).Length < 0.2f) return 1.0f; else return 0.0f; }
static public JointState CloneFrom(JointState rjs) { JointState rel = new JointState(); rel.Timestamp = rjs.Timestamp; rel.NeckPos = rjs.NeckPos; rel.RelativeJoints = new Vector3[rjs.RelativeJoints.Length]; rjs.RelativeJoints.CopyTo(rel.RelativeJoints, 0); return rel; }
public void Run(string[] args) { Command c = Recognizer.Command.Help; if (args.Length > 0) { c = (Command)Enum.Parse(typeof(Recognizer.Command), args[0]); } if (c == Recognizer.Command.Help) { Console.WriteLine("Usage:\n\tFinalProject.exe command [filename]\n\nCommands:"); foreach (var cm in Enum.GetNames(typeof(Recognizer.Command))) { Console.WriteLine(cm); } return; } // For CV mCV = new CrossValidation("cvindex.txt"); //////////////////// // CHANGE THESE LINES TO SWAP MODELS //////////////////// mRec = new LogisticRegressionRecognizer(); mSeg = new DumbSegmenter(); Console.WriteLine("Using recognizer {0}", mRec.GetType().ToString()); Console.WriteLine("Using segmenter {0}", mSeg.GetType().ToString()); mRecFilename = "models/" + mRec.GetType().ToString() + ".rec.model"; mSegFilename = "models/" + mSeg.GetType().ToString() + ".seg.model"; mSeg.GestureSegmented += delegate(object sender, EventArgs e) { var segm = ((ISegmenter)sender).LastGesture; var recres = mRec.RecognizeSingleGesture(segm); if (recres.Confidence1 > 0.5f) { Console.WriteLine("Recognized gesture: {0}", recres.Gesture1); } else { Console.WriteLine("Inconclusive"); } }; string filename = "gestures/track_high_kick_01.log"; if (args.Length > 1) { filename = args[1]; } InputGesture gest; Thread visthread; switch (c) { case Command.Train: Train(); break; case Command.TestSingle: LoadModels(); var result = mRec.RecognizeSingleGesture(new InputGesture(new LogFileLoader(filename))); Console.WriteLine(result.ToString()); break; case Command.TestRecognize: LoadModels(); var test_gestures = LoadData(mGestureNames, false); int[] total = Enumerable.Range(0, test_gestures.Count).Select(x => 0).ToArray(), correct = Enumerable.Range(0, test_gestures.Count).Select(x => 0).ToArray(); int i = 0; Console.WriteLine(); foreach (var gn in test_gestures) { foreach (var tg in gn.Value) { total[i]++; var result2 = mRec.RecognizeSingleGesture(tg); if (result2.Gesture1 == gn.Key) { correct[i]++; } } Console.WriteLine("{0}: {1} correct / {2} total = {3}% correct", gn.Key, correct[i], total[i], (float)correct[i] / (float)total[i] * 100.0f); i++; } Console.WriteLine("TEST RESULTS:\n\t{0} correct / {1} total = {2}% correct", correct.Sum(), total.Sum(), (float)correct.Sum() / (float)total.Sum() * 100.0f); Utility.PrintMemoryUsage(); break; case Command.TestRealtime: LoadModels(); gest = new InputGesture(new LogFileLoader(filename)); visthread = new Thread(new ThreadStart(this.StartVisualize)); visthread.Start(); while (true) // Wait for window to get created { lock (this) { if (mVisWindow != null) { break; } } } float lastTime = gest.States[0].Timestamp; foreach (var frame in gest.States) { mSeg.AddState(frame); mVisWindow.CurrState = frame; Thread.Sleep((int)((frame.Timestamp - lastTime) * 750.0f)); lastTime = frame.Timestamp; } mSeg.Finish(); visthread.Abort(); break; case Command.RunRealtime: LoadModels(); visthread = new Thread(new ThreadStart(this.StartVisualize)); visthread.Start(); while (true) // Wait for window to get created { lock (this) { if (mVisWindow != null) { break; } } } var nfl = new NetworkFrameListener(4711); nfl.Start(); Console.WriteLine("Press the 'x' key to quit"); while (true) { var frame = nfl.GetState(); if (frame != null) { var js = JointState.FromRawJointState(frame); mSeg.AddState(js); mVisWindow.CurrState = js; } if (Console.KeyAvailable) { var cki = Console.ReadKey(true); if (cki.Key == ConsoleKey.X) { break; } } if (!nfl.Running) { break; } Thread.Sleep(0); } mSeg.Finish(); nfl.Stop(); visthread.Abort(); break; case Command.PrintFeatures: gest = new InputGesture(new LogFileLoader(filename)); /*foreach ( var f in Features.AllFeatures.SingleGestureFeatures ) { * Console.WriteLine("{0}: {1}", f.ToString(), f.QueryGesture(gest)); * }*/ foreach (var f in Features.AllFeatures.GestureFeatures) { Console.WriteLine("{0}: {1}", f.ToString(), f.QueryGesture(gest)); } break; case Command.BenchmarkRecognize: Benchmarks.BenchmarkRecognize(); break; case Command.CycleCV: mCV.Incr(); mCV.Save(); break; } }
public NumberCriticalPoints(string jn, JointState.JointComponent jc) { JN = jn; JC = jc; }
public float QueryFrame(JointState js) { if ( js.Pos("right-foot").Y >= -0.2f ) return 1.0f; else return 0.0f; }
static public JointState FromRawJointState(RawJointState rjs) { JointState rel = new JointState(); rel.Timestamp = rjs.Timestamp; rel.NeckPos = rjs.Joints[0]; rel.RelativeJoints = rjs.Joints.Select(x => x - rel.NeckPos).ToArray(); rel.RelativeAngles = new float[rjs.Joints.Length]; for ( int i = 1; i < rel.RelativeJoints.Length; i++ ) { Vector3 thisVec = rel.RelativeJoints[i] - rel.RelativeJoints[JointParents[i]]; Vector3 parentVec = (JointParents[JointParents[i]] == -1) ? Vector3.UnitY : rel.RelativeJoints[JointParents[i]] - rel.RelativeJoints[JointParents[JointParents[i]]]; rel.RelativeAngles[i] = Vector3.CalculateAngle(thisVec, parentVec); } return rel; }
public DerivativeSum(string jn, JointState.JointComponent jc, Func<JointState, bool> condition) { JN = jn; JC = jc; Cond = condition; }
public AxisCoincidence(string jn, JointState.JointComponent ja, JointState.JointComponent jb) { JN = jn; JA = ja; JB = jb; }