Tesseract uses an image from a byte array

I have an image file that has been read into a byte array and I am trying to process it through Tesseract:

using (TesseractEngine engine = new TesseractEngine(@"tessdata", "eng", EngineMode.Default))
  using (MemoryStream ms = new MemoryStream(imgByteArray))
  {
    Bitmap bmp = new Bitmap(ms)
    using (Pix img = PixConverter.ToPix(bmp))
      using (Page page = engine.Process(img, PageSegMode.Auto))
  }

      

Is there a better way to do this?

Then I try to do it with the same image via the file path:

using (TesseractEngine engine = new TesseractEngine(@"tessdata", "eng", EngineMode.Default))
  using (Pix img = Pix.LoadFromFile(@"C:\img1.png"))
    using (Page page = engine.Process(img, PageSegMode.Auto))

      

The second gives much better results. How can I use a byte array and get the same results? In my application, I cannot work with file paths.

+3


source to share





All Articles