Example #1
0
        /// <summary>
        /// 识别
        /// </summary>
        /// <param name="strokes">笔迹集合</param>
        /// <returns>候选词数组</returns>
        public string[] Recognize(StrokeCollection strokes)
        {
            if (strokes == null || strokes.Count == 0)
            {
                return(Params.EmptyAlternates);
            }

            var analyzer = new InkAnalyzer();

            analyzer.AddStrokes(strokes, Params.SimplifiedChineseLanguageId);
            analyzer.SetStrokesType(strokes, StrokeType.Writing);

            var status = analyzer.Analyze();

            if (status.Successful)
            {
                return(analyzer.GetAlternates()
                       .OfType <AnalysisAlternate>()
                       .Select(x => x.RecognizedString)
                       .ToArray());
            }

            analyzer.Dispose();

            return(Params.EmptyAlternates);
        }
 private void InkCanvas_StrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e)
 {
     InkAnalyzer analyser = new InkAnalyzer();
     analyser.AddStrokes(_inkCanvas.Strokes);
     analyser.Analyze();
     _inkResults.Text = analyser.GetRecognizedString();
     e.Handled = false;
 }
Example #3
0
        private void InsertButton_Click(object sender, RoutedEventArgs e)
        {
            InkAnalyzer inkAnalyzer = new InkAnalyzer();

            inkAnalyzer.AddStrokes(insertionBox.InkCanvas.Strokes);
            inkAnalyzer.Analyze();
            InkUtils.MergeParagraphs(inkAnalyzer);
            insertReflow.process(inkAnalyzer);
            insertionBox.Visibility = Visibility.Collapsed;
            inserter.insertStrokes(this.inkAnalyzer, MainInkCanvas, insertionBox.InkCanvas);
        }
        // IACore,IAWinFx
        //  C:\Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7
        // IALoader
        //  C:\Program Files\Microsoft SDKs\Windows\v6.1\Bin
        // それぞれのライブラリは「Windows SDK for Windows Server 2008 and .NET Framework 3.5」で取得できる
        //  http://www.microsoft.com/en-us/download/confirmation.aspx?id=11310
        private string InkAnalyze(InkCanvas canvas)
        {
            InkAnalyzer theInkAnalyzer = new InkAnalyzer();

            // キャンバスに描かれた文字を認識するためにアナライザにストロークをセット
            theInkAnalyzer.AddStrokes(canvas.Strokes);
            theInkAnalyzer.SetStrokesType(canvas.Strokes, StrokeType.Writing);

            // 文字を解析
            theInkAnalyzer.Analyze();

            // 文字を解析した結果の第1候補を返す
            return(theInkAnalyzer.GetRecognizedString());
        }
        // IACore,IAWinFx
        //  C:\Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7
        // IALoader
        //  C:\Program Files\Microsoft SDKs\Windows\v6.1\Bin
        // それぞれのライブラリは「Windows SDK for Windows Server 2008 and .NET Framework 3.5」で取得できる
        //  http://www.microsoft.com/en-us/download/confirmation.aspx?id=11310
        private string InkAnalyze( InkCanvas canvas )
        {
            InkAnalyzer theInkAnalyzer = new InkAnalyzer();

            // キャンバスに描かれた文字を認識するためにアナライザにストロークをセット
            theInkAnalyzer.AddStrokes( canvas.Strokes );
            theInkAnalyzer.SetStrokesType( canvas.Strokes, StrokeType.Writing );

            // 文字を解析
            theInkAnalyzer.Analyze();

            // 文字を解析した結果の第1候補を返す
            return theInkAnalyzer.GetRecognizedString();
        }
