Example #1
0
        public void RecognizeGesture(List <RecPoint> points_at, bool strokeEnd, bool gestureEnd, int lp)
        {
            Gesture candidate    = new Gesture(points_at.GetRange(0, lp + 1).ToArray(), "", points_at[lp].StrokeID + 1);
            string  gestureClass = "";

            gestureClass = DG3.Recognizer.ClassifyParts(candidate, gesture_dataset, gestureEnd, strokeEnd, allow_excess_strokes);

            candidates.Add(candidate);
            if (gestureClass == "")
            {
                Gesture np = new Gesture(null, "Exceeded max number of strokes");
                recognized.Add(np);
                System.Windows.Application.Current.Dispatcher.Invoke(new Action(() => {
                    PredictedName.Text    = "Exceeded max number of strokes";
                    PredictedImage.Source = RenderImages.RenderToPNGImageSource(np);
                }));
            }
            else if (gestureClass.Contains('['))
            {
                string gestureTemplate = gestureClass.Split('[')[0].TrimEnd();
                int    nstrokes        = gestureClass.Split(',').Count();
                foreach (Gesture g in gesture_dataset)
                {
                    if (g.Name == gestureTemplate)
                    {
                        foreach (Gesture gp in g.Part_Combinations[nstrokes])
                        {
                            if (gp.Name == gestureClass)
                            {
                                recognized.Add(gp);
                                System.Windows.Application.Current.Dispatcher.Invoke(new Action(() => {
                                    PredictedName.Text    = "Recognized as: " + gestureClass;
                                    PredictedImage.Source = RenderImages.RenderToPNGImageSource(gp);
                                }));
                                break;
                            }
                        }
                        break;
                    }
                }
            }
            else
            {
                foreach (Gesture g in gesture_dataset)
                {
                    if (g.Name == gestureClass)
                    {
                        recognized.Add(g);
                        System.Windows.Application.Current.Dispatcher.Invoke(new Action(() => {
                            PredictedName.Text    = "Recognized as: " + gestureClass;
                            PredictedImage.Source = RenderImages.RenderToPNGImageSource(g);
                        }));
                        break;
                    }
                }
            }
        }
Example #2
0
        public ViewSamplesWindow(List <Gesture> prototypes)
        {
            InitializeComponent();
            samples = prototypes;
            int row_index    = 0;
            int column_index = 0;

            foreach (Gesture g in prototypes)
            {
                if (column_index >= SamplesGrid.ColumnDefinitions.Count)
                {
                    SamplesGrid.ColumnDefinitions.Add(new ColumnDefinition());
                }

                var dp  = new DockPanel();
                var txt = new System.Windows.Controls.Label();
                txt.Content = g.Name;
                var img = new System.Windows.Controls.Image();
                img.Source = RenderImages.RenderToPNGImageSource(g, true, true);
                img.Width  = 96;
                img.Height = 96;
                img.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                img.VerticalAlignment   = System.Windows.VerticalAlignment.Center;
                txt.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                txt.VerticalAlignment   = System.Windows.VerticalAlignment.Center;

                DockPanel.SetDock(txt, Dock.Top);
                DockPanel.SetDock(img, Dock.Top);

                dp.Children.Add(txt);
                dp.Children.Add(img);


                Border b = new Border();
                b.BorderBrush     = new SolidColorBrush(Colors.DarkBlue);
                b.BorderThickness = new Thickness(0);
                b.Background      = System.Windows.Media.Brushes.Transparent;
                b.Child           = dp;
                b.Width           = 164;
                b.Height          = 164;

                Grid.SetRow(b, row_index);
                Grid.SetColumn(b, column_index);
                SamplesGrid.Children.Add(b);
                b.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler((sender, e) => changeSample(sender, PartsGrid));
                b.MouseEnter          += new System.Windows.Input.MouseEventHandler(HighlightSelection);
                b.MouseLeave          += new System.Windows.Input.MouseEventHandler(MouseLeaveSelection);
                column_index++;
            }
        }
Example #3
0
        private void ShowParts(Grid targetGrid, Gesture t)
        {
            int row_index    = 0;
            int column_index = 0;

            foreach (var d in t.Part_Combinations)
            {
                foreach (var g in d.Value)
                {
                    if (column_index >= targetGrid.ColumnDefinitions.Count)
                    {
                        targetGrid.ColumnDefinitions.Add(new ColumnDefinition());
                    }

                    var dp  = new DockPanel();
                    var txt = new System.Windows.Controls.Label();
                    txt.Content = g.Name;
                    var img = new System.Windows.Controls.Image();
                    img.Source = RenderImages.RenderToPNGImageSource(g, true, true);
                    img.Width  = 96;
                    img.Height = 96;
                    img.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    img.VerticalAlignment   = System.Windows.VerticalAlignment.Center;
                    txt.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    txt.VerticalAlignment   = System.Windows.VerticalAlignment.Center;

                    DockPanel.SetDock(txt, Dock.Top);
                    DockPanel.SetDock(img, Dock.Top);

                    dp.Children.Add(txt);
                    dp.Children.Add(img);


                    Border b = new Border();
                    b.BorderBrush     = new SolidColorBrush(Colors.DarkBlue);
                    b.BorderThickness = new Thickness(0);
                    b.Background      = System.Windows.Media.Brushes.Transparent;
                    b.Child           = dp;
                    b.Width           = 164;
                    b.Height          = 164;

                    Grid.SetRow(b, row_index);
                    Grid.SetColumn(b, column_index);
                    targetGrid.Children.Add(b);
                    column_index++;
                }
            }
        }
