예제 #1
0
        /// <summary>
        /// Detect all the characters in the image.
        /// </summary>
        /// <returns>All the characters in the image</returns>
        public Character[] GetCharacters()
        {
            using (VectorOfByte textSeq = new VectorOfByte())
                using (VectorOfTesseractResult results = new VectorOfTesseractResult())
                {
                    OcrInvoke.TessBaseAPIExtractResult(_ptr, textSeq, results);

                    byte[]            bytes = textSeq.ToArray();
                    TesseractResult[] trs   = results.ToArray();

                    Character[] res = new Character[trs.Length];
                    int         idx = 0;
                    for (int i = 0; i < trs.Length; i++)
                    {
                        TesseractResult tr = trs[i];
                        res[i].Text = _utf8.GetString(bytes, idx, tr.Length).Replace("\n", Environment.NewLine);

                        idx        += tr.Length;
                        res[i].Cost = tr.Cost;
                        if (tr.Cost == 0)
                        {
                            res[i].Region = Rectangle.Empty;
                        }
                        else
                        {
                            res[i].Region = tr.Region;
                        }
                    }
                    return(res);
                }
        }
예제 #2
0
        /// <summary>
        /// Detect all the charactors in the image.
        /// </summary>
        /// <returns>All the charactors in the image</returns>
        public Charactor[] GetCharactors()
        {
            using (MemStorage stor = new MemStorage())
            {
                Seq <byte>            textSeq = new Seq <byte>(stor);
                Seq <TesseractResult> results = new Seq <TesseractResult>(stor);
                TessBaseAPIExtractResult(_ptr, textSeq, results);

                byte[]            bytes = textSeq.ToArray();
                TesseractResult[] trs   = results.ToArray();

                Charactor[] res = new Charactor[trs.Length];
                int         idx = 0;
                for (int i = 0; i < trs.Length; i++)
                {
                    TesseractResult tr = trs[i];
                    res[i].Text = _utf8.GetString(bytes, idx, tr.Length).Replace("\n", Environment.NewLine);

                    idx        += tr.Length;
                    res[i].Cost = tr.Cost;
                    if (tr.Cost == 0)
                    {
                        res[i].Region = Rectangle.Empty;
                    }
                    else
                    {
                        res[i].Region = tr.Region;
                    }
                }
                return(res);
            }
        }
 /// <summary>
 /// Get the item in the specific index
 /// </summary>
 /// <param name="index">The index</param>
 /// <returns>The item in the specific index</returns>
 public TesseractResult this[int index]
 {
     get
     {
         TesseractResult result = new TesseractResult();
         VectorOfTesseractResultGetItem(_ptr, index, ref result);
         return(result);
     }
 }
 /// <summary>
 /// Convert the standard vector to an array of TesseractResult
 /// </summary>
 /// <returns>An array of TesseractResult</returns>
 public TesseractResult[] ToArray()
 {
     TesseractResult[] res = new TesseractResult[Size];
     if (res.Length > 0)
     {
         GCHandle handle = GCHandle.Alloc(res, GCHandleType.Pinned);
         VectorOfTesseractResultCopyData(_ptr, handle.AddrOfPinnedObject());
         handle.Free();
     }
     return(res);
 }
 internal static extern void VectorOfTesseractResultGetItem(IntPtr vec, int index, ref TesseractResult element);