Example #6
0
        public static void transposeStrokes(InkAnalyzer inkAnalyzer, StrokeCollection strokes, double offsetX, double offsetY)
        {
            if (inkAnalyzer != null)
            {
                inkAnalyzer.RemoveStrokes(strokes);
            }

            Matrix transform = new Matrix();

            transform.Translate(offsetX, offsetY);
            strokes.Transform(transform, false);

            if (inkAnalyzer != null)
            {
                inkAnalyzer.AddStrokes(strokes);
            }
        }
        public HttpResponseMessage<String> Recognize(string strokes)
        {
            var strokePointsData = JsonConvert.DeserializeObject<dynamic>(strokes);

            var strokeCollection = GetStrokeCollectionFromPoints(strokePointsData);

            var inkAnalyzer = new InkAnalyzer();

            inkAnalyzer.AddStrokes(strokeCollection);

            var analysisStatus = inkAnalyzer.Analyze();

            if (analysisStatus.Successful)
            {
                var recognizedString = inkAnalyzer.GetRecognizedString();
                return new HttpResponseMessage<string>(recognizedString);
            }
            else
                return new HttpResponseMessage<string>("Data not recognized");
        }
        public String Recognize([FromBody] Results.Stroke stroke)
        {
            var strokePointsData = JsonConvert.DeserializeObject<dynamic>(stroke.Json);

            var strokeCollection = GetStrokeCollectionFromPoints(strokePointsData);

            var inkAnalyzer = new InkAnalyzer();

            inkAnalyzer.AddStrokes(strokeCollection);

            var analysisStatus = inkAnalyzer.Analyze();

            if (analysisStatus.Successful)
            {
                var recognizedString = inkAnalyzer.GetRecognizedString();
                return recognizedString;
            }
            else
                return "Data not recognized";
        }
        private void btnAnalyze_Click(object sender, RoutedEventArgs e)
        {
            InkAnalyzer theInkAnalyzer = new InkAnalyzer();

            // キャンバスに描かれた文字を認識するためにアナライザにストロークをセット
            theInkAnalyzer.AddStrokes(InkCanvas1.Strokes);
            theInkAnalyzer.SetStrokesType(InkCanvas1.Strokes, StrokeType.Writing);

            // 文字を解析
            theInkAnalyzer.Analyze();

            // 文字を解析した結果の第1候補を表示する
            MessageBox.Show(theInkAnalyzer.GetRecognizedString());

            // その他の候補を表示する
            AnalysisAlternateCollection alternates = theInkAnalyzer.GetAlternates();

            foreach (var alternate in alternates)
            {
                MessageBox.Show(alternate.RecognizedString);
            }
        }
        public HttpResponseMessage <String> Recognize(string strokes)
        {
            var strokePointsData = JsonConvert.DeserializeObject <dynamic>(strokes);

            var strokeCollection = GetStrokeCollectionFromPoints(strokePointsData);

            var inkAnalyzer = new InkAnalyzer();

            inkAnalyzer.AddStrokes(strokeCollection);

            var analysisStatus = inkAnalyzer.Analyze();

            if (analysisStatus.Successful)
            {
                var recognizedString = inkAnalyzer.GetRecognizedString();
                return(new HttpResponseMessage <string>(recognizedString));
            }
            else
            {
                return(new HttpResponseMessage <string>("Data not recognized"));
            }
        }
        public String Recognize([FromBody] Results.Stroke stroke)
        {
            var strokePointsData = JsonConvert.DeserializeObject <dynamic>(stroke.Json);

            var strokeCollection = GetStrokeCollectionFromPoints(strokePointsData);

            var inkAnalyzer = new InkAnalyzer();

            inkAnalyzer.AddStrokes(strokeCollection);

            var analysisStatus = inkAnalyzer.Analyze();

            if (analysisStatus.Successful)
            {
                var recognizedString = inkAnalyzer.GetRecognizedString();
                return(recognizedString);
            }
            else
            {
                return("Data not recognized");
            }
        }
        public MyInkAnalyzer(StrokeCollection strokeCollection)
        {
            if (strokeCollection.Count > 0)
            {
                _strokeCollection = strokeCollection;
                analyze           = new InkAnalyzer();
                //2052:简体中文 1033:英语
                analyze.AddStrokes(strokeCollection, GlobalValues.InkAnalyzerLanguageId);
                //analyze.BackgroundAnalyze();

                AnalysisStatus status = analyze.Analyze();

                if (status.Successful)
                {
                    analyzeResults = analyze.GetRecognizedString();
                }
                else
                {
                    analyzeResults = "Recognition Failed";
                }

                analyze.RemoveStrokes(_strokeCollection);
            }
        }