Example #4
0
        private void ShowDataset(bool HighlightStrokes, bool HighlightParts = false)
        {
            int row_index = 0, column_index = 0;

            foreach (Gesture g in gesture_dataset)
            {
                if (g.SampleNumber == "01")
                {
                    if (column_index >= DatasetGrid.ColumnDefinitions.Count)
                    {
                        column_index = 0;
                        row_index++;
                    }
                    if (row_index >= DatasetGrid.RowDefinitions.Count)
                    {
                        DatasetGrid.RowDefinitions.Add(new RowDefinition());
                    }

                    var    dp          = new DockPanel();
                    var    txt         = new System.Windows.Controls.Label();
                    string pattern     = @"\d+$";
                    string replacement = "";
                    Regex  rgx         = new Regex(pattern);
                    txt.Content = rgx.Replace(g.Name, replacement);
                    var img = new System.Windows.Controls.Image();

                    img.Source = RenderImages.RenderToPNGImageSource(g, HighlightStrokes, HighlightParts);
                    img.Width  = 96;
                    img.Height = 96;
                    img.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    img.VerticalAlignment   = System.Windows.VerticalAlignment.Center;
                    txt.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    txt.VerticalAlignment   = System.Windows.VerticalAlignment.Center;

                    RenderOptions.SetBitmapScalingMode(img, BitmapScalingMode.HighQuality);

                    DockPanel.SetDock(txt, Dock.Top);
                    DockPanel.SetDock(img, Dock.Top);

                    dp.Children.Add(txt);
                    dp.Children.Add(img);


                    Border b = new Border();
                    b.BorderBrush     = new SolidColorBrush(Colors.DarkBlue);
                    b.BorderThickness = new Thickness(0);
                    b.Background      = System.Windows.Media.Brushes.Transparent;
                    b.Child           = dp;
                    b.Width           = 164;
                    b.Height          = 164;

                    Grid.SetRow(b, row_index);
                    Grid.SetColumn(b, column_index);
                    DatasetGrid.Children.Add(b);
                    b.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(viewGestureSkeleton);
                    b.MouseEnter          += new System.Windows.Input.MouseEventHandler(HighlightSelection);
                    b.MouseLeave          += new System.Windows.Input.MouseEventHandler(MouseLeaveSelection);
                    column_index++;
                }
            }
        }
Example #5
0
        private void ShowHistory(StackPanel target, List <Gesture> candidates, List <Gesture> recognized)
        {
            for (int i = 0; i < candidates.Count; i++)
            {
                Gesture c = candidates[i];
                Gesture r = recognized[i];

                var gpb = new GroupBox();

                var dpl     = new DockPanel();
                var timetxt = new System.Windows.Controls.Label();
                timetxt.Content = Math.Round(TimeSpan.FromMilliseconds(c.PointsRaw.Last().Time).TotalSeconds, 3);
                var img_candidate = new System.Windows.Controls.Image();
                img_candidate.Source = RenderImages.RenderToPNGImageSource(c);
                img_candidate.Width  = 96;
                img_candidate.Height = 96;

                var rectxt = new System.Windows.Controls.Label();
                rectxt.Content = r.Name;
                var img_recognized = new System.Windows.Controls.Image();
                img_recognized.Source = RenderImages.RenderToPNGImageSource(r);
                img_recognized.Width  = 96;
                img_recognized.Height = 96;

                gpb.Header = Math.Round(TimeSpan.FromMilliseconds(c.PointsRaw.Last().Time).TotalSeconds, 3) + "ms";

                var grid = new Grid();
                grid.ColumnDefinitions.Add(new ColumnDefinition());
                grid.ColumnDefinitions.Add(new ColumnDefinition());
                grid.Margin = new System.Windows.Thickness(10, 0, 0, 10);

                gpb.Content = grid;
                var stpInput   = new StackPanel();
                var inputLabel = new System.Windows.Controls.Label();
                inputLabel.Content = "Gesture Input";
                stpInput.Children.Add(inputLabel);
                var inpBorder = new Border();
                inpBorder.BorderThickness     = new System.Windows.Thickness(1);
                inpBorder.BorderBrush         = System.Windows.Media.Brushes.Black;
                inpBorder.Child               = img_candidate;
                inpBorder.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                inpBorder.VerticalAlignment   = System.Windows.VerticalAlignment.Center;
                inpBorder.Width               = 100;
                inpBorder.Height              = 100;
                stpInput.Children.Add(inpBorder);
                var stpPrediction = new StackPanel();
                stpPrediction.Children.Add(rectxt);
                var predBorder = new Border();
                predBorder.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                predBorder.VerticalAlignment   = System.Windows.VerticalAlignment.Center;
                predBorder.BorderThickness     = new System.Windows.Thickness(1);
                predBorder.BorderBrush         = System.Windows.Media.Brushes.Black;
                predBorder.Child  = img_recognized;
                predBorder.Width  = 100;
                predBorder.Height = 100;

                stpInput.HorizontalAlignment      = System.Windows.HorizontalAlignment.Center;
                stpInput.VerticalAlignment        = System.Windows.VerticalAlignment.Center;
                stpPrediction.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                stpPrediction.VerticalAlignment   = System.Windows.VerticalAlignment.Center;

                stpPrediction.Children.Add(predBorder);

                Grid.SetRow(stpInput, 0);
                Grid.SetColumn(stpInput, 0);
                Grid.SetRow(stpPrediction, 0);
                Grid.SetColumn(stpPrediction, 1);

                grid.Children.Add(stpInput);
                grid.Children.Add(stpPrediction);

                target.Children.Add(gpb);
            }
        }