本文整理汇总了Java中com.googlecode.tesseract.android.TessBaseAPI.setImage方法的典型用法代码示例。如果您正苦于以下问题:Java TessBaseAPI.setImage方法的具体用法?Java TessBaseAPI.setImage怎么用?Java TessBaseAPI.setImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.googlecode.tesseract.android.TessBaseAPI
的用法示例。
在下文中一共展示了TessBaseAPI.setImage方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例3: 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);
}
示例4: 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();
}
示例5: 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());
}
}
});
}
}
示例6: 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();
}
示例7: 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;
}
示例8: 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;
}
示例9: 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();
}
示例10: 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;
}
}
示例11: 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;
}
示例12: populateMap
import com.googlecode.tesseract.android.TessBaseAPI; //导入方法依赖的package包/类
protected void populateMap(Bitmap bmp) throws ExecutionException, InterruptedException
{
Log.i("info", String.format("Image size: %d x %d", bmp.getWidth(), bmp.getHeight()));
// Attempt to initialize the API.
final TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init(sTessBasePath.get(), DEFAULT_LANGUAGE);
baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_BLOCK);
baseApi.setImage(bmp);
Pixa allLinesPixa = baseApi.getTextlines();
Log.i("info", String.format("allLinesPixa.size() == %d", allLinesPixa.size()));
baseApi.setPageSegMode(PageSegMode.PSM_SINGLE_LINE);
Rect boxRect = allLinesPixa.getBoxRect(1);
baseApi.setRectangle(boxRect);
mStatsMap.put(mAgentStr, baseApi.getUTF8Text().replaceFirst(" .*$", ""));
Log.i("info", "Recognized Agent Name: " + mStatsMap.get(mAgentStr));
boolean varStatus = baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, "0123456789,");
baseApi.setRectangle(allLinesPixa.getBoxRect(3));
mStatsMap.put(mApStr, baseApi.getUTF8Text().split("\\s")[0]);
varStatus = baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, "");
Log.i("info", "AP: " + mStatsMap.get(mApStr));
for (Rect curRect : allLinesPixa.getBoxRects())
{
baseApi.setRectangle(curRect);
String text = baseApi.getUTF8Text();
for (Pair<String, Integer> statNamePair : mStatNames)
{
if (text.startsWith(statNamePair.first))
{
varStatus = baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, "0123456789,M");
baseApi.setRectangle(curRect);
String[] splitStatString = baseApi.getUTF8Text().split("\\s");
int pos = statNamePair.second < 0 ? splitStatString.length+statNamePair.second : statNamePair.second;
mStatsMap.put(statNamePair.first, splitStatString[pos]);
varStatus = baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, "");
break;
}
}
}
baseApi.end();
}