コード例 #1
0
        private static void Main(string[] args)
        {
            Console.Write("Input image path:");

            string input = Console.ReadLine();

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            T.TesseractEngine engine = new T.TesseractEngine("tessdata", "tur", T.EngineMode.TesseractAndLstm);

            stopwatch.Stop();

            Console.WriteLine("Engine creation :" + stopwatch.ElapsedMilliseconds.ToString() + " ms");

            stopwatch.Restart();

            T.Pix image = T.Pix.LoadFromFile(input);

            T.Page page = engine.Process(image);

            string text = page.GetText();

            stopwatch.Stop();

            Console.WriteLine("Process time :" + stopwatch.ElapsedMilliseconds.ToString() + " ms");

            Console.Write("Result: " + text);

            Console.Read();
        }
コード例 #2
0
ファイル: Page.cs プロジェクト: Picazsoo/tesseract
 internal Page(TesseractEngine engine, Pix image, string imageName, Rect regionOfInterest, PageSegMode pageSegmentMode)
 {
     Engine = engine;
     Image = image;
     ImageName = imageName;
     RegionOfInterest = regionOfInterest;
     PageSegmentMode = pageSegmentMode;
 }
コード例 #3
0
 private PixelFormat GetPixelFormat(Pix pix)
 {
     switch (pix.Depth) {
         //case 1: return PixelFormat.Format1bppIndexed;
         //case 2: return PixelFormat.Format4bppIndexed;
        // case 4: return PixelFormat.Format4bppIndexed;
         case 8: return PixelFormat.Format8bppIndexed;
         case 16: return PixelFormat.Format16bppGrayScale;
         case 32: return PixelFormat.Format32bppArgb;
         default: throw new InvalidOperationException(String.Format("Pix depth {0} is not supported.", pix.Depth));
     }
 }
コード例 #4
0
        /// <summary>
        /// Processes the specific image.
        /// </summary>
        /// <remarks>
        /// You can only have one result iterator open at any one time.
        /// </remarks>
        /// <param name="image">The image to process.</param>
        /// <param name="region">The image region to process.</param>
        /// <returns>A result iterator</returns>
        public Page Process(Pix image, Rect region, PageSegMode? pageSegMode = null)
        {
            if (image == null) throw new ArgumentNullException("image");
            if (region.X1 < 0 || region.Y1 < 0 || region.X2 > image.Width || region.Y2 > image.Height)
                throw new ArgumentException("The image region to be processed must be within the image bounds.", "region");
            if (processCount > 0) throw new InvalidOperationException("Only one image can be processed at once. Please make sure you dispose of the page once your finished with it.");

            processCount++;

            Interop.TessApi.BaseAPISetPageSegMode(handle, pageSegMode.HasValue ? pageSegMode.Value : DefaultPageSegMode);
            Interop.TessApi.BaseApiSetImage(handle, image.Handle);
            Interop.TessApi.BaseApiSetRectangle(handle, region.X1, region.Y1, region.Width, region.Height);

            var page = new Page(this);
            page.Disposed += OnIteratorDisposed;
            return page;
        }
コード例 #5
0
 private void CopyColormap(Bitmap img, Pix pix)
 {
     var imgPalette = img.Palette;
     var imgPaletteEntries = imgPalette.Entries;
     var pixColormap = PixColormap.Create(pix.Depth);
     try {
         for (int i = 0; i < imgPaletteEntries.Length; i++) {
             if (!pixColormap.AddColor((PixColor)imgPaletteEntries[i])) {
                 throw new InvalidOperationException(String.Format("Failed to add colormap entry {0}.", i));
             }
         }
         pix.Colormap = pixColormap;
     } catch (Exception) {
         pixColormap.Dispose();
         throw;
     }
 }
