I'm trying to build a sample application in java that will read an image file and just output the text extracted from the image. I found the Tesseract project which seems promising, however, its in c++. In order to use it, should I simply run it as a command line from my java app Runtime.exec(...)
? Or is there a better solution, maybe a JAR? Additionally, this is just a sample app, would running it as a command line app be a concern from scalability perspective?
Tess4J is a Java wrapper for the Tesseract APIs that provides OCR support for various image formats like JPEG, GIF, PNG, and BMP. Then, we can use the Tesseract class provided by tess4j to process the image: File image = new File("src/main/resources/images/multiLanguageText.
Tesseract OCR is an optical character reading engine developed by HP laboratories in 1985 and open sourced in 2005. Since 2006 it is developed by Google.
OCR for Java allows you to extract text from images, screenshots, specific areas of an image, and create searchable PDFs from scanned files on any platform that supports Java. With its powerful yet easy-to-use API, even the complex OCR tasks take less than 10 lines of code.
Tesseract is an open source text recognition (OCR) Engine, available under the Apache 2.0 license. It can be used directly, or (for programmers) using an API to extract printed text from images. It supports a wide variety of languages.
Now tesseract is provided by the javacv project, this is a far better option than using Tess4J since all that is required is adding a single dependency to your pom file, the native libs for your platform will then be downloaded and linked automatically for you by the javacv tesseract version.
I've created an example maven project here - https://github.com/piersy/BasicTesseractExample
and also an example gradle project here - https://github.com/piersy/BasicTesseractExampleGradle
For this to work on my ubuntu machine I needed to update my install of libstdc++6
I achieved this by running the following although just installing libstdc++6 may work for you.
sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt-get update sudo apt-get install libstdc++6
Note the gradle project does not perform the automatic install but is is still a hell of a lot simpler than using Tess4J
The javacv project is here - https://github.com/bytedeco/javacpp-presets/tree/master/tesseract
Big props to the javacv guys, only wish I'd found this earlier as it would have saved me a week of getting tess4j to work on multiple platforms!
I have used the tesseract project in my java code. All you need to do is
Please have a look into this http://tphangout.com/?p=18
It gives instructions on how to build a java project to read an image and convert it into text using the tesseract OCR API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With