本文整理汇总了Java中com.googlecode.tesseract.android.TessBaseAPI.init方法的典型用法代码示例。如果您正苦于以下问题:Java TessBaseAPI.init方法的具体用法?Java TessBaseAPI.init怎么用?Java TessBaseAPI.init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.googlecode.tesseract.android.TessBaseAPI
的用法示例。
在下文中一共展示了TessBaseAPI.init方法的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: 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";
}
示例4: 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);
}
示例5: 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);
}
示例6: 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();
}
示例7: 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());
}
}
});
}
}
示例8: init
import com.googlecode.tesseract.android.TessBaseAPI; //导入方法依赖的package包/类
/**
* Initializes the OCR helper and readies it for use.
*
* @param dataPath Path the OCR data files.
* @return Bitmap with replaced colors
*/
public static synchronized OcrHelper init(@NonNull String dataPath,
@NonNull PokeInfoCalculator pokeInfoCalculator,
@NonNull GoIVSettings settings) {
if (instance == null) {
tesseract = new TessBaseAPI();
tesseract.init(dataPath, "eng");
tesseract.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_LINE);
tesseract.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST,
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/♀♂");
nidoFemale = pokeInfoCalculator.get(28).name;
nidoMale = pokeInfoCalculator.get(31).name;
nidoUngendered = nidoFemale.replace("♀", "").toLowerCase();
ocrCache = new LruCache<>(200);
appraisalCache = new LruCache<>(200);
candyWordFirst = isCandyWordFirst();
instance = new OcrHelper();
}
isPokeSpamEnabled = settings.isPokeSpamEnabled();
Map<String, String> appraisalMap = settings.loadAppraisalCache();
for (Map.Entry<String, String> entry : appraisalMap.entrySet()) {
appraisalCache.put(entry.getKey(), entry.getValue());
}
return instance;
}
示例9: recognizeText
import com.googlecode.tesseract.android.TessBaseAPI; //导入方法依赖的package包/类
private void recognizeText(){
String language = "";
if (Binarization.language == 0)
language = "eng";
else
language= "spa";
baseApi = new TessBaseAPI();
baseApi.init(DATA_PATH, language,TessBaseAPI.OEM_TESSERACT_ONLY);
baseApi.setImage(Binarization.umbralization);
textScanned = baseApi.getUTF8Text();
}
示例10: OcrRunnable
import com.googlecode.tesseract.android.TessBaseAPI; //导入方法依赖的package包/类
public OcrRunnable(MainService context, CaptureWindow captureWindow){
mContext = context;
mCaptureWindow = captureWindow;
mBox = null;
mTessBaseAPI = new TessBaseAPI();
String storagePath = mContext.getExternalFilesDir(null).getAbsolutePath();
Log.e(TAG, storagePath);
mTessBaseAPI.init(storagePath, "jpn");
//mTessBaseAPI.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_BLOCK_VERT_TEXT);
}
示例11: digitRecognition
import com.googlecode.tesseract.android.TessBaseAPI; //导入方法依赖的package包/类
private String digitRecognition(Bitmap bitmap) {
TessBaseAPI tess = new TessBaseAPI();
tess.init(DATA_PATH, lang);
tess.setVariable("tessedit_char_whitelist", "0123456789");
tess.setImage(bitmap);
String stopNumber = tess.getUTF8Text();
tess.end();
return stopNumber;
}
示例12: TessOCR
import com.googlecode.tesseract.android.TessBaseAPI; //导入方法依赖的package包/类
public TessOCR() {
// TODO Auto-generated constructor stub
mTess = new TessBaseAPI();
String datapath = Environment.getExternalStorageDirectory() + "/tesseract/";
String language = "eng";
File dir = new File(datapath + "tessdata/");
if (!dir.exists())
dir.mkdirs();
mTess.init(datapath, language);
}
示例13: testInit
import com.googlecode.tesseract.android.TessBaseAPI; //导入方法依赖的package包/类
@SmallTest
public void testInit() {
// 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);
// Attempt to shut down the API.
baseApi.end();
}
示例14: go
import com.googlecode.tesseract.android.TessBaseAPI; //导入方法依赖的package包/类
public String go(String s)
{
String result=null;
TessBaseAPI tess = new TessBaseAPI();
String path = s;
tess.init(TESSBASE_PATH, DEFAULT_LANGUAGE);
File image=new File(path);
tess.setImage(image);
result = tess.getUTF8Text();
return result;
}
示例15: testGetUTF8Text
import com.googlecode.tesseract.android.TessBaseAPI; //导入方法依赖的package包/类
@SmallTest
public void testGetUTF8Text() {
// 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());
final String inputText = "hello baby";
// Attempt to initialize the API.
final TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);
baseApi.setPageSegMode(TessBaseAPI.PSM_SINGLE_LINE);
// Set the image to a Bitmap containing "hello".
final Bitmap bmp = Bitmap.createBitmap(640, 480, Bitmap.Config.ARGB_8888);
final Paint paint = new Paint();
final Canvas canvas = new Canvas(bmp);
paint.setColor(Color.WHITE);
paint.setStyle(Style.FILL);
canvas.drawRect(new Rect(0, 0, 640, 480), paint);
paint.setColor(Color.BLACK);
paint.setStyle(Style.FILL);
paint.setAntiAlias(true);
paint.setTextAlign(Align.CENTER);
paint.setTextSize(24.0f);
canvas.drawText(inputText, 320, 240, paint);
baseApi.setImage(bmp);
// Ensure that the result is correct.
final String outputText = baseApi.getUTF8Text();
assertTrue("\"" + outputText + "\" != \"" + inputText + "\"", inputText.equals(outputText));
// Attempt to shut down the API.
baseApi.end();
bmp.recycle();
}