コード例 #1
0
  @SmallTest
  public void testGetThresholdedImage() {
    // 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);

    // Check the size of the thresholded image.
    Pix pixd = baseApi.getThresholdedImage();
    assertNotNull("Thresholded image is null.", pixd);
    assertEquals(bmp.getWidth(), pixd.getWidth());
    assertEquals(bmp.getHeight(), pixd.getHeight());

    // Attempt to shut down the API.
    baseApi.end();
    bmp.recycle();
    pixd.recycle();
  }
コード例 #2
0
  private void textExtraction(Bitmap croppedPic) {
    int width, height;
    height = croppedPic.getHeight();
    width = croppedPic.getWidth();

    Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bmpGrayscale);
    Paint paint = new Paint();
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
    paint.setColorFilter(f);
    c.drawBitmap(croppedPic, 0, 0, paint);

    baseApi.setImage(bmpGrayscale);
    baseApi.setImage(baseApi.getThresholdedImage());
    String recognizedText = baseApi.getUTF8Text();
    recognizedText = recognizedText.replaceAll("[^a-zA-Z0-9\\s]+", "");
    extractedText.setText(recognizedText);

    croppedImage.setImageBitmap(bmpGrayscale);
  }