Morkus
Morkus

Reputation: 597

How do I pass File Stream to Tesseract

In all the examples I've seen, including the one I have working, you interact with Tesseract using a file path.

However, since I need to use Tesseract in a web service, the user will pass a Base64Encoded stream to the web service method, not a file path string.

Thus far, I have not been able to find the right method to let me use a ByteArrayOutputStream or a File object.

The file path (string) is read using: pixRead(), but this method doesn't work with a File object or ByteArrayOutputStream.

--

I also tried the tess4j library as an alternative since it uses a File object (I tried every released version in testing) but only got a crashed JVM. Others got that message also (but no resolution) so now I'm back at just regular Tesseract.

--

Would anyone please give me a code example of how to pass a File Object or a ByteArrayOutputStream to Tesseract so I can read the image?

Thanks.

Upvotes: 0

Views: 997

Answers (1)

user898678
user898678

Reputation: 3328

There are at least 2 options to avoid using file path:

  • command line: tesseract executable accept image from sdtin. You can try something like this: curl "http://d2jaiao3zdxbzm.cloudfront.net/wp-content/uploads/figure-65.png" | tesseract - -.

  • tesseract API: you can set image data to tesseract engine with SetImage directly. I am not familiar with java but looks like it is also available in tess4j as TessBaseAPISetImage.

Upvotes: 0

Related Questions