Inheritance: IInkRecognizerContainer
示例#1
0
        public Page1()
        {
            this.InitializeComponent();

            penSize = minPenSize;// + penSizeIncrement * PenThickness.SelectedIndex;

            InkDrawingAttributes drawingAttributes = new InkDrawingAttributes();
            drawingAttributes.Color = Windows.UI.Colors.Red;
            drawingAttributes.Size = new Size(penSize, penSize);
            drawingAttributes.IgnorePressure = false;
            drawingAttributes.FitToCurve = true;

            inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes);
            inkCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Mouse | Windows.UI.Core.CoreInputDeviceTypes.Pen | Windows.UI.Core.CoreInputDeviceTypes.Touch;
            inkCanvas.InkPresenter.StrokesCollected += InkPresenter_StrokesCollected;
            inkCanvas.InkPresenter.StrokesErased += InkPresenter_StrokesErased;


            // Show the available recognizers
            inkRecognizerContainer = new InkRecognizerContainer();
            recoView = inkRecognizerContainer.GetRecognizers();
            if (recoView.Count > 0)
            {
                foreach (InkRecognizer recognizer in recoView)
                {
                    RecoName.Items.Add(recognizer.Name);
                }
            }
            else
            {
                RecoName.IsEnabled = false;
                RecoName.Items.Add("No Recognizer Available");
            }
            RecoName.SelectedIndex = 0;
        }
示例#2
0
        public Settings()
        {
            this.InitializeComponent();

            roamingSettings = ApplicationData.Current.RoamingSettings;
            localSettings = ApplicationData.Current.LocalSettings;

            inkRecognizerContainer = new InkRecognizerContainer();
            recognizerView = inkRecognizerContainer.GetRecognizers();

            if (recognizerView.Count > 0)
            {
                foreach (InkRecognizer recognizer in recognizerView)
                {
                    RecogizerName.Items.Add(recognizer.Name);
                }
            }
            else
            {
                RecogizerName.IsEnabled = false;
                RecogizerName.Items.Add("No Recognizer Available");
            }
            

            GetSettings();
        }
示例#3
0
        public MainPage()
        {
            this.InitializeComponent();

            ink.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Touch | Windows.UI.Core.CoreInputDeviceTypes.Pen | Windows.UI.Core.CoreInputDeviceTypes.Mouse;
            ink.InkPresenter.StrokeInput.StrokeContinued += StrokeInput_StrokeContinued;

           ink.InkPresenter.StrokesCollected += InkPresenter_StrokesCollected;

            var vec1 = new Vector() { Start = new Point() { X = 0, Y = 0 }, End = new Point { X = 1, Y = 1 } };
            var vec2 = new Vector() { Start = new Point() { X = 0, Y = 0 }, End = new Point { X = 1, Y = 0 } };

            System.Diagnostics.Debug.WriteLine("Ängle =" + vec2.Angle(vec1));



            inkRecognizerContainer = new InkRecognizerContainer();
            recoView = inkRecognizerContainer.GetRecognizers();
         

            // Set the text services so we can query when language changes
            textServiceManager = CoreTextServicesManager.GetForCurrentView();
            textServiceManager.InputLanguageChanged += TextServiceManager_InputLanguageChanged;

            SetDefaultRecognizerByCurrentInputMethodLanguageTag();


            
        }
