当前位置: 首页>>代码示例>>Java>>正文


Java TessBaseAPI.end方法代码示例

本文整理汇总了Java中com.googlecode.tesseract.android.TessBaseAPI.end方法的典型用法代码示例。如果您正苦于以下问题:Java TessBaseAPI.end方法的具体用法?Java TessBaseAPI.end怎么用?Java TessBaseAPI.end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.googlecode.tesseract.android.TessBaseAPI的用法示例。


在下文中一共展示了TessBaseAPI.end方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
 
开发者ID:simplezhli,项目名称:Tesseract-OCR-Scanner,代码行数:24,代码来源:TessEngine.java

示例2: 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";
}
 
开发者ID:F4b1-,项目名称:Pixtern-Library,代码行数:25,代码来源:CardValidationActivity.java

示例3: 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();
}
 
开发者ID:Awahid,项目名称:scanNedit,代码行数:18,代码来源:TessBaseAPITest.java

示例4: 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());
                }
            }
        });
    }
}
 
开发者ID:shenhuanet,项目名称:Ocr-android,代码行数:41,代码来源:RecognitionActivity.java

示例5: 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;
}
 
开发者ID:Bhek,项目名称:Final-Year-Project,代码行数:11,代码来源:ImageActivity.java

示例6: 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();
}
 
开发者ID:Awahid,项目名称:scanNedit,代码行数:14,代码来源:TessBaseAPITest.java

示例7: 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();
}
 
开发者ID:Awahid,项目名称:scanNedit,代码行数:40,代码来源:TessBaseAPITest.java

示例8: 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;
  }
}
 
开发者ID:phoenixtwister,项目名称:cordova-juleskelly-tesseract,代码行数:75,代码来源:TesseractOCR.java

示例9: 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;
}
 
开发者ID:mplackowski,项目名称:previewOCR,代码行数:69,代码来源:CameraTool.java

示例10: 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();
}
 
开发者ID:keithel,项目名称:Ingress-Stat-Tracker,代码行数:45,代码来源:StatTrackerActivity.java


注:本文中的com.googlecode.tesseract.android.TessBaseAPI.end方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。