Java Code Examples for com.sun.jna.ptr.PointerByReference#setPointer()

The following examples show how to use com.sun.jna.ptr.PointerByReference#setPointer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TessAPITest.java    From tess4j with Apache License 2.0 6 votes vote down vote up
/**
 * Test of TessBaseAPIInit4 method, of class TessAPI.
 */
@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 = api.TessBaseAPIInit4(handle, datapath, language, oem, configs, configs_size, vars_vec, vars_values, vars_vec_size, FALSE);
    assertEquals(expResult, result);
}
 
Example 2
Source File: TessAPI1Test.java    From tess4j with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source File: Tesseract.java    From tess4j with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Tesseract engine.
 */
protected void init() {
    api = TessAPI.INSTANCE;
    handle = api.TessBaseAPICreate();
    StringArray sarray = new StringArray(configList.toArray(new String[0]));
    PointerByReference configs = new PointerByReference();
    configs.setPointer(sarray);
    api.TessBaseAPIInit1(handle, datapath, language, ocrEngineMode, configs, configList.size());
    if (psm > -1) {
        api.TessBaseAPISetPageSegMode(handle, psm);
    }
}
 
Example 4
Source File: Tesseract1.java    From tess4j with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Tesseract engine.
 */
protected void init() {
    handle = TessBaseAPICreate();
    StringArray sarray = new StringArray(configList.toArray(new String[0]));
    PointerByReference configs = new PointerByReference();
    configs.setPointer(sarray);
    TessBaseAPIInit1(handle, datapath, language, ocrEngineMode, configs, configList.size());
    if (psm > -1) {
        TessBaseAPISetPageSegMode(handle, psm);
    }
}
 
Example 5
Source File: TessAPITest.java    From tess4j with Apache License 2.0 4 votes vote down vote up
/**
 * Test of ResultRenderer method, of class TessAPI.
 *
 * @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 = 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);

    api.TessBaseAPISetOutputName(handle, output);

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

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

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

    if (result == FALSE) {
        logger.error("Error during processing.");
        return;
    }

    while ((renderer = api.TessResultRendererNext(renderer)) != null) {
        String ext = api.TessResultRendererExtention(renderer).getString(0);
        logger.info(String.format("TessResultRendererExtention: %s\nTessResultRendererTitle: %s\nTessResultRendererImageNum: %d",
                ext,
                api.TessResultRendererTitle(renderer).getString(0),
                api.TessResultRendererImageNum(renderer)));
    }

    api.TessDeleteResultRenderer(renderer);
    assertTrue(new File(outputbase + ".pdf").exists());
}
 
Example 6
Source File: TessAPI1Test.java    From tess4j with Apache License 2.0 4 votes vote down vote up
/**
     * 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 = ITessAPI.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/ResultRenderer1";
        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, FALSE));
        int result = TessAPI1.TessBaseAPIProcessPages(handle, image, null, 0, renderer);

//        if (result == FALSE) {
//            logger.error("Error during processing.");
//            return;
//        }
        while ((renderer = TessAPI1.TessResultRendererNext(renderer)) != null) {
            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());
    }