Example #13
0
        ///Draw handwritings
        //private void DrawHandwriting(Skeleton skeleton, DrawingContext drawingContext)
        //{

        //    Joint handRightJoint = skeleton.Joints[JointType.HandRight];
        //    Point handRightPoint = SkeletonPointToScreen(handRightJoint.Position);

        //    Joint handLeftJoint = skeleton.Joints[JointType.HandLeft];
        //    Point handLeftPoint = SkeletonPointToScreen(handLeftJoint.Position);


        //    if (handLeftPoint.Y < handRightPoint.Y)
        //    {
        //        if (!handwritings.Points.Contains(handRightPoint))
        //        {
        //            handwritings.Points.Add(handRightPoint);
        //        }
        //        for (int i = 0; i < handwritings.Points.Count - 1; i++)
        //        {
        //            drawingContext.DrawLine(new Pen(Brushes.Yellow, 3), handwritings.Points[i], handwritings.Points[i + 1]);
        //        }
        //    }
        //    else
        //        handwritings.Points.Clear();  // To clear the old painting

        //    if (handwritings.Points.Count > 0)
        //    {
        //        StylusPointCollection spc = new StylusPointCollection();
        //        for (int i = 0; i < handwritings.Points.Count; i++)
        //        {
        //            spc.Add(new StylusPoint(handwritings.Points[i].X, handwritings.Points[i].Y));
        //        }

        //        Stroke s = new Stroke(spc);
        //        StrokeCollection sc = new StrokeCollection(new Stroke[] { s });

        //        InkAnalyzer inkAnalyzer = new InkAnalyzer();
        //        inkAnalyzer.AddStrokes(sc);
        //        AnalysisStatus status = inkAnalyzer.Analyze();
        //        if (status.Successful)
        //        {
        //            textBlockResult.Text = inkAnalyzer.GetRecognizedString();
        //            sc.Clear();
        //        }
        //    }
        //}

        private void DrawColorfulHandwriting(Skeleton skeleton, DrawingContext drawingContext)
        {
            Joint handRightJoint = skeleton.Joints[JointType.HandRight];
            Point handRightPoint = SkeletonPointToScreen(handRightJoint.Position);

            Joint handLeftJoint = skeleton.Joints[JointType.HandLeft];
            Point handLeftPoint = SkeletonPointToScreen(handLeftJoint.Position);

            int depth = SkeletonDepthToScreen(handRightJoint.Position);

            //SolidColorBrush brush = new SolidColorBrush();
            int fontsize;

            if (depth < 1500)
            {
                //brush = Brushes.White;
                fontsize = 36;
            }
            else if (depth < 2000)
            {
                //brush = Brushes.Pink;
                fontsize = 56;
            }
            else
            {
                //brush = Brushes.Red;
                fontsize = 72;
            }

            if (handLeftPoint.Y < handRightPoint.Y)
            {
                if (!handwritings.Points.Contains(handRightPoint))
                {
                    handwritings.Points.Add(handRightPoint);
                }
                for (int i = 0; i < handwritings.Points.Count - 1; i++)
                {
                    drawingContext.DrawLine(new Pen(brush, 3), handwritings.Points[i], handwritings.Points[i + 1]);
                }
                //StartSineWave(depth);
            }
            else
            {
                StopSineWave();
                handwritings.Points.Clear();  // To clear the old painting
            }
            if (handwritings.Points.Count > 0)
            {
                StylusPointCollection spc = new StylusPointCollection();
                for (int i = 0; i < handwritings.Points.Count; i++)
                {
                    spc.Add(new StylusPoint(handwritings.Points[i].X, handwritings.Points[i].Y));
                }

                Stroke           s  = new Stroke(spc);
                StrokeCollection sc = new StrokeCollection(new Stroke[] { s });

                InkAnalyzer inkAnalyzer = new InkAnalyzer();
                inkAnalyzer.AddStrokes(sc);
                AnalysisStatus status = inkAnalyzer.Analyze();
                if (status.Successful)
                {
                    textBlockResult.Text     = inkAnalyzer.GetRecognizedString();
                    textBlockResult.FontSize = fontsize;
                    sc.Clear();
                }
            }
        }
