예제 #1
0
  /** Test of TessBaseAPIInit4 method, of class TessAPI1. */
  @Test
  public void testTessBaseAPIInit4() {
    logger.info("TessBaseAPIInit4");
    int oem = TessOcrEngineMode.OEM_DEFAULT;
    PointerByReference configs = null;
    int configs_size = 0;
    // disable loading dictionaries
    String[] args = new String[] {"load_system_dawg", "load_freq_dawg"};
    StringArray sarray = new StringArray(args);
    PointerByReference vars_vec = new PointerByReference();
    vars_vec.setPointer(sarray);

    args = new String[] {"F", "F"};
    sarray = new StringArray(args);
    PointerByReference vars_values = new PointerByReference();
    vars_values.setPointer(sarray);

    NativeSize vars_vec_size = new NativeSize(args.length);

    int expResult = 0;
    int result =
        TessAPI1.TessBaseAPIInit4(
            handle,
            datapath,
            language,
            oem,
            configs,
            configs_size,
            vars_vec,
            vars_values,
            vars_vec_size,
            FALSE);
    assertEquals(expResult, result);
  }
예제 #2
0
  protected void setBinaries(Map<CLDevice, byte[]> binaries) {
    if (this.devices == null) {
      this.devices = new CLDevice[binaries.size()];
      int iDevice = 0;
      for (CLDevice device : binaries.keySet()) this.devices[iDevice++] = device;
    }
    int nDevices = this.devices.length;
    NativeSize[] lengths = new NativeSize[nDevices];
    cl_device_id[] deviceIds = new cl_device_id[nDevices];
    Memory binariesArray = new Memory(Pointer.SIZE * nDevices);
    Memory[] binariesMems = new Memory[nDevices];

    for (int iDevice = 0; iDevice < nDevices; iDevice++) {
      CLDevice device = devices[iDevice];
      byte[] binary = binaries.get(device);

      Memory binaryMem = binariesMems[iDevice] = new Memory(binary.length);
      binaryMem.write(0, binary, 0, binary.length);
      binariesArray.setPointer(iDevice * Pointer.SIZE, binaryMem);

      lengths[iDevice] = toNS(binary.length);
      deviceIds[iDevice] = device.getEntity();
    }
    PointerByReference binariesPtr = new PointerByReference();
    binariesPtr.setPointer(binariesArray);

    IntBuffer errBuff = NIOUtils.directInts(1, ByteOrder.nativeOrder());
    int previousAttempts = 0;
    IntBuffer statuses = NIOUtils.directInts(nDevices, ByteOrder.nativeOrder());
    do {
      entity =
          CL.clCreateProgramWithBinary(
              context.getEntity(), nDevices, deviceIds, lengths, binariesPtr, statuses, errBuff);
    } while (failedForLackOfMemory(errBuff.get(0), previousAttempts++));
  }
예제 #3
0
 /** Test of TessBaseAPIInit1 method, of class TessAPI1. */
 @Test
 public void testTessBaseAPIInit1() throws Exception {
   logger.info("TessBaseAPIInit1");
   int oem = TessOcrEngineMode.OEM_DEFAULT;
   String[] args = {"hocr"};
   StringArray sarray = new StringArray(args);
   PointerByReference configs = new PointerByReference();
   configs.setPointer(sarray);
   int configs_size = args.length;
   int expResult = 0;
   int result = TessAPI1.TessBaseAPIInit1(handle, datapath, language, oem, configs, configs_size);
   assertEquals(expResult, result);
 }
예제 #4
0
  private void writeNative(byte[] bs) throws SerialPortException {
    Memory mem = new Memory(Byte.SIZE * bs.length + 1);
    mem.clear();

    PointerByReference inipar = new PointerByReference();
    inipar.setPointer(mem);
    for (int i = 0; i < bs.length; i++) {
      inipar.getPointer().setByte(i * Byte.SIZE / 8, bs[i]);
    }
    byte c = '\n';
    inipar.getPointer().setByte((bs.length + 1) * Byte.SIZE / 8, c);
    int rt = NativeLoader.getInstance().serialport_write(getFd(), inipar);
    if (rt != 0) {
      logger.error("Warning fail to write store " + bs.length);
      throw new SerialPortException("The serial port is closed " + getFd());
    }
  }
예제 #5
0
  /**
   * Test of ResultRenderer method, of class TessAPI1.
   *
   * @throws java.lang.Exception
   */
  @Test
  public void testResultRenderer() throws Exception {
    logger.info("TessResultRenderer");
    String image = String.format("%s/%s", this.testResourcesDataPath, "eurotext.tif");
    String output = "capi-test.txt";
    int set_only_init_params = TessAPI.FALSE;
    int oem = TessOcrEngineMode.OEM_DEFAULT;
    PointerByReference configs = null;
    int configs_size = 0;

    String[] params = {"load_system_dawg", "tessedit_char_whitelist"};
    String vals[] = {"F", ""}; // 0123456789-.IThisalotfpnex
    PointerByReference vars_vec = new PointerByReference();
    vars_vec.setPointer(new StringArray(params));
    PointerByReference vars_values = new PointerByReference();
    vars_values.setPointer(new StringArray(vals));
    NativeSize vars_vec_size = new NativeSize(params.length);

    TessAPI1.TessBaseAPISetOutputName(handle, output);

    int rc =
        TessAPI1.TessBaseAPIInit4(
            handle,
            datapath,
            language,
            oem,
            configs,
            configs_size,
            vars_vec,
            vars_values,
            vars_vec_size,
            set_only_init_params);

    if (rc != 0) {
      TessAPI1.TessBaseAPIDelete(handle);
      logger.error("Could not initialize tesseract.");
      return;
    }

    String outputbase = "target/test-classes/test-results/outputbase1";
    TessResultRenderer renderer = TessAPI1.TessHOcrRendererCreate(outputbase);
    TessAPI1.TessResultRendererInsert(renderer, TessAPI1.TessBoxTextRendererCreate(outputbase));
    TessAPI1.TessResultRendererInsert(renderer, TessAPI1.TessTextRendererCreate(outputbase));
    String dataPath = TessAPI1.TessBaseAPIGetDatapath(handle);
    TessAPI1.TessResultRendererInsert(
        renderer, TessAPI1.TessPDFRendererCreate(outputbase, dataPath));
    TessAPI1.TessResultRendererBeginDocument(renderer, image);
    int result = TessAPI1.TessBaseAPIProcessPages(handle, image, null, 0, renderer);
    TessAPI1.TessResultRendererEndDocument(renderer);

    //        if (result == FALSE) {
    //            logger.error("Error during processing.");
    //            return;
    //        }
    for (; renderer != null; renderer = TessAPI1.TessResultRendererNext(renderer)) {
      String ext = TessAPI1.TessResultRendererExtention(renderer).getString(0);
      logger.info(
          String.format(
              "TessResultRendererExtention: %s\nTessResultRendererTitle: %s\nTessResultRendererImageNum: %d",
              ext,
              TessAPI1.TessResultRendererTitle(renderer).getString(0),
              TessAPI1.TessResultRendererImageNum(renderer)));
    }

    TessAPI1.TessDeleteResultRenderer(renderer);
    assertTrue(new File(outputbase + ".pdf").exists());
  }