示例#4
0
        private async void Recognize(object sender, EventArgs e)
        {
            if (Ink != null)
            {
                string str = string.Empty;
                IReadOnlyList<InkStroke> currentStrokes = Ink.InkPresenter.StrokeContainer.GetStrokes();
                if (currentStrokes.Count > 0)
                {
                    try
                    {
                        var inkRecognizerContainer = new InkRecognizerContainer();
                        var recognitionResults = await inkRecognizerContainer.RecognizeAsync(Ink.InkPresenter.StrokeContainer, InkRecognitionTarget.All);

                        if (recognitionResults.Count > 0)
                            foreach (var r in recognitionResults)
                                str += r.GetTextCandidates()[0];
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }

                if (_vm != null)
                    _vm.RecognizeResult(str);
            }
        }
示例#5
0
        private async void RecognizeButton_Click(object sender, RoutedEventArgs e)
        {
            var inkRecognizer = new InkRecognizerContainer();
            if (null != inkRecognizer)
            {
                var recognitionResults = await inkRecognizer.RecognizeAsync(this.InkCanvas.InkPresenter.StrokeContainer, InkRecognitionTarget.All);
                string recognizedText = string.Join(" ", recognitionResults.Select(i => i.GetTextCandidates()[0]));

                var messageDialog = new MessageDialog(recognizedText);
                await messageDialog.ShowAsync();
            }
        }
示例#6
0
 public static async Task<string> Recognize(this InkCanvas inkCanvas)
 {
     var strokes = inkCanvas.InkPresenter.StrokeContainer;
     if (strokes.GetStrokes().Any())
     {
         var recognizer = new InkRecognizerContainer();
         var results = await recognizer.RecognizeAsync(strokes, InkRecognitionTarget.All);
         var candidates = results.Select(x => x.GetTextCandidates().First());
         return string.Join(" ", candidates);
     }
     else
     {
         return string.Empty;
     }
 }
        public Scenario2()
        {
            this.InitializeComponent();

            // Initialize drawing attributes. These are used in inking mode.
            InkDrawingAttributes drawingAttributes = new InkDrawingAttributes();
            drawingAttributes.Color = Windows.UI.Colors.Red;
            double penSize = 4;
            drawingAttributes.Size = new Windows.Foundation.Size(penSize, penSize);
            drawingAttributes.IgnorePressure = false;
            drawingAttributes.FitToCurve = true;

            // Show the available recognizers
            inkRecognizerContainer = new InkRecognizerContainer();
            recoView = inkRecognizerContainer.GetRecognizers();
            if (recoView.Count > 0)
            {
                foreach (InkRecognizer recognizer in recoView)
                {
                    RecoName.Items.Add(recognizer.Name);
                }
            }
            else
            {
                RecoName.IsEnabled = false;
                RecoName.Items.Add("No Recognizer Available");
            }
            RecoName.SelectedIndex = 0;

            // Set the text services so we can query when language changes
            textServiceManager = CoreTextServicesManager.GetForCurrentView();
            textServiceManager.InputLanguageChanged += TextServiceManager_InputLanguageChanged;

            SetDefaultRecognizerByCurrentInputMethodLanguageTag();

            // Initialize reco tooltip
            recoTooltip = new ToolTip();
            recoTooltip.Content = InstallRecoText;
            ToolTipService.SetToolTip(InstallReco, recoTooltip);

            // Initialize the InkCanvas
            inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes);
            inkCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Mouse | Windows.UI.Core.CoreInputDeviceTypes.Pen | Windows.UI.Core.CoreInputDeviceTypes.Touch;

            this.Unloaded += Scenario2_Unloaded;
            this.SizeChanged += Scenario2_SizeChanged;
        }
        public Scenario2()
        {
            this.InitializeComponent();
            //read language related resource file .strings/en or zh-cn/resources.resw
            Run run1 = new Run();
            run1.Text = ResourceManagerHelper.ReadValue("Description2_p1");
            this.textDes.Inlines.Add(run1);
            this.textDes.Inlines.Add(new LineBreak());

            // Initialize drawing attributes. These are used in inking mode.
            InkDrawingAttributes drawingAttributes = new InkDrawingAttributes();
            drawingAttributes.Color = Windows.UI.Colors.Red;
            double penSize = 4;
            drawingAttributes.Size = new Windows.Foundation.Size(penSize, penSize);
            drawingAttributes.IgnorePressure = false;
            drawingAttributes.FitToCurve = true;

            // Show the available recognizers
            inkRecognizerContainer = new InkRecognizerContainer();
            recoView = inkRecognizerContainer.GetRecognizers();
            if (recoView.Count > 0)
            {
                foreach (InkRecognizer recognizer in recoView)
                {
                    RecoName.Items.Add(recognizer.Name);
                }
            }
            else
            {
                RecoName.IsEnabled = false;
                RecoName.Items.Add("No Recognizer Available");
            }
            RecoName.SelectedIndex = 0;

            // Set the text services so we can query when language changes
            textServiceManager = CoreTextServicesManager.GetForCurrentView();
            textServiceManager.InputLanguageChanged += TextServiceManager_InputLanguageChanged;

            SetDefaultRecognizerByCurrentInputMethodLanguageTag();

            // Initialize the InkCanvas
            inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes);
            inkCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Mouse | Windows.UI.Core.CoreInputDeviceTypes.Pen | Windows.UI.Core.CoreInputDeviceTypes.Touch;

            this.SizeChanged += Scenario2_SizeChanged;
        }
        public MainPage()
        {
            this.InitializeComponent();

            InkDrawingAttributes drawingAttributes = new InkDrawingAttributes();
            drawingAttributes.Color = Windows.UI.Colors.Black;
            drawingAttributes.Size = new Size(4, 4);
            drawingAttributes.IgnorePressure = false;
            drawingAttributes.FitToCurve = true;


            inkRecognizerContainer = new InkRecognizerContainer();
            recoView = inkRecognizerContainer.GetRecognizers();
            if (recoView.Count > 0)
            {
                foreach (InkRecognizer recognizer in recoView)
                {
                    RecoName.Items.Add(recognizer.Name);
                }
            }
            else
            {
                RecoName.IsEnabled = false;
                RecoName.Items.Add("No Recognizer Available");
            }
            RecoName.SelectedIndex = 0;



            InkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes);
            InkCanvas.InkPresenter.InputDeviceTypes = 
                Windows.UI.Core.CoreInputDeviceTypes.Mouse |
                Windows.UI.Core.CoreInputDeviceTypes.Pen |
                Windows.UI.Core.CoreInputDeviceTypes.Touch;

            // 音声合成の追加
            synthesizer = new SpeechSynthesizer();

        }
