本文整理汇总了Java中com.googlecode.tesseract.android.TessBaseAPI.setDebug方法的典型用法代码示例。如果您正苦于以下问题:Java TessBaseAPI.setDebug方法的具体用法?Java TessBaseAPI.setDebug怎么用?Java TessBaseAPI.setDebug使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.googlecode.tesseract.android.TessBaseAPI
的用法示例。
在下文中一共展示了TessBaseAPI.setDebug方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: initOcrEngine
import com.googlecode.tesseract.android.TessBaseAPI; //导入方法依赖的package包/类
private void initOcrEngine() {
tessOCRApi = new TessBaseAPI();
tessOCRApi.setDebug(true);
try {
tessOCRApi.init(DATA_PATH, lang);
} catch (IllegalArgumentException e) {
tessOCRApi = null;
}
}
示例4: recognizeImage
import com.googlecode.tesseract.android.TessBaseAPI; //导入方法依赖的package包/类
public void recognizeImage(String imageURL, final CallbackContext callbackContext) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
imageURL = imageURL.substring(7);
Log.v(TAG, imageURL);
Log.v(TAG, "Starting image decoding...");
Bitmap bitmap = BitmapFactory.decodeFile(imageURL, options);
try {
// convert captured image to bitmap format
ExifInterface exif = new ExifInterface(imageURL);
int exifOrientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL
);
Log.v(TAG, "Orient: "+ exifOrientation);
int rotate = 0;
switch (exifOrientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
}
Log.v(TAG, "Rotation: " + rotate);
if (rotate != 0) {
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Matrix mtx = new Matrix();
mtx.preRotate(rotate);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, false);
}
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
// scan and recognize the bitmap image
String recognizedText = "";
Log.v(TAG, "Before baseApi");
TessBaseAPI baseApi = new TessBaseAPI();
baseApi.setDebug(true);
baseApi.init(DATA_PATH, lang);
baseApi.setImage(bitmap);
recognizedText = baseApi.getUTF8Text();
baseApi.end();
Log.v(TAG, "OCRED Text: " + recognizedText);
if (lang.equalsIgnoreCase("eng")) {
recognizedText = recognizedText.replaceAll("[^a-zA-Z0-9]+", " ");
}
recognizedText = recognizedText.trim();
Log.v(TAG, "Recognized Text: " + recognizedText);
callbackContext.success(recognizedText);
Log.v(TAG, "Scanning completed");
return;
}
catch (Exception ex) {
Log.e(TAG,ex.getMessage());
callbackContext.error(ex.getMessage());
return;
}
}
示例5: startOCR
import com.googlecode.tesseract.android.TessBaseAPI; //导入方法依赖的package包/类
public boolean startOCR() {
if(mOCRShouldWork) return false;
nullCheck();
mOCRShouldWork = true;
mPicker = new RectanglePicker(mActivity);
mParent.addView(mPicker);
mOCRQueue = new LinkedBlockingQueue<byte[]>();
mTesseract = new TessBaseAPI();
mTesseract.setDebug(true);
mTesseract.init(CameraInterface.DATA_PATH, CameraInterface.LANG);
mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
String text = msg.getData().getString(CameraInterface.OCR_TEXT);
float accuracy = msg.getData().getFloat(
CameraInterface.OCR_ACCURACY);
if (mOCRListener != null) {
mOCRListener.onTextRecognized(text, accuracy);
}
}
};
mOCRWorker = new Thread(new Runnable() {
@Override
public void run() {
while (mOCRShouldWork) {
try {
byte[] imageData = mOCRQueue.take();
mPreviewBitmap = getBitmapImageFromYUV(imageData, mSize.width,
mSize.height, mDegrees, mPicker.rect(mSize, mDegrees));
if(mOCRQueue.size()>CameraInterface.OCR_QUEUE_SIZE)
mOCRQueue.clear();
forwardPreviewBitmap(mPreviewBitmap);
mTesseract.clear();
mTesseract.setImage(mPreviewBitmap);
String recognizedText = mTesseract.getUTF8Text();
float accuracy = mTesseract.meanConfidence();
recognizedText = recognizedText.replaceAll("[^a-zA-Z0-9]+", " ");
updateOCR(recognizedText,accuracy);
} catch (InterruptedException e) {
Log.d(TAG, "mOCRThread InterruptedException "+e);
}
}
mTesseract.end();
}
});
mOCRWorker.start();
return true;
}