Esempio n. 1
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);
             */
        }