コード例 #6
0
        public Bitmap Convert(Pix pix, bool includeAlpha = false)
        {
            var pixelFormat = GetPixelFormat(pix);
            var depth = pix.Depth;
            var img = new Bitmap(pix.Width, pix.Height, pixelFormat);

            BitmapData imgData = null;
            PixData pixData = null;
            try {
                // TODO: Set X and Y resolution

                // transfer pixel data
                if ((pixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed) {
                    TransferPalette(pix, img);
                }

                // transfer data
                pixData = pix.GetData();
                imgData = img.LockBits(new Rectangle(0, 0, img.Width, img.Height), ImageLockMode.WriteOnly, pixelFormat);
                
                if (depth == 32) {
                    TransferData32(pixData, imgData, includeAlpha ? 0 : 255);
                } else if (depth == 16) {
                    TransferData16(pixData, imgData);
                } else if (depth == 8) {
                    TransferData8(pixData, imgData);
                } else if (depth == 1) {
                    TransferData1(pixData, imgData);
                }
                return img;
            } catch (Exception) {
                img.Dispose();
                throw;
            } finally {
                if (imgData != null) {
                    img.UnlockBits(imgData);
                }
            }
        }
コード例 #7
0
ファイル: PixConverter.cs プロジェクト: Picazsoo/tesseract
 /// <summary>
 /// Converts the specified <paramref name="pix"/> to a Bitmap.
 /// </summary>
 /// <param name="pix">The source image to be converted.</param>
 /// <returns>The converted pix as a <see cref="Bitmap"/>.</returns>
 public static Bitmap ToBitmap(Pix pix)
 {
     return pixConverter.Convert(pix);
 }
コード例 #8
0
        /// <summary>
        /// Processes a specified region in the image using the specified page layout analysis mode.
        /// </summary>
        /// <remarks>
        /// You can only have one result iterator open at any one time.
        /// </remarks>
        /// <param name="image">The image to process.</param>
        /// <param name="inputName">Sets the input file's name, only needed for training or loading a uzn file.</param>
        /// <param name="region">The image region to process.</param>
        /// <param name="pageSegMode">The page layout analyasis method to use.</param>
        /// <returns>A result iterator</returns>
        public Page Process(Pix image, string inputName, Rect region, PageSegMode? pageSegMode = null)
        {
            if (image == null) throw new ArgumentNullException("image");
            if (region.X1 < 0 || region.Y1 < 0 || region.X2 > image.Width || region.Y2 > image.Height)
                throw new ArgumentException("The image region to be processed must be within the image bounds.", "region");
            if (processCount > 0) throw new InvalidOperationException("Only one image can be processed at once. Please make sure you dispose of the page once your finished with it.");

            processCount++;

            var actualPageSegmentMode = pageSegMode.HasValue ? pageSegMode.Value : DefaultPageSegMode;
            Interop.TessApi.Native.BaseAPISetPageSegMode(handle, actualPageSegmentMode);
            Interop.TessApi.Native.BaseApiSetImage(handle, image.Handle);
            if(!String.IsNullOrEmpty(inputName)) {
                Interop.TessApi.Native.BaseApiSetInputName(handle, inputName);
            }
            var page = new Page(this, image, inputName, region, actualPageSegmentMode);
            page.Disposed += OnIteratorDisposed;
            return page;
        }
コード例 #9
0
 public PageDisposalHandle(Page page, Pix pix)
 {
     this.page      = page;
     this.pix       = pix;
     page.Disposed += OnPageDisposed;
 }
コード例 #10
0
 /// <summary>
 /// Processes a specified region in the image using the specified page layout analysis mode.
 /// </summary>
 /// <remarks>
 /// You can only have one result iterator open at any one time.
 /// </remarks>
 /// <param name="image">The image to process.</param>
 /// <param name="region">The image region to process.</param>
 /// <param name="pageSegMode">The page layout analyasis method to use.</param>
 /// <returns>A result iterator</returns>
 public Page Process(Pix image, Rect region, PageSegMode?pageSegMode = null) => Process(image, null, region, pageSegMode);
コード例 #11
0
 /// <summary>
 /// Processes a specified region in the image using the specified page layout analysis mode.
 /// </summary>
 /// <remarks>
 /// You can only have one result iterator open at any one time.
 /// </remarks>
 /// <param name="image">The image to process.</param>
 /// <param name="region">The image region to process.</param>
 /// <param name="pageSegMode">The page layout analyasis method to use.</param>
 /// <returns>A result iterator</returns>
 public Page Process(Pix image, Rect region, PageSegMode? pageSegMode = null)
 {
     return Process(image, null, region, pageSegMode);
 }
コード例 #12
0
ファイル: PageIterator.cs プロジェクト: skyaxl/tesseract
 public Pix GetBinaryImage(PageIteratorLevel level)
 {
     return(Pix.Create(Interop.TessApi.PageIteratorGetBinaryImage(handle, level)));
 }
コード例 #13
0
ファイル: PageIterator.cs プロジェクト: skyaxl/tesseract
 public Pix GetImage(PageIteratorLevel level, int padding, out int x, out int y)
 {
     return(Pix.Create(Interop.TessApi.PageIteratorGetImage(handle, level, padding, out x, out y)));
 }
コード例 #14
0
			public PageDisposalHandle(Page page, Pix pix)
			{
				this.page = page;
				this.pix = pix;
				page.Disposed += OnPageDisposed;
			}
コード例 #15
0
ファイル: PixData.cs プロジェクト: ehsan2022002/VirastarE
 internal PixData(Pix pix)
 {
     Pix          = pix;
     Data         = LeptonicaApi.Native.pixGetData(Pix.Handle);
     WordsPerLine = LeptonicaApi.Native.pixGetWpl(Pix.Handle);
 }
コード例 #16
0
 internal PixData(Pix pix)
 {
     Pix          = pix;
     Data         = LeptonicaPrimitives.Api.pixGetData(pix.Handle);
     WordsPerLine = LeptonicaPrimitives.Api.pixGetWpl(pix.Handle);
 }
コード例 #17
0
 /// <summary>
 /// Processes a specified region in the image using the specified page layout analysis mode.
 /// </summary>
 /// <remarks>
 /// You can only have one result iterator open at any one time.
 /// </remarks>
 /// <param name="image">The image to process.</param>
 /// <param name="region">The image region to process.</param>
 /// <param name="pageSegMode">The page layout analyasis method to use.</param>
 /// <returns>A result iterator</returns>
 public Page Process(Pix image, Rect region, PageSegMode? pageSegMode = null)
 {
     return Process(image, null, new Rect(0, 0, image.Width, image.Height), pageSegMode);
 }
コード例 #18
0
ファイル: PixData.cs プロジェクト: Picazsoo/tesseract
		internal PixData(Pix pix)
		{		
            Pix = pix;
            Data = Interop.LeptonicaApi.Native.pixGetData(Pix.Handle);
            WordsPerLine = Interop.LeptonicaApi.Native.pixGetWpl(Pix.Handle);
		}
コード例 #19
0
 public static Bitmap ToBitmap(Pix pix) => pixConverter.Convert(pix);
コード例 #20
0
 private void TransferPalette(Pix pix, Bitmap img)
 {
     var pallete = img.Palette;
     var maxColors = pallete.Entries.Length;
     var colormap = pix.Colormap;
     if (colormap != null && colormap.Count <= maxColors) {
         var colormapCount = colormap.Count;
         for (int i = 0; i < colormapCount; i++) {
             pallete.Entries[i] = (SD.Color)colormap[i];
         }
     } else {
         for (int i = 0; i < maxColors; i++) {
             var value = (byte)(i % maxColors);
             pallete.Entries[i] = SD.Color.FromArgb(value, value, value);
         }
     }
     // This is required to force the palette to update!
     img.Palette = pallete;
 }
コード例 #21
0
ファイル: Page.cs プロジェクト: bolte-17/tesseract-csharp
 internal Page(TesseractEngine engine, Pix image, Rect regionOfInterest)
 {
     Engine           = engine;
     Image            = image;
     RegionOfInterest = regionOfInterest;
 }
コード例 #22
0
ファイル: PixConverter.cs プロジェクト: MRmlik12/tesseract-1
 /// <summary>
 /// Converts the specified <paramref name="pix"/> to a Bitmap.
 /// </summary>
 /// <param name="pix">The source image to be converted.</param>
 /// <returns>The converted pix as a <see cref="Bitmap"/>.</returns>
 public static Bitmap ToBitmap(Pix pix)
 {
     return(pixConverter.Convert(pix));
 }
コード例 #23
0
 /// <summary>
 /// Processes a specified region in the image using the specified page layout analysis mode.
 /// </summary>
 /// <remarks>
 /// You can only have one result iterator open at any one time.
 /// </remarks>
 /// <param name="image">The image to process.</param>
 /// <param name="region">The image region to process.</param>
 /// <param name="pageSegMode">The page layout analyasis method to use.</param>
 /// <returns>A result iterator</returns>
 public Page Process(Pix image, Rect region, PageSegMode?pageSegMode = null)
 {
     return(Process(image, null, region, pageSegMode));
 }
コード例 #24
0
ファイル: Page.cs プロジェクト: RokGrdina/tesseract
        internal Page(TesseractEngine engine, Pix image, Rect regionOfInterest)
        {
            Engine = engine;
			Image = image;
			RegionOfInterest = regionOfInterest;
        }
コード例 #25
0
 /// <summary>
 /// Processes the specific image.
 /// </summary>
 /// <remarks>
 /// You can only have one result iterator open at any one time.
 /// </remarks>
 /// <param name="image">The image to process.</param>
 /// <param name="inputName">Sets the input file's name, only needed for training or loading a uzn file.</param>
 /// <param name="pageSegMode">The page layout analyasis method to use.</param>
 public Page Process(Pix image, string inputName, PageSegMode?pageSegMode = null)
 {
     return(Process(image, inputName, new Rect(0, 0, image.Width, image.Height), pageSegMode));
 }
コード例 #26
0
 /// <summary>
 /// Processes the specific image.
 /// </summary>
 /// <remarks>
 /// You can only have one result iterator open at any one time.
 /// </remarks>
 /// <param name="image">The image to process.</param>
 /// <param name="inputName">Sets the input file's name, only needed for training or loading a uzn file.</param>
 /// <param name="pageSegMode">The page layout analyasis method to use.</param>
 public Page Process(Pix image, string inputName, PageSegMode? pageSegMode = null)
 {
     return Process(image, inputName, new Rect(0, 0, image.Width, image.Height), pageSegMode);
 }
コード例 #27
0
 /// <summary>
 /// Processes the specific image.
 /// </summary>
 /// <remarks>
 /// You can only have one result iterator open at any one time.
 /// </remarks>
 /// <param name="image">The image to process.</param>
 /// <param name="pageSegMode">The page layout analyasis method to use.</param>
 public Page Process(Pix image, PageSegMode?pageSegMode = null) => Process(image, null, new Rect(0, 0, image.Width, image.Height), pageSegMode);