Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

ocr - How can I use Tesseract in Android?

I have searched on the net for a couple of hours. I got many answers saying we need to use NDK, etc. for "Tesseract" for WINDOWS.

But I didn't get any step-by-step/proper explanation of what should be done when NDK is installed. How to get the .so files? I have finished installing NDK and Cygwin. To check if it's done properly, I entered make -v and it gave the expected output.

Can anyone who has used "Tesseract" tell me how they have done it? (I have downloaded "Mezzofanti", but there I didn't find any of the "Tesseract" files.)

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

You need to use tess-two project for working with Tesseract on Android.
The tess-two contains tools for compiling the Tesseract and Leptonica libraries for use on the Android platform. It provides a Java API for accessing natively-compiled Tesseract and Leptonica APIs.

Adding tess-two to your project:

add to build.gradle:

dependencies {
    compile 'com.rmtheis:tess-two:5.4.1'
}

Using Tesseract:

import com.googlecode.tesseract.android.TessBaseAPI;

private String extractText(Bitmap bitmap) throws Exception{
    TessBaseAPI tessBaseApi = new TessBaseAPI();
    tessBaseApi.init(DATA_PATH, "eng");
    tessBaseApi.setImage(bitmap);
    String extractedText = tessBaseApi.getUTF8Text();
    tessBaseApi.end();
    return extractedText;
}

You can looking on my simple one-class example of using Tesseract for Android. It contains only 200 lines of Java code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...