Example #1
0
        private string[] Regconize()         // REM 识别 ptinfos 中的点
        {
            List <System.Drawing.Point> listpts = new List <System.Drawing.Point>();

            foreach (var i in ptinfos)
            {
                listpts.Add(i.ToDrawingPoint());
            }
            // REM 每一笔转换成stroke
            Stroke stroke = ink.CreateStroke(listpts.ToArray());

            // REM 添加到识别器的上下文
            recognizectx.Strokes.Add(stroke);
            RecognitionStatus recognizestatus = new RecognitionStatus();
            RecognitionResult recognizeresult = recognizectx.Recognize(out recognizestatus);
            // REM 识别器的所有选择
            RecognitionAlternates recognizealternates = recognizeresult.GetAlternatesFromSelection();
            // REM 列出识别器所识别出的内容
            List <string> result = new List <string>();

            for (var i = 0; i <= recognizealternates.Count - 1; i++)
            {
                string text = recognizealternates[i].ToString();
                // Console.WriteLine(text)
                result.Add(text);
            }
            return(result.ToArray());
        }
Example #2
0
        /// <summary>
        /// Converts a Sketch substroke into a Microsoft.Ink stroke.
        /// </summary>
        /// <param name="substroke">The Sketch substroke to convert</param>
        /// <param name="ink">A Microsoft.Ink Ink object</param>
        /// <returns>The desired ink stroke</returns>
        private Microsoft.Ink.Stroke convertToInk(
            Sketch.Substroke substroke,
            Microsoft.Ink.Ink ink)
        {
            int pointsCount = substroke.Points.Length;

            System.Drawing.Point[] inkPoints = new System.Drawing.Point[pointsCount];

            // Convert the Sketch point format to Microsoft point format
            for (int i = 0; i < pointsCount; i++)
            {
                inkPoints[i] = new System.Drawing.Point(
                    (int)(substroke.Points[i].X),
                    (int)(substroke.Points[i].Y));
            }

            return(ink.CreateStroke(inkPoints));
        }
Example #3
0
        /// <summary>
        /// Creates the strokes in this xml document as C# strokes and adds them to the corresponding Ink object.
        /// We cannot create new strokes with the same Id's that we have in the MIT XML format, so instead we
        /// return a hash table mapping the created strokes' Ids (1, 2, ... , n) with the strokes.
        /// </summary>
        ///
        /// <returns>A Hashtable that holds links back to the Converter strokes</returns>
        public Hashtable getIdToCStroke(Sketch sketch, Microsoft.Ink.Ink inkObject)
        {
            ArrayList strokes = sketch.Shapes;
            ArrayList points  = sketch.Points;

            Hashtable retTable = new Hashtable();

            // Create a hashtable between points and IDs for easy access
            Hashtable pointTable = sketch.IdToPoint;

            // Now create the C# strokes
            foreach (Shape s in strokes)
            {
                Stroke st = new Stroke(s);

                // first check to be sure it's a matching shape
                if (st.matches(Stroke.ShapeType.STROKE))
                {
                    // Get all of the stroke's points
                    ArrayList pts = s.getArgIds();

                    System.Drawing.Point[] xypts = new System.Drawing.Point[pts.Count];
                    //int[] pressureData = new int[pts.Count];
                    //int[] timerData    = new int[pts.Count];

                    int index = 0;
                    //Console.WriteLine( "loading stroke...");
                    foreach (string id in pts)
                    {
                        Point p = (Point)pointTable[id];
                        st.Points.Add(p);
                        st.Args.Add(new Stroke.Arg("Point", p.Id));

                        // Just get the x and the y, ignore the rest
                        int x = Convert.ToInt32(p.X);
                        int y = Convert.ToInt32(p.Y);

                        //Console.WriteLine( "[x: {0}, y: {1}]", x, y );
                        xypts[index] = new System.Drawing.Point(x, y);

                        //pressureData[index] = (int)p.Pressure;
                        //timerData[index]    = (int)p.Time;

                        ++index;
                    }

                    Microsoft.Ink.Stroke newStroke = inkObject.CreateStroke(xypts);

                    /*
                     * // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dntablet/html/TimeStampsBestPractices.asp
                     * // mike used: 8fe68ce5-c39c-4f52-afbb-65344e8e49ff
                     * newstroke.ExtendedProperties.Add(new Guid("8A54CF58-97E6-4fc5-8F06-F8BAD2E19B22"), (long)s.Time);
                     *
                     * // newstroke.SetPacketValuesByProperty(Microsoft.Ink.PacketProperty.NormalPressure, pressureData);
                     * newstroke.SetPacketValuesByProperty(Microsoft.Ink.PacketProperty.TimerTick, timerData);
                     */

                    retTable.Add(newStroke.Id, st);
                }
            }

            return(retTable);
        }