Example #14
0
        private void OCRText(int mode = 0)
        {
            StrokeCollection sc;

            switch (mode)
            {
            case 0:
                sc = OCRCanvas.Strokes;
                break;

            case 1:
                sc = TegakiCanvas.GetSelectedStrokes();
                break;

            default:
                return;
            }

            ia = new InkAnalyzer();
            if (sc.Count == 0)
            {
                return;
            }
            CustomRecognizerNode node;
            double x, y;
            int    height;

            getStrokeZahyo(sc, out x, out y, out height);

            // キャンバスに描かれた文字を認識するためにアナライザにストロークをセット
            if (EngineList.SelectedItem != null)
            {
                node = ia.CreateCustomRecognizer((Guid)EngineList.SelectedValue);
                ia.AddStrokesToCustomRecognizer(sc, node);
            }
            else
            {
                ia.AddStrokes(sc);
            }
            ia.SetStrokesType(sc, StrokeType.Writing);

            // 文字を解析
            ia.Analyze();

            //罫線にピタッとなるようにする
            y = ((int)((y + lineMargine / 2) / lineMargine) * lineMargine) + 1 * (int)((y + lineMargine / 2) / lineMargine);

            height = (int)((height + lineMargine / 2) / lineMargine) * lineMargine;
            if (height >= 8)
            {
                TextBlock tb = new TextBlock()
                {
                    Text = ia.GetRecognizedString(), FontSize = height - 8, VerticalAlignment = System.Windows.VerticalAlignment.Top, LineStackingStrategy = LineStackingStrategy.BlockLineHeight, LineHeight = height
                };
                //noteRoot.Children.Add(tb);
                TegakiCanvas.Children.Add(tb);
                InkCanvas.SetLeft(tb, x);
                InkCanvas.SetTop(tb, y);
            }
            //textBox1.Text += ia.GetRecognizedString();
            switch (mode)
            {
            case 0:
                OCRCanvas.Strokes.Clear();
                break;

            case 1:
                foreach (Stroke s in sc)
                {
                    TegakiCanvas.Strokes.Remove(s);
                }
                break;
            }

            /*
             * // その他の候補を表示する
             * AnalysisAlternateCollection alternates = theInkAnalyzer.GetAlternates();
             * foreach (var alternate in alternates)
             * MessageBox.Show(alternate.RecognizedString);
             */
        }
Example #15
0
        public static void transposeStrokes(InkAnalyzer inkAnalyzer, StrokeCollection strokes, double offsetX, double offsetY)
        {
            if(inkAnalyzer != null)
            {
                inkAnalyzer.RemoveStrokes(strokes);
            }

            Matrix transform = new Matrix();
            transform.Translate(offsetX, offsetY);
            strokes.Transform(transform, false);

            if(inkAnalyzer != null)
            {
                inkAnalyzer.AddStrokes(strokes);
            }
        }
Example #16
0
 private void InsertButton_Click(object sender, RoutedEventArgs e)
 {
     InkAnalyzer inkAnalyzer = new InkAnalyzer();
     inkAnalyzer.AddStrokes(insertionBox.InkCanvas.Strokes);
     inkAnalyzer.Analyze();
     InkUtils.MergeParagraphs(inkAnalyzer);
     insertReflow.process(inkAnalyzer);
     insertionBox.Visibility = Visibility.Collapsed;
     inserter.insertStrokes(this.inkAnalyzer, MainInkCanvas, insertionBox.InkCanvas);
 }