示例#10
0
        public MainPage()
        {
            this.InitializeComponent();

            roamingSettings = ApplicationData.Current.RoamingSettings;
            localSettings = ApplicationData.Current.LocalSettings;

            //Setup the default ink canvas attributes
            InkDrawingAttributes drawingAttributes = new InkDrawingAttributes();

            drawingAttributes.Color = Windows.UI.Colors.Black;
            drawingAttributes.Size = new Size(4, 4);
            drawingAttributes.IgnorePressure = false;
            drawingAttributes.FitToCurve = true;

            inkRecognizerContainer = new InkRecognizerContainer();
            recognizerView = inkRecognizerContainer.GetRecognizers();

            if(localSettings.Values.Keys.Contains("RecogniserName"))
            {
                var recogniserName = localSettings.Values["RecogniserName"];
                SetRecognizerByName(recogniserName.ToString());
                Status.Text = recogniserName.ToString();
            }
           
            inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes);

            //Allow Mouse, Pen and Touch inputs to the ink canvas (default is pen only)
            inkCanvas.InkPresenter.InputDeviceTypes =
                CoreInputDeviceTypes.Mouse |
                //CoreInputDeviceTypes.Touch |
                CoreInputDeviceTypes.Pen;

            //Register the StrokeCollected event
            inkCanvas.InkPresenter.StrokesCollected += InkPresenter_StrokesCollected;

            GetTextFile();
        }
示例#11
0
        public MainPage()
        {


            this.InitializeComponent();
            InkDrawingAttributes drawingAttributes = new InkDrawingAttributes();
            drawingAttributes.Color = Windows.UI.Colors.Black;
            drawingAttributes.Size = new Size(4, 4);
            drawingAttributes.IgnorePressure = false;
            drawingAttributes.FitToCurve = true;

            inkRecognizerContainer = new InkRecognizerContainer();
            recoView = inkRecognizerContainer.GetRecognizers();
            if (recoView.Count > 0)
            {
                foreach (InkRecognizer recognizer in recoView)
                {
                    RecoName.Items.Add(recognizer.Name);
                }
            }
            else
            {
                RecoName.IsEnabled = false;
                RecoName.Items.Add("No Recognizer Available");
            }
            RecoName.SelectedIndex = 0;

            // Set the text services so we can query when language changes
            textServiceManager = CoreTextServicesManager.GetForCurrentView();
            textServiceManager.InputLanguageChanged += TextServiceManager_InputLanguageChanged;

            SetDefaultRecognizerByCurrentInputMethodLanguageTag();

            InkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes);
            InkCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Mouse | Windows.UI.Core.CoreInputDeviceTypes.Pen | Windows.UI.Core.CoreInputDeviceTypes.Touch;

        }
