Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
409 views
in Technique[技术] by (71.8m points)

ocr - Using Tesseract from java

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...