Created
August 6, 2018 15:07
-
-
Save Sren-Hmkn/f7929efe7919eff63f259fe1e09654df to your computer and use it in GitHub Desktop.
Implementing the tess-two class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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