示例#12
0
        public void inking_initialization()
        {

            
            myInkCanvas.Width = rootGrid.ActualWidth;
            myInkCanvas.Height = rootGrid.ActualHeight;

            InkDrawingAttributes drawingAttributes = new InkDrawingAttributes();
            drawingAttributes.Color = Windows.UI.Colors.Black;
            drawingAttributes.Size = new Size(4, 4);
            drawingAttributes.IgnorePressure = false;
            drawingAttributes.FitToCurve = true;


            try
            {
                inkRecognizerContainer = new InkRecognizerContainer();
                recoView = inkRecognizerContainer.GetRecognizers();
                if (recoView.Count > 0)
                {
                    inkRecognizerContainer.SetDefaultRecognizer(recoView.First());
                }
            }
            catch (Exception)
            {
                System.Diagnostics.Debug.WriteLine("Couldn't initialize InkRecognizer");
            }

            myInkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(
                drawingAttributes);
            myInkCanvas.InkPresenter.InputDeviceTypes =
                Windows.UI.Core.CoreInputDeviceTypes.Mouse |
                Windows.UI.Core.CoreInputDeviceTypes.Pen |
                Windows.UI.Core.CoreInputDeviceTypes.Touch;


        }
示例#13
0
        private async void Reco_Click(object sender, RoutedEventArgs e)
        {
            if (inkCanvas.InkPresenter.StrokeContainer.GetStrokes().Count > 0)
            {
                var recognizer = new InkRecognizerContainer();
                var recognitionResults = await recognizer.RecognizeAsync(inkCanvas.InkPresenter.StrokeContainer, InkRecognitionTarget.All);

                string result = "";
                //justACanvas.Children.Clear();

                if (recognitionResults.Count > 0)
                {
                    foreach (var r in recognitionResults)
                    {
                        var candidates = r.GetTextCandidates();
                        result += " " + candidates[0];

                        //var rect = r.BoundingRect;
                        //var text = new TextBlock();
                        //text.Text = candidates[0];
                        //justACanvas.Children.Add(text);
                        //Canvas.SetTop(text, rect.Bottom + 5);
                        //Canvas.SetLeft(text, rect.Left);
                    }
                }
                else
                    result = "NO TEXT RECOGNIZED!";

                recoResult.Text = result;
            }
        }
        private async Task RecognizeInkerText()
        {
            var inkRecognizer = new InkRecognizerContainer();
            var recognitionResults = await inkRecognizer.RecognizeAsync(Inker.InkPresenter.StrokeContainer, InkRecognitionTarget.All);

            List<TextBox> boxes = new List<TextBox>();

            foreach (var result in recognitionResults)
            {
                List<UIElement> elements = new List<UIElement>(
                    VisualTreeHelper.FindElementsInHostCoordinates(
                        new Rect(new Point(result.BoundingRect.X, result.BoundingRect.Y),
                        new Size(result.BoundingRect.Width, result.BoundingRect.Height)),
                    this));

                TextBox box = elements.Where(el => el is TextBox && (el as TextBox).IsEnabled).FirstOrDefault() as TextBox;

                if (box != null)
                {
                    if (!boxes.Contains(box))
                    {
                        boxes.Add(box);
                        box.Text = "";
                    }
                    box.Text +=  result.GetTextCandidates().FirstOrDefault().Trim();
                }
            }

            Inker.InkPresenter.StrokeContainer.Clear();
        }
示例#15
0
        private async void reco_Click(object sender, RoutedEventArgs e)
        {
            if (ink.InkPresenter.StrokeContainer.GetStrokes().Count > 0)
            {
                var recognizer = new InkRecognizerContainer();
                var recognitionResults = await recognizer.RecognizeAsync(ink.InkPresenter.StrokeContainer, InkRecognitionTarget.All);

                string result = "";
                //justACanvas.Children.Clear();

                if (recognitionResults.Count > 0)
                {
                    foreach (var r in recognitionResults)
                    {
                        var candidates = r.GetTextCandidates();
                        result += " " + candidates[0];
                        
                    }
                }
                else
                    result = "NO TEXT RECOGNIZED!";

                RecoResult.Text = result;
            }
        }
