void _CheckIfSegmented() { if ( mCurrSegmentSize >= _minSegmentSize ) { Console.WriteLine("Segmented gesture"); LastGesture = InputGesture.FromJointStates(mCurrGesture); GestureSegmented(this, null); } }
public float QueryGesture(InputGesture ig) { Func <JointState, float> f = x => x.Component(JN, JC); float min = ig.States.Min(f), max = ig.States.Max(f); float center = (max + min) / 2.0f; float dist_threshold = 0.5f; bool dir = (f(ig.States[1]) - f(ig.States[0])) > 0.0f; var count = 0; var sinceLast = 100; for (int i = 1; i < ig.States.Count; i++) { float maxthres = (max - center) * dist_threshold; float minthres = (min - center) * dist_threshold; bool newdir = (f(ig.States[i]) - f(ig.States[i - 1])) > 0.0f; if (newdir != dir && sinceLast > 10) { float relpos = f(ig.States[i]) - center; if (relpos > maxthres || relpos < minthres) { count++; } sinceLast = 0; } dir = newdir; sinceLast++; } return((float)count / (float)ig.States.Count); }
private static void Verify(InputGesture inputGesture) { if (inputGesture == null) { throw new ArgumentNullException(nameof(inputGesture)); } }
public IDisposable RegisterCommand(ICommand command, InputGesture gesture) { var binding = new InputBinding(command, gesture); window.InputBindings.Add(binding); return(new Remover(window, binding)); }
internal static void _RegisterClassHandlers(Type controlType, bool acceptsRichContent, bool readOnly, bool registerEventListeners) { CommandHelpers.RegisterCommandHandler(controlType, ApplicationCommands.Copy, new ExecutedRoutedEventHandler(TextEditorCopyPaste.OnCopy), new CanExecuteRoutedEventHandler(TextEditorCopyPaste.OnQueryStatusCopy), KeyGesture.CreateFromResourceStrings(SR.Get("KeyCopy"), SR.Get("KeyCopyDisplayString")), KeyGesture.CreateFromResourceStrings(SR.Get("KeyCtrlInsert"), SR.Get("KeyCtrlInsertDisplayString"))); if (acceptsRichContent) { CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.CopyFormat, new ExecutedRoutedEventHandler(TextEditorCopyPaste.OnCopyFormat), new CanExecuteRoutedEventHandler(TextEditorCopyPaste.OnQueryStatusCopyFormat), "KeyCopyFormat", "KeyCopyFormatDisplayString"); } if (!readOnly) { CommandHelpers.RegisterCommandHandler(controlType, ApplicationCommands.Cut, new ExecutedRoutedEventHandler(TextEditorCopyPaste.OnCut), new CanExecuteRoutedEventHandler(TextEditorCopyPaste.OnQueryStatusCut), KeyGesture.CreateFromResourceStrings(SR.Get("KeyCut"), SR.Get("KeyCutDisplayString")), KeyGesture.CreateFromResourceStrings(SR.Get("KeyShiftDelete"), SR.Get("KeyShiftDeleteDisplayString"))); ExecutedRoutedEventHandler executedRoutedEventHandler = new ExecutedRoutedEventHandler(TextEditorCopyPaste.OnPaste); CanExecuteRoutedEventHandler canExecuteRoutedEventHandler = new CanExecuteRoutedEventHandler(TextEditorCopyPaste.OnQueryStatusPaste); InputGesture inputGesture = KeyGesture.CreateFromResourceStrings(SR.Get("KeyShiftInsert"), SR.Get("KeyShiftInsertDisplayString")); new UIPermission(UIPermissionClipboard.AllClipboard).Assert(); try { CommandHelpers.RegisterCommandHandler(controlType, ApplicationCommands.Paste, executedRoutedEventHandler, canExecuteRoutedEventHandler, inputGesture); } finally { CodeAccessPermission.RevertAssert(); } if (acceptsRichContent) { CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.PasteFormat, new ExecutedRoutedEventHandler(TextEditorCopyPaste.OnPasteFormat), new CanExecuteRoutedEventHandler(TextEditorCopyPaste.OnQueryStatusPasteFormat), "KeyPasteFormat", "KeyPasteFormatDisplayString"); } } }
internal void UnregisterGesture(InputGesture gesture) { if (registeredGestures.ContainsKey(gesture)) { registeredGestures.Remove(gesture); } }
internal static void RegisterCommandHandler(Type controlType, RoutedCommand command, ExecutedRoutedEventHandler executedRoutedEventHandler, CanExecuteRoutedEventHandler canExecuteRoutedEventHandler, InputGesture inputGesture, InputGesture inputGesture2, InputGesture inputGesture3, InputGesture inputGesture4) { PrivateRegisterCommandHandler(controlType, command, executedRoutedEventHandler, canExecuteRoutedEventHandler, inputGesture, inputGesture2, inputGesture3, inputGesture4); }
private void OnMappingAdded(Mode mode, InputGesture gesture, Action <PadEditor> action) { if (mode == currentMode) { BindMacro(gesture, action); } }
bool AreGestureEqual(InputGesture left, InputGesture right) { if (left.GetType() != right.GetType()) { return(false); } var leftKeyGesture = left as UnrestrictedKeyGesture; if (leftKeyGesture != null) { var rightKeyGesture = (UnrestrictedKeyGesture)right; return(rightKeyGesture.Key == leftKeyGesture.Key && rightKeyGesture.Modifiers == leftKeyGesture.Modifiers); } var leftMouseGesture = left as MouseGesture; if (leftMouseGesture != null) { var rightMouseGesture = (MouseGesture)right; return(rightMouseGesture.MouseAction == leftMouseGesture.MouseAction && rightMouseGesture.Modifiers == leftMouseGesture.Modifiers); } return(false); }
/// <summary> /// Remove a binding according to an InputGesture. /// </summary> /// <param name="model"></param> /// <param name="gesture"></param> public void RemoveBinding(ViewModelBase model, InputGesture gesture) { FrameworkElement element = model.ViewElement as FrameworkElement; if (element == null) { return; } InputBindingCollection elementBindings = element.InputBindings; // need to find the exact class instance that was added. for (int i = elementBindings.Count - 1; i >= 0; i--) { if (!gesture.Equals(elementBindings[i].Gesture)) { continue; } Console.WriteLine("Removing binding"); this.GetBindingList(model).Remove(elementBindings[i]); elementBindings.RemoveAt(i); return; } // for-loop. }
/// <summary> /// Replace a binding with the given InputGesture with the new input binding. /// </summary> /// <param name="model"></param> /// <param name="old_binding"></param> /// <param name="new_binding"></param> public void ReplaceBinding(ViewModelBase model, InputGesture gesture, InputBinding new_binding) { FrameworkElement element = model.ViewElement as FrameworkElement; if (element == null) { return; } InputBindingCollection elementBindings = element.InputBindings; List <InputBinding> viewBindingList = this.GetBindingList(model); for (int i = elementBindings.Count - 1; i >= 0; i--) { InputBinding b = elementBindings[i]; // searching for a matching gesture - this gesture is being replaced. if (!b.Gesture.Equals(gesture)) { continue; } Console.WriteLine("OVERWRITING BINDING"); // NOTE: b is being removed because 'old_binding' is just logically equivalent, // not necessarily the same object. // TODO: replace with Predicate remove. viewBindingList.Remove(b); viewBindingList.Add(new_binding); //elementBindings.RemoveAt( i ); elementBindings[i] = new_binding; break; } // for-loop. }
public float QueryGesture(InputGesture ig) { Func <JointState, float> f = x => x.NeckPos.Y; float min = ig.States.Min(f), max = ig.States.Max(f); return(max - min); }
//------------------------------------------------------ // // Class Internal Methods // //------------------------------------------------------ #region Class Internal Methods // Registers all text editing command handlers for a given control type internal static void _RegisterClassHandlers(Type controlType, bool acceptsRichContent, bool readOnly, bool registerEventListeners) { CommandHelpers.RegisterCommandHandler(controlType, ApplicationCommands.Copy, new ExecutedRoutedEventHandler(OnCopy), new CanExecuteRoutedEventHandler(OnQueryStatusCopy), KeyGesture.CreateFromResourceStrings(KeyCopy, SR.Get(SRID.KeyCopyDisplayString)), KeyGesture.CreateFromResourceStrings(KeyCtrlInsert, SR.Get(SRID.KeyCtrlInsertDisplayString))); if (acceptsRichContent) { CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.CopyFormat, new ExecutedRoutedEventHandler(OnCopyFormat), new CanExecuteRoutedEventHandler(OnQueryStatusCopyFormat), KeyGesture.CreateFromResourceStrings(KeyCopyFormat, SRID.KeyCopyFormatDisplayString)); } if (!readOnly) { CommandHelpers.RegisterCommandHandler(controlType, ApplicationCommands.Cut, new ExecutedRoutedEventHandler(OnCut), new CanExecuteRoutedEventHandler(OnQueryStatusCut), KeyGesture.CreateFromResourceStrings(KeyCut, SR.Get(SRID.KeyCutDisplayString)), KeyGesture.CreateFromResourceStrings(KeyShiftDelete, SR.Get(SRID.KeyShiftDeleteDisplayString))); // temp vars to reduce code under elevation ExecutedRoutedEventHandler ExecutedRoutedEventHandler = new ExecutedRoutedEventHandler(OnPaste); CanExecuteRoutedEventHandler CanExecuteRoutedEventHandler = new CanExecuteRoutedEventHandler(OnQueryStatusPaste); InputGesture inputGesture = KeyGesture.CreateFromResourceStrings(KeyShiftInsert, SR.Get(SRID.KeyShiftInsertDisplayString)); new UIPermission(UIPermissionClipboard.AllClipboard).Assert(); //BlessedAssert try { CommandHelpers.RegisterCommandHandler(controlType, ApplicationCommands.Paste, ExecutedRoutedEventHandler, CanExecuteRoutedEventHandler, inputGesture); } finally { CodeAccessPermission.RevertAssert(); } if (acceptsRichContent) { CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.PasteFormat, new ExecutedRoutedEventHandler(OnPasteFormat), new CanExecuteRoutedEventHandler(OnQueryStatusPasteFormat), KeyPasteFormat, SRID.KeyPasteFormatDisplayString); } } }
//public static void ExecuteZoomCommand(object sender, ExecutedRoutedEventArgs e) //{ // Debug.WriteLine("Zoom"); // (sender as ImageViewer).Scale += 0.1; //} ////public static RoutedUICommand ZoomCommand; //public static CommandBinding ZoomBinding; private static InputGestureCollection GestureToGestureCollection(InputGesture gesture) { InputGestureCollection retVal = new InputGestureCollection(); retVal.Add(gesture); return(retVal); }
public void AddGlobalCommand(ICommand command, InputGesture gesture) { var binding = new InputBinding(command, gesture); var newGesture = gesture as KeyGesture; if (newGesture != null) { foreach (InputBinding b in _globalBindings) { var g = b.Gesture as KeyGesture; if (g != null && g.Key == newGesture.Key && g.Modifiers == newGesture.Modifiers) { throw new Exception("Duplicated gesture!"); } } } _globalBindings.Add(binding); if (MainWindow != null) { MainWindow.InputBindings.Add(binding); } }
/// <summary> /// Регистрирует обработчик команды /// </summary> /// <param name="controlType">Тип контрола</param> /// <param name="command">Команда</param> /// <param name="executedRoutedEventHandler">Обработчик выполнения команды</param> /// <param name="inputGesture">Горячая клавиша</param> public static void RegisterCommandHandler( Type controlType, RoutedCommand command, ExecutedRoutedEventHandler executedRoutedEventHandler, InputGesture inputGesture) { PrivateRegisterCommandHandler(controlType, command, executedRoutedEventHandler, null, new[] { inputGesture }); }
/// <summary> /// This method creates a WPF input binding from the Gesture in this object. /// </summary> /// <returns>WPF input binding.</returns> protected override InputBinding CreateInputBinding() { if (Gesture == null) { Gesture = new KeyGesture(_key, _modKeys); } return(new System.Windows.Input.KeyBinding(new CommandParameterRouter(this), (KeyGesture)Gesture)); }
/// <summary> /// Adds a new gesture to associate inputbindings /// </summary> public void AddGesture(InputGesture gesture) { if (_inputBinding == null) { _inputBinding = new InputBindingCollection(); } _inputBinding.Add(new InputBinding(this, gesture)); }
public float QueryGesture(InputGesture ig) { float sum = 0.0f; for ( int i = 1; i < ig.States.Count; i++ ) { sum += (float)Math.Abs(ig.States[i].Component(JointName, JointComponent) - ig.States[i-1].Component(JointName, JointComponent)); } return sum / (float)ig.States.Count; }
public float QueryGesture(InputGesture ig) { float np = ig.States[0].Component(JointName, JointComponent) + ig.States[ig.States.Count - 1].Component(JointName, JointComponent); np /= 2.0f; float posd = ig.States.Select(x => x.Component(JointName, JointComponent)).Where(x => x >= np).Select(x => x - np).Sum(), negd = ig.States.Select(x => x.Component(JointName, JointComponent)).Where(x => x < np).Select(x => x - np).Sum(); return posd + negd; }
public FullscreenCommand(string name, MainWindow wnd, InputGesture inputGesture) : base(name, inputGesture) { this.wnd = wnd; this.wnd.PreviewKeyDown += wnd_PreviewKeyDown; this.fullscreenHandler = new FullscreenHandler(wnd); this.fullscreenHandler.FullscreenChanged += fullscreenHandler_FullscreenChanged; }
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]); }
/// <summary> /// ジェスチャーの追加を行います /// </summary> /// <param name="gesture">Gesture.</param> public void RegisterGesture(InputGesture gesture) { var index = this.gestures.FindIndex(g => g.Order > gesture.Order); if (index < 0) { index = this.gestures.Count; } this.gestures.Insert(index, gesture); }
public float QueryGesture(InputGesture ig) { float np = ig.States[0].Component(JointName, JointComponent) + ig.States[ig.States.Count - 1].Component(JointName, JointComponent); np /= 2.0f; float posd = ig.States.Select(x => x.Component(JointName, JointComponent)).Where(x => x >= np).Select(x => x - np).Sum(), negd = ig.States.Select(x => x.Component(JointName, JointComponent)).Where(x => x < np).Select(x => x - np).Sum(); return(posd + negd); }
public float QueryGesture(InputGesture ig) { float sum = 0.0f; for (int i = 1; i < ig.States.Count; i++) { sum += (float)Math.Abs(ig.States[i].Component(JointName, JointComponent) - ig.States[i - 1].Component(JointName, JointComponent)); } return(sum / (float)ig.States.Count); }
public RecognizerResult RecognizeSingleGesture(InputGesture g) { foreach ( var js in g.States ) { if ( mFeatures[0].QueryFrame(js) > 0.0f ) { var res = RecognizerResult.Empty(); res.Gesture1 = "high_kick"; res.Confidence1 = 100.0f; return res; } } return RecognizerResult.Empty(); }
public void SetShortcut(DependencyObject view, InputGesture gesture, object handler) { var inputBindingTrigger = new InputBindingTrigger(); inputBindingTrigger.InputBinding = new InputBinding(new RoutedCommand(), gesture); //var target = ViewLocator.LocateForModel(handler, null, null); Interaction.GetTriggers(view).Add(inputBindingTrigger); inputBindingTrigger.Actions.Add(new TestTriggerAction(handler)); }
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]); }
/// <summary> /// Adds a new gesture to associate inputbindings /// </summary> public DelegateCommand AddGesture(InputGesture gesture) { if (this.inputBindings == null) { this.inputBindings = new InputBindingCollection(); } this.inputBindings.Add(new InputBinding(this, gesture)); return(this); }
public InputGesture[] GetGestures() { InputGesture[] gestures = new InputGesture[modifierCombinations.Length]; int i = 0; foreach (var modifier in modifierCombinations) { gestures[i++] = CreateGesture(modifier); } return(gestures); }
private void SetupKeybind(InputGesture keyGesture, ExecutedRoutedEventHandler onPress) { var changeItemValues = new RoutedCommand(); var ib = new InputBinding(changeItemValues, keyGesture); InputBindings.Add(ib); // Bind handler. var cb = new CommandBinding(changeItemValues); cb.Executed += onPress; CommandBindings.Add(cb); }
public MainWindowCommand(string text, string name, InputGesture gesture = null, bool noImage = false) : base(text, name, typeof(MainWindow)) { if (gesture != null) { InputGestures.Add(gesture); } if (!noImage && !string.IsNullOrEmpty(name)) { string packUri = string.Format("pack://application:,,,/CommandIcons/{0}.png", name); ImageSource = new ImageSourceConverter().ConvertFromString(packUri) as ImageSource; } }
private void OnSelectedCommandChanged() { InputGesture inputGesture = null; if (!string.IsNullOrWhiteSpace(SelectedCommand)) { inputGesture = _commandManager.GetInputGesture(SelectedCommand); } SelectedCommandInputGesture = inputGesture; SelectedCommandNewInputGesture = null; }
private static InputGestureCollection WrapGesture(InputGesture gesture) { var list = new System.Collections.ArrayList(); if (null != gesture) { list.Add(gesture); } var coll = new InputGestureCollection(list); return(coll); }
public float QueryGesture(InputGesture ig) { Func<JointState, float> f = x => x.Component(JointName, JointComponent); float min = ig.States.Min(f), max = ig.States.Max(f); if ( Directional ) { bool before = ig.States.FindIndex(x => x.Component(JointName, JointComponent) == min) < ig.States.FindIndex(x => x.Component(JointName, JointComponent) == max); return (before) ? max - min : min - max; } else { return max - min; } }
private void BindMacro(InputGesture gesture, Action <PadEditor> action) { var oldBinding = InputBindings.OfType <InputBinding>().FirstOrDefault(i => i.Gesture.Equals(gesture)); if (oldBinding != null) { InputBindings.Remove(oldBinding); } InputBindings.Add( new InputBinding(EditingCommands.HandleKey, gesture) { CommandParameter = action }); }
static public void BenchmarkRecognize() { var sw = new Stopwatch(); var gest = new InputGesture(new LogFileLoader("gestures/track_high_kick_01.log")); var numiters = 1000; sw.Start(); for ( int i = 0; i < numiters; i++ ) { foreach ( var f in Features.AllFeatures.GestureFeatures ) { f.QueryGesture(gest); } } sw.Stop(); Console.WriteLine("Elapsed time ({0} iters): {1}", numiters, sw.Elapsed); Console.WriteLine("Gestures per second: {0}", 1000.0f / (sw.ElapsedMilliseconds / (float)numiters)); }
public static void Main (string[] args) { string filename = "gestures/track_high_kick_00.log"; Command cmd = LogFileVisualizer.Command.ViewGesture; if ( args.Length > 0 ) { filename = args[0]; if ( args.Length > 1 ) { cmd = (LogFileVisualizer.Command)Enum.Parse(typeof(LogFileVisualizer.Command), args[1]); } } string whichJoint; switch ( cmd ) { case Command.ViewGesture: using ( var vw = new GestureJointVisualizer(filename) ) { vw.Run(30.0); } break; case Command.PlotJoint: whichJoint = GetJointName(); var gest1 = new InputGesture(new LogFileLoader(filename)); var jp = new JointPlotter(gest1, whichJoint, true); Application.Run(jp.DisplayPlots()); break; case Command.PlotJointsFromGestures: whichJoint = GetJointName(); var plotlist = new List<JointPlotter>(); var fnames = LogFileLoader.LogFilenames(filename); Form last = null; foreach ( var name in fnames ) { var gest2 = new InputGesture(new LogFileLoader(name)); var jp2 = new JointPlotter(gest2, whichJoint, false); plotlist.Add(jp2); last = jp2.DisplayPlots(); } Application.Run(last); break; } }
public JointPlotter(InputGesture g, string jointname, bool angle) { mGesture = g; mJointName = jointname; mPlotAngle = angle; }
static public IEnumerable<float> GestureFeatureResults(InputGesture ig) { return GestureFeatures.Select(x => x.QueryGesture(ig)); }
/// <summary> /// Equalses the specified other. /// </summary> /// <param name="other">The other.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> /// <exception cref="System.NotImplementedException"></exception> protected bool Equals(InputGesture other) { if (other == null) { return false; } if (Key != other.Key) { return false; } if (Modifiers != other.Modifiers) { return false; } return true; }
public float QueryGesture(InputGesture ig) { Func<JointState, float> f = x => x.Component(JN, JC); float count = 0.0f; float sum = 0.0f; for ( int i = 1; i < ig.States.Count; i++ ) { var state = ig.States[i]; if ( Cond(state) ) { sum += f(state) - f(ig.States[i-1]); count += 1.0f; } } return (count == 0.0f) ? 0.0f : sum / count; }
public float QueryGesture(InputGesture ig) { Func<JointState, float> f = x => x.Component(JN, JC); float min = ig.States.Min(f), max = ig.States.Max(f); float center = (max + min) / 2.0f; float dist_threshold = 0.5f; bool dir = (f(ig.States[1]) - f(ig.States[0])) > 0.0f; var count = 0; var sinceLast = 100; for ( int i = 1; i < ig.States.Count; i++ ) { float maxthres = (max - center) * dist_threshold; float minthres = (min - center) * dist_threshold; bool newdir = (f(ig.States[i]) - f(ig.States[i-1])) > 0.0f; if ( newdir != dir && sinceLast > 10 ) { float relpos = f(ig.States[i]) - center; if ( relpos > maxthres || relpos < minthres ) { count++; } sinceLast = 0; } dir = newdir; sinceLast++; } return (float)count / (float)ig.States.Count; }
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 float QueryGesture(InputGesture ig) { Func<JointState, float> f1 = x => x.Component(JN, JA), f2 = x => x.Component(JN, JB); double sum = 0.0f; for ( int i = 1; i < ig.States.Count; i++ ) { var state = ig.States[i]; var pstate = ig.States[i-1]; if ( f1(state) - f1(pstate) > 0.0f ) { sum += f2(state) - f2(pstate); } else { sum -= f2(state) - f2(pstate); } } return (float)(sum * 100.0) / (float)ig.States.Count; }
public float QueryGesture(InputGesture ig) { return ig.States.Select(x => (x.Pos(JN1) - x.Pos(JN2)).LengthFast).Max(); }
public float QueryGesture(InputGesture ig) { Func<JointState, float> f = x => x.NeckPos.Y; float min = ig.States.Min(f), max = ig.States.Max(f); return max - min; }
public float QueryGesture (InputGesture ig) { return ig.States.Sum(x => mFeature.QueryFrame(x)) / (float)ig.States.Count; }