Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /** Initializes Tesseract engine. */
 private void init() {
   pageNum = 0;
   api = TessAPI.INSTANCE;
   handle = api.TessBaseAPICreate();
   api.TessBaseAPIInit2(handle, datapath, language, ocrEngineMode);
   api.TessBaseAPISetPageSegMode(handle, psm);
 }
Exemplo n.º 3
0
  /**
   * 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);
    }
  }
Exemplo n.º 4
0
 /** 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));
   }
 }
Exemplo n.º 5
0
 /** Releases all of the native resources used by this instance. */
 private void dispose() {
   api.TessBaseAPIDelete(handle);
 }