question

Jramos avatar image
Jramos asked ·

The problem Recognition shape with ToggleSwitch

Hi:
the problem with ToggleSwitch, when I activate the ToggleSwitch does not do shape recognition but when I put it off it does shape recognitionlink text



private async void RecoShape_Toggled(object sender, RoutedEventArgs e)
{
var toggleSwitch = sender as ToggleSwitch;

if(toggleSwitch != null)
{
IF(tggleswitch.IsOn == true)

 {
     recognitionCanvas.visibility = visibility.Visible;
 }

}

}

windows-uwp-xaml
7 comments
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I made a sample on my side. A Canvas in the XAML and a ToggleSwitch to control the visibility. When I click on the ToggleSwitch, the canvas appears and disappears as expected. Could you please share more details about your issue?

0 Votes 0 · ·

Hi:


When I draw on the InkCanvas for example a triangle and active toggle swtich does the recognition but when I activate the toggleSwitch before and then I do by jemplo the triangle does not produce the recognition of shape


0 Votes 0 · ·

Well, I tried with inkcanvas. When I click the ToggleSwitch to make the Inkcanvas show and disappear, I could always draw ink in the Inkcanvas. I do not quite understand what do you mean about this- ‘ I do by jemplo the triangle does not produce the recognition of shape’. Is jemplo a third party library? If it is, what does it do?

0 Votes 0 · ·

HI:


Draw Triagle : if you turn on the Toggle Switch when, for example, the triangle does not do shape recognition.


2.Now if we draw the triangle and the ToggleSwitch is in "OFF" and activate "ON" it produces shape recognition.


.alt text in the picture refers to the first case of list


0 Votes 0 · ·

I tested the ink recognition you said. It works correctly on my side. Even the Toggleswitch is clicked to hide and show the Inkcanvas for many times, the ink recognition function works every time. Could you please check the Ink analysis sample (basic) sample from the document?


0 Votes 0 · ·

Hi:


Reviewing the documentation it seems that this may well be that the problem is in the ToggleSwitch is assumed when the Toggleswitch is activated to "On" before drawing and when drawing the triangle must do so automatically.


0 Votes 0 · ·

I don't understand you well. Have you tried the official document's sample? Adding a Toggleswitch and try to recognize the shape. On my side, it works correctly.

0 Votes 0 · ·

1 Answer

Jramos avatar image
Jramos answered ·

Hi:
this is the code of recoginition of form in class cs

 private readonly Canvas _reconigtionCanvas;
         private readonly InkCanvas _inkCanvas;
    
         InkAnalyzer inkAnalyzer = new InkAnalyzer();
         IReadOnlyList inkStrokes = null;
         InkAnalysisResult inkAnalysisResults = null;
    
    
         public InkRecognitionService(Canvas reconigtionCanvas, InkCanvas inkCanvas)
         {
             _reconigtionCanvas = reconigtionCanvas;
             _inkCanvas = inkCanvas;
    
    
         }
    
    
            
    
    
    
         public void DrawEllipse(InkAnalysisInkDrawing shape)
         {
             var points = shape.Points;
             Ellipse ellipse = new Ellipse();
    
             ellipse.Width = shape.BoundingRect.Width;
             ellipse.Width = shape.BoundingRect.Height;
    
             Canvas.SetTop(ellipse, shape.BoundingRect.Top);
             Canvas.SetLeft(ellipse, shape.BoundingRect.Left);
    
             var brush = new SolidColorBrush(Windows.UI.ColorHelper.FromArgb(255, 0, 0, 255));
             ellipse.Stroke = brush;
             ellipse.StrokeThickness = 2;
             _reconigtionCanvas.Children.Add(ellipse);
         }
    
         /// 
         /// 
         /// 
         /// 
    
         public void DrawPolygon(InkAnalysisInkDrawing shape)
         {
    
             List points = new List(shape.Points);
             Polygon polygon = new Polygon();
    
             foreach (Point point in points)
             {
                 polygon.Points.Add(point);
             }
    
             var brush = new SolidColorBrush(Windows.UI.ColorHelper.FromArgb(255, 0, 0, 255));
             polygon.Stroke = brush;
             polygon.StrokeThickness = 2;
             _reconigtionCanvas.Children.Add(polygon);
         }
    
    
         public  async Task RecognizeStrokes()
         {
    
    
            inkStrokes = _inkCanvas.InkPresenter.StrokeContainer.GetStrokes();
    
             if (inkStrokes.Count > 0)
             {
                 inkAnalyzer.AddDataForStrokes(inkStrokes);
    
                 inkAnalysisResults = await inkAnalyzer.AnalyzeAsync();
    
                 if (inkAnalysisResults.Status == InkAnalysisStatus.Updated)
                 {
                     var inkwordNodes =
                        inkAnalyzer.AnalysisRoot.FindNodes(
                            InkAnalysisNodeKind.InkWord);
                     foreach (InkAnalysisInkWord node in inkwordNodes)
                     {
    
                         foreach (var strokeId in node.GetStrokeIds())
                         {
                             var stroke = _inkCanvas.InkPresenter.StrokeContainer.GetStrokeById(strokeId);
                             stroke.Selected = true;
                         }
    
                         inkAnalyzer.RemoveDataForStrokes(node.GetStrokeIds());
                     }
    
                     _inkCanvas.InkPresenter.StrokeContainer.DeleteSelected();
    
                     var inkdrawingNodes =
                         inkAnalyzer.AnalysisRoot.FindNodes(
                             InkAnalysisNodeKind.InkDrawing);
    
                     foreach (InkAnalysisInkDrawing node in inkdrawingNodes)
                     {
                         if (node.DrawingKind == InkAnalysisDrawingKind.Drawing)
                         {
                             // Catch and process  unsupported shapes.
                         }
                         else
                         {
                             if (node.DrawingKind == InkAnalysisDrawingKind.Circle ||
                                  node.DrawingKind == InkAnalysisDrawingKind.Ellipse  )
                             {
                                 DrawEllipse(node);
                                   
                             }
                             else
                             {
                                 DrawPolygon(node);
    
                                   
    
    
                             }
                               
                             foreach (var strokeId in node.GetStrokeIds())
                             {
                                 var stroke = _inkCanvas.InkPresenter.StrokeContainer.GetStrokeById(strokeId);
                                 stroke.Selected = true;
                             }
                         }
    
                         inkAnalyzer.RemoveDataForStrokes(node.GetStrokeIds());
                     }
    
                     _inkCanvas.InkPresenter.StrokeContainer.DeleteSelected();
                 }
             }
    
    
    
         }
    
    
     }
 }
1 comment Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I tried the code, but it works well. Could you please tell me have you tried the official sample to see if it works on your side?

0 Votes 0 · ·