Is there any way to add images as byte[] to the FREngine.IEngine for OCR processing rather than giving the path of image file to the "AddImageFile" method of FREngine.FRDocument object?.

this is for Windows web service, .NET

asked 27 Jan, 18:23

SGumaste's gravatar image

SGumaste
111


Please consider using the IFRDocument::AddImageFileFromStream method. This method opens an image file from the input stream implemented by the user, and adds the pages corresponding to the opened file to the document. For more information about this method please refer to the Help file: API Reference→Document-Related Objects→Document Organization Objects→FRDocument Object, section "Methods" and API Reference→Supplementary Objects→IReadStream.

link

answered 30 Jan, 09:54

Oksana%20Serdyuk's gravatar image

Oksana Serdyuk ♦♦
1.5k16

Hi Oksnana, I did try using IReadStream but no luck, program goes into infinite loop. Definitely I am doing something wrong, I am pasting my code here can you please help me : am breaking into two comments because of chars restrictions public void foo() {FREngine.IEngine engine = _enginesPool.GetEngine(); FREngine.FRDocument frDocument = engine.CreateFRDocument(); byte[] myBytes = File.ReadAllBytes(argImagesPath); CustomReadStream crs = new CustomReadStream(myBytes); frDocument.AddImageFileFromStream(crs, null, null, null, "0");}

(30 Jan, 15:59) SGumaste

class CustomReadStream : IReadStream { public CustomReadStream(byte[] argImageBytes) {currentPos = 0; imageBytes = new byte[argImageBytes.Length]; argImageBytes.CopyTo(imageBytes, 0);} public int Read(out Array data, int count) { data = imageBytes; buf = new byte[imageBytes.Length]; imageBytes.CopyTo(buf, 0); return imageBytes.Length; }

(30 Jan, 16:00) SGumaste

public void Close() { imageBytes = null; buf = null; } uint currentPos = 0; byte[] imageBytes = null; byte[] buf = null; }

(30 Jan, 16:00) SGumaste

Hi,

Please sorry for the delay!

First of all, please check what FineReader Engine release you use. The case is that the implementation of the IReadStream interface was changed in our Help file to more optimal beginning from the 5th release of the program, the build number - 11.1.10.100. And now the current version of FineReader Engine 11 is the 8th release, the build number - 11.1.19.48. Please contact your Sales Manager to update your FineReader Engine package.

Below please find our sample C# code snippet illustrating how to implement the IReadStream interface and use the IFRDocument::AddImageFileFromStream() method:

// ...
using System.IO; 
// ...

class CustomReadStream : FREngine.IReadStream
{
    private MemoryStream fileBytes = null;

    public CustomReadStream(byte[] _fileBytes)
    {
        fileBytes = new MemoryStream(_fileBytes);
    }

    public void Close()
    {
        fileBytes.Close();
    }

    public int Read(out byte[] data, int count)
    {
        data = new byte[count];
        int readBytes = fileBytes.Read(data, 0, count);
        return readBytes;
    }
}

// ...

// Create document
FREngine.FRDocument document = engineLoader.Engine.CreateFRDocument();

// Add image file to document  
byte[] myBytes = File.ReadAllBytes(imagePath);
CustomReadStream readStream = new CustomReadStream(myBytes);
document.AddImageFileFromStream(readStream, null, null, null, "0");

Then you can continue processing using the FRDocument object in the way you prefer.

link

answered 02 Feb, 13:35

Oksana%20Serdyuk's gravatar image

Oksana Serdyuk ♦♦
1.5k16

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×42
×3

Asked: 27 Jan, 18:23

Seen: 94 times

Last updated: 02 Feb, 13:35

© 2016 ABBYY. All rights Reserved. www.ABBYY.com | Privacy Policy | Legal