示例#16
0
        protected override void OnApplyTemplate()
        {
            container = this.GetTemplateChild(ContainerName) as Grid;
            textBox = this.GetTemplateChild(TextBoxName) as TextBox;
            inkCanvas = this.GetTemplateChild(InkCanvasName) as InkCanvas;
            inkBorder = this.GetTemplateChild(InkBorderName) as Border;
            inkWindow = this.GetTemplateChild(InkWindowName) as Popup;

            inkRecognizerContainer = new InkRecognizerContainer();
            recognizers = inkRecognizerContainer.GetRecognizers();

            // Set the text services so we can query when language changes
            textServiceManager = CoreTextServicesManager.GetForCurrentView();
            textServiceManager.InputLanguageChanged += TextServiceManager_InputLanguageChanged;

            SetDefaultRecognizerByCurrentInputMethodLanguageTag();

            // Create a timer that expires after 1 second
            recognitionTimer = new DispatcherTimer();
            recognitionTimer.Interval = new TimeSpan(0, 0, 1);
            recognitionTimer.Tick += RecoTimer_Tick;

            pointerTimer = new DispatcherTimer();
            pointerTimer.Interval = new TimeSpan(0, 0, 2);
            pointerTimer.Tick += PointerTimer_Tick;

            textBox.PointerEntered += TextBox_PointerEntered;
            textBox.AddHandler(PointerPressedEvent, new PointerEventHandler(TextBox_PointerPressed), true);
            textBox.SelectionChanged += TextBox_SelectionChanged;

            inkCanvas.PointerEntered += InkCanvas_PointerEntered;
            inkCanvas.InkPresenter.StrokesCollected += InkCanvas_StrokesCollected;
            inkCanvas.InkPresenter.StrokeInput.StrokeStarted += InkCanvas_StrokeStarted;
            inkCanvas.InkPresenter.StrokesErased += InkPresenter_StrokesErased;
            
            // Initialize drawing attributes. These are used in inking mode.
            InkDrawingAttributes drawingAttributes = new InkDrawingAttributes();
            drawingAttributes.Color = InkColor;
            double penSize = PenSize;
            drawingAttributes.Size = new Windows.Foundation.Size(penSize, penSize);
            drawingAttributes.IgnorePressure = false;
            drawingAttributes.FitToCurve = true;

            // Initialize the InkCanvas
            inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes);
            inkCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Pen;

            //InputPane inputPane = InputPane.GetForCurrentView();
            //inputPane.Showing += InputPane_Showing;

            this.SizeChanged += InkTextBox_SizeChanged;

            enableText();
            base.OnApplyTemplate();
        }
示例#17
0
        private async Task RecognizeInkerText()
        {
            System.Diagnostics.Debug.WriteLine("RecognizeInkerText");
            try
            {
                var inkRecognizer = new InkRecognizerContainer();
                var recognitionResults = await inkRecognizer.RecognizeAsync(inker.InkPresenter.StrokeContainer, InkRecognitionTarget.All);

                List<TextBox> textBoxes = new List<TextBox>();

                string value = string.Empty; 

                foreach (var result in recognitionResults)
                {
                    if (TargetTextControl == null)
                    {
                        Point p = new Point(result.BoundingRect.X, result.BoundingRect.Y);
                        Size s = new Size(result.BoundingRect.Width, result.BoundingRect.Height);
                        Rect r = new Rect(p, s);
                        var elements = VisualTreeHelper.FindElementsInHostCoordinates(r, contentPresenter);

                        TextBox box = elements.Where(el => el is TextBox && (el as TextBox).IsEnabled).FirstOrDefault() as TextBox;
                        if (box != null)
                        {
                            if (!textBoxes.Contains(box))
                            {
                                textBoxes.Add(box);
                                box.Text = "";
                            }
                            if (string.IsNullOrEmpty(box.Text) == false)
                                box.Text += " ";
                            box.Text += result.GetTextCandidates().FirstOrDefault().Trim();
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(value) == false)
                            value += " ";
                        value += result.GetTextCandidates().FirstOrDefault().Trim();
                    }
                        
                }

                if (TargetTextControl != null)
                {
                    var type = TargetTextControl.GetType();
                    PropertyInfo pInfo = type.GetProperty(TEXT_PROPERTY_NAME);
                    pInfo.SetValue(TargetTextControl, value);
                }

                inker.InkPresenter.StrokeContainer.Clear();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }