Skip to content

Instantly share code, notes, and snippets.

@Sren-Hmkn
Created August 6, 2018 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sren-Hmkn/f7929efe7919eff63f259fe1e09654df to your computer and use it in GitHub Desktop.
Save Sren-Hmkn/f7929efe7919eff63f259fe1e09654df to your computer and use it in GitHub Desktop.
Implementing the tess-two class
package com.example.android.myapplication;
import android.content.Context;
import android.graphics.Bitmap;
import com.googlecode.tesseract.android.TessBaseAPI;
import static com.googlecode.tesseract.android.TessBaseAPI.PageSegMode.PSM_AUTO;
public final class MyTessOCR {
private String datapath;
private static TessBaseAPI mTess = new TessBaseAPI();
Context context;
public MyTessOCR(Context context) {
this.context = context;
datapath = context.getExternalFilesDir("/").getPath() + "/";
mTess.setDebug(true);
mTess.init(datapath, "eng");
mTess.setPageSegMode(PSM_AUTO);
}
public void stopRecognition() {
mTess.stop();
}
public String getOCRResult(Bitmap bitmap) {
String whitelist = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.-!?";
mTess.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, whitelist);
mTess.setImage(bitmap);
String result = mTess.getUTF8Text();
return result;
}
public void onDestroy() {
if (mTess != null)
mTess.end();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment