本文整理汇总了Java中com.googlecode.tesseract.android.TessBaseAPI类的典型用法代码示例。如果您正苦于以下问题:Java TessBaseAPI类的具体用法?Java TessBaseAPI怎么用?Java TessBaseAPI使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TessBaseAPI类属于com.googlecode.tesseract.android包,在下文中一共展示了TessBaseAPI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: detectText
import com.googlecode.tesseract.android.TessBaseAPI; //导入依赖的package包/类
public String detectText(Bitmap bitmap) {
Log.d(TAG, "Initialization of TessBaseApi");
TessDataManager.initTessTrainedData(context);
TessBaseAPI tessBaseAPI = new TessBaseAPI();
String path = TessDataManager.getTesseractFolder();
Log.d(TAG, "Tess folder: " + path);
tessBaseAPI.setDebug(true);
tessBaseAPI.init(path, "eng");
// 白名单
tessBaseAPI.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
// 黑名单
tessBaseAPI.setVariable(TessBaseAPI.VAR_CHAR_BLACKLIST, "[email protected]#$%^&*()_+=-[]}{;:'\"\\|~`,./<>?");
tessBaseAPI.setPageSegMode(TessBaseAPI.PageSegMode.PSM_AUTO_OSD);
Log.d(TAG, "Ended initialization of TessEngine");
Log.d(TAG, "Running inspection on bitmap");
tessBaseAPI.setImage(bitmap);
String inspection = tessBaseAPI.getHOCRText(0);
Log.d(TAG, "Confidence values: " + tessBaseAPI.meanConfidence());
tessBaseAPI.end();
System.gc();
return Tools.getTelNum(inspection);
}
示例2: init
import com.googlecode.tesseract.android.TessBaseAPI; //导入依赖的package包/类
/**
* Initializes Tesseract library using traineddata file.
* Should not be called directly, is public for testing.
*/
public void init() {
baseApi = new TessBaseAPI();
baseApi.setDebug(true);
String path = Environment.getExternalStorageDirectory() + "/" + Util.FOLDER_DIGITAL_VOTING_PASS + "/";
File trainedDataFile = new File(path, TesseractOCR.FOLDER_TESSERACT_DATA + "/" + trainedData);
try {
mDeviceStorageAccessLock.acquire();
if (!trainedDataFile.exists()) {
Log.i(TAG, "No existing trained data found, copying from assets..");
Util.copyAssetsFile(assetManager.open(trainedData), trainedDataFile);
} else {
Log.i(TAG, "Existing trained data found");
}
mDeviceStorageAccessLock.release();
baseApi.init(path, trainedData.replace(TesseractOCR.TRAINED_DATA_EXTENSION, "")); //extract language code from trained data file
} catch (IOException | InterruptedException e) {
e.printStackTrace();
//TODO show error to user, coping failed
}
}
示例3: resumeOCR
import com.googlecode.tesseract.android.TessBaseAPI; //导入依赖的package包/类
/**
* Method to start or restart recognition after the OCR engine has been initialized,
* or after the app regains focus. Sets state related settings and OCR engine parameters,
* and requests camera initialization.
*/
void resumeOCR() {
Log.d(TAG, "resumeOCR()");
// This method is called when Tesseract has already been successfully initialized, so set
// isEngineReady = true here.
isEngineReady = true;
isPaused = false;
if (handler != null) {
handler.resetState();
}
if (baseApi != null) {
baseApi.setPageSegMode(pageSegmentationMode);
baseApi.setVariable(TessBaseAPI.VAR_CHAR_BLACKLIST, characterBlacklist);
baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, characterWhitelist);
}
if (hasSurface) {
// The activity was paused but not stopped, so the surface still exists. Therefore
// surfaceCreated() won't be called, so init the camera here.
initCamera(surfaceHolder);
}
}
示例4: processOcrIterator
import com.googlecode.tesseract.android.TessBaseAPI; //导入依赖的package包/类
private List<OcrChar> processOcrIterator(ResultIterator iterator){
List<OcrChar> ocrChars = new ArrayList<>();
if (iterator.next(TessBaseAPI.PageIteratorLevel.RIL_SYMBOL)){
iterator.begin();
}
else {
return ocrChars;
}
do {
List<Pair<String, Double>> choices = iterator.getChoicesAndConfidence(TessBaseAPI.PageIteratorLevel.RIL_SYMBOL);
int[] pos = iterator.getBoundingBox(TessBaseAPI.PageIteratorLevel.RIL_SYMBOL);
ocrChars.add(new OcrChar(choices, pos));
} while (iterator.next(TessBaseAPI.PageIteratorLevel.RIL_SYMBOL));
iterator.delete();
return ocrChars;
}
示例5: doInBackground
import com.googlecode.tesseract.android.TessBaseAPI; //导入依赖的package包/类
@Override
protected String doInBackground(String... params) {
runOnUiThread(new Runnable() {
@Override
public void run() {
ProgressWheel pBar = (ProgressWheel) findViewById(R.id.progressBar);
pBar.setVisibility(View.VISIBLE);
pBar.spin();
pBar.setText("Fetching...");
}
});
// Sets Up Tesseract for text recognition.
baseApi = new TessBaseAPI();
baseApi.init(Environment.getExternalStorageDirectory() + "/tesseract/", "eng");
//baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST,"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
baseApi.setVariable("load_system_dawg","F");
baseApi.setVariable("load_freq_dawg","F");
baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_AUTO_OSD);
for (String key : card.getPatternMap().keySet()) {
if(card.getPatternMap().get(key).getResource().matches("[t][e][x][t].*")) fetchTextNew(card.getPattern(key).getResource());
}
baseApi.end();
return "sucess";
}
示例6: OCRFrameWorker
import com.googlecode.tesseract.android.TessBaseAPI; //导入依赖的package包/类
public OCRFrameWorker(OnCameraPreviewListener.FrameDrawer drawer) {
super(drawer);
this.tessBaseAPI = new TessBaseAPI();
this.tessBaseAPI.setPageSegMode(PageSegMode.PSM_AUTO_OSD);
this.tessBaseAPI.setVariable(TessBaseAPI.VAR_ACCURACYVSPEED,
String.valueOf(50));
this.tessBaseAPI.init(Environment.getExternalStorageDirectory().getPath(), "eng");
paint = new Paint();
paint.setColor(Color.RED);
int size = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
(float) 11.0, drawer.getDisplayMetrics());
paint.setTextSize(size);
bounds = new Rect();
paint.getTextBounds("Q", 0, 1, bounds);
lines = drawer.getDisplayMetrics().heightPixels / bounds.height();
}
示例7: onActivityResult
import com.googlecode.tesseract.android.TessBaseAPI; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
return;
}
if (requestCode == cameraResultCode) {
Bundle extras = data.getExtras();
Bitmap bmp = (Bitmap) extras.get("data");
image.setImageBitmap(bmp);
TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init("/mnt/sdcard/tesseract/", "chi_tra");
baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_LINE);
baseApi.setImage(bmp);
String outputText = baseApi.getUTF8Text();
tessResults.setText(outputText);
}
super.onActivityResult(requestCode, resultCode, data);
}
示例8: onCreate
import com.googlecode.tesseract.android.TessBaseAPI; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_orc_bitmap);
findView();
mTextBitmap = getTextImage("你好", 300, 300);
image.setImageBitmap(mTextBitmap);
baseApi = new TessBaseAPI();
baseApi.init("/mnt/sdcard/tesseract/", "chi_tra");
baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_LINE);
baseApi.setImage(mTextBitmap);
String outputText = baseApi.getUTF8Text();
tessResults.setText(outputText);
}
示例9: resumeOCR
import com.googlecode.tesseract.android.TessBaseAPI; //导入依赖的package包/类
/**
* Method to start or restart recognition after the OCR engine has been initialized,
* or after the app regains focus. Sets state related settings and OCR engine parameters,
* and requests camera initialization.
*/
void resumeOCR() {
Log.d(TAG, "resumeOCR()");
// This method is called when Tesseract has already been successfully initialized, so set
// isEngineReady = true here.
isEngineReady = true;
isPaused = false;
if (handler != null) {
handler.resetState();
}
if (baseApi != null) {
baseApi.setPageSegMode(pageSegmentationMode);
//baseApi.setVariable(TessBaseAPI.VAR_CHAR_BLACKLIST, characterBlacklist);
baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, "ABCDEFabcdef0123456789");
}
if (hasSurface) {
// The activity was paused but not stopped, so the surface still exists. Therefore
// surfaceCreated() won't be called, so init the camera here.
initCamera(surfaceHolder);
}
}
示例10: testSetImage
import com.googlecode.tesseract.android.TessBaseAPI; //导入依赖的package包/类
@SmallTest
public void testSetImage() {
// First, make sure the eng.traineddata file exists.
assertTrue("Make sure that you've copied " + DEFAULT_LANGUAGE + ".traineddata to "
+ EXPECTED_FILE, new File(EXPECTED_FILE).exists());
// Attempt to initialize the API.
final TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);
// Set the image to a Bitmap.
final Bitmap bmp = Bitmap.createBitmap(640, 480, Bitmap.Config.ARGB_8888);
baseApi.setImage(bmp);
// Attempt to stesthut down the API.
baseApi.end();
}
示例11: resumeOcrEngine
import com.googlecode.tesseract.android.TessBaseAPI; //导入依赖的package包/类
/**
* Method to start or restart recognition after the OCR engine has been
* initialized, or after the app regains focus. Sets state related settings
* and OCR engine parameters, and requests camera initialization.
*/
public void resumeOcrEngine() {
Log.d(TAG, "resumeOcrEngine()");
// This method is called when Tesseract has already been successfully
// initialized, so set
// isEngineReady = true here.
if (mBaseApi != null) {
if (mCaptureActivityHandler != null) {
mCaptureActivityHandler.startDecode(mBaseApi);
}
mBaseApi.setPageSegMode(PAGE_SEGMENTATION_MODE);
mBaseApi.setVariable(TessBaseAPI.VAR_CHAR_BLACKLIST, "");
mBaseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, CHARACTER_WHITELIST);
}
}
示例12: initOcrEngine
import com.googlecode.tesseract.android.TessBaseAPI; //导入依赖的package包/类
/**
* Requests initialization of the OCR engine with the given parameters.
*
* @param storageRoot Path to location of the tessdata directory to use
* @param languageCode Three-letter ISO 639-3 language code for OCR
* @param languageName Name of the language for OCR, for example, "English"
*/
private void initOcrEngine(File storageRoot, String languageCode, String languageName) {
// Set up the dialog box for the thermometer-style download progress
// indicator
if (mInitOcrProgressDialog != null) {
mInitOcrProgressDialog.dismiss();
}
mInitOcrProgressDialog = new ProgressDialog(this);
// Start AsyncTask to install language data and init OCR
new OcrInitAsyncTask(this,
new TessBaseAPI(),
mInitOcrProgressDialog,
languageCode,
languageName,
OCR_ENGINE_MODE).execute(storageRoot.toString());
}
示例13: getOcrEngineModeName
import com.googlecode.tesseract.android.TessBaseAPI; //导入依赖的package包/类
/**
* Returns a string that represents which OCR engine(s) are currently set to be run.
*
* @return OCR engine mode
*/
String getOcrEngineModeName() {
String ocrEngineModeName = "";
String[] ocrEngineModes = getResources().getStringArray(R.array.ocrenginemodes);
if (ocrEngineMode == TessBaseAPI.OEM_TESSERACT_ONLY) {
ocrEngineModeName = ocrEngineModes[0];
} else if (ocrEngineMode == TessBaseAPI.OEM_CUBE_ONLY) {
ocrEngineModeName = ocrEngineModes[1];
} else if (ocrEngineMode == TessBaseAPI.OEM_TESSERACT_CUBE_COMBINED) {
ocrEngineModeName = ocrEngineModes[2];
}
return ocrEngineModeName;
}
示例14: OcrRecognizeAsyncTask
import com.googlecode.tesseract.android.TessBaseAPI; //导入依赖的package包/类
OcrRecognizeAsyncTask(CaptureActivity activity, TessBaseAPI baseApi, byte[] data, int width, int height) {
this.activity = activity;
this.baseApi = baseApi;
this.data = data;
this.width = width;
this.height = height;
}
示例15: run
import com.googlecode.tesseract.android.TessBaseAPI; //导入依赖的package包/类
@Override
public void run() {
if (originBitmap == null) {
scanFailed(getString(R.string.string_null_pic_single));
return;
}
if (originBitmap.getConfig() != Bitmap.Config.ARGB_8888) {
scanFailed(getString(R.string.string_pic_not_a888));
return;
}
try {
TessBaseAPI api = new TessBaseAPI();
api.init(Common.getTessDataDir(context), Common.getLanguage(context));
api.setImage(originBitmap.copy(Bitmap.Config.ARGB_8888, true));
final String result = api.getUTF8Text();
runOnUiThread(new Runnable() {
@Override
public void run() {
if (isStarting && !isFinishing()) {
scanSuccess(result);
}
}
});
originBitmap.recycle();
api.clear();
api.end();
} catch (final Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
if (getString(R.string.error_tessdata_folder).equals(e.getMessage())) {
scanFailed(getString(R.string.string_tess_not_ready));
} else {
scanFailed(e.getMessage());
}
}
});
}
}