/**
  * Gets recognized text.
  *
  * @return the recognized text
  */
 private String getOCRText() {
   Pointer utf8Text =
       hocr ? api.TessBaseAPIGetHOCRText(handle, pageNum - 1) : api.TessBaseAPIGetUTF8Text(handle);
   String str = utf8Text.getString(0);
   api.TessDeleteText(utf8Text);
   return str;
 }
 /** Initializes Tesseract engine. */
 private void init() {
   pageNum = 0;
   api = TessAPI.INSTANCE;
   handle = api.TessBaseAPICreate();
   api.TessBaseAPIInit2(handle, datapath, language, ocrEngineMode);
   api.TessBaseAPISetPageSegMode(handle, psm);
 }
  /**
   * Sets image to be processed.
   *
   * @param xsize width of image
   * @param ysize height of image
   * @param buf pixel data
   * @param rect the bounding rectangle defines the region of the image to be recognized. A
   *     rectangle of zero dimension or <code>null</code> indicates the whole image.
   * @param bpp bits per pixel, represents the bit depth of the image, with 1 for binary bitmap, 8
   *     for gray, and 24 for color RGB.
   */
  private void setImage(int xsize, int ysize, ByteBuffer buf, Rectangle rect, int bpp) {
    int bytespp = bpp / 8;
    int bytespl = (int) Math.ceil(xsize * bpp / 8.0);
    api.TessBaseAPISetImage(handle, buf, xsize, ysize, bytespp, bytespl);

    if (rect != null && !rect.isEmpty()) {
      api.TessBaseAPISetRectangle(handle, rect.x, rect.y, rect.width, rect.height);
    }
  }
 /** Sets Tesseract's internal parameters. */
 private void setTessVariables() {
   Enumeration<?> em = prop.propertyNames();
   while (em.hasMoreElements()) {
     String key = (String) em.nextElement();
     api.TessBaseAPISetVariable(handle, key, prop.getProperty(key));
   }
 }
 /** Releases all of the native resources used by this instance. */
 private void dispose() {
   api.TessBaseAPIDelete(handle);
 }