コード例 #1
0
    @Override
    public HRESULT QueryInterface(REFIID.ByValue refid, PointerByReference ppvObject) {
      this.QueryInterface_called = true;
      if (null == ppvObject) {
        return new HRESULT(WinError.E_POINTER);
      }

      String s = refid.toGuidString();
      IID appEvnts4 = new IID("{00020A01-0000-0000-C000-000000000046}");
      REFIID.ByValue riid = new REFIID.ByValue(appEvnts4.getPointer());

      if (refid.equals(riid)) {
        return WinError.S_OK;
      }

      if (new Guid.IID(refid.getPointer()).equals(Unknown.IID_IUNKNOWN)) {
        ppvObject.setValue(this.getPointer());
        return WinError.S_OK;
      }

      if (new Guid.IID(refid.getPointer()).equals(Dispatch.IID_IDISPATCH)) {
        ppvObject.setValue(this.getPointer());
        return WinError.S_OK;
      }

      return new HRESULT(WinError.E_NOINTERFACE);
    }
コード例 #2
0
ファイル: TessAPI1Test.java プロジェクト: zhaojianping/tess4j
  /**
   * Test of TessBaseAPIGetUTF8Text method, of class TessAPI1.
   *
   * @throws java.lang.Exception
   */
  @Test
  public void testTessBaseAPIGetUTF8Text_Pix() throws Exception {
    logger.info("TessBaseAPIGetUTF8Text_Pix");
    String expResult = expOCRResult;
    File tiff = new File(this.testResourcesDataPath, "eurotext.tif");
    Leptonica leptInstance = Leptonica.INSTANCE;
    Pix pix = leptInstance.pixRead(tiff.getPath());
    TessAPI1.TessBaseAPIInit3(handle, datapath, language);
    TessAPI1.TessBaseAPISetImage2(handle, pix);
    Pointer utf8Text = TessAPI1.TessBaseAPIGetUTF8Text(handle);
    String result = utf8Text.getString(0);
    TessAPI1.TessDeleteText(utf8Text);
    logger.info(result);

    // release Pix resource
    PointerByReference pRef = new PointerByReference();
    pRef.setValue(pix.getPointer());
    leptInstance.pixDestroy(pRef);

    assertEquals(expResult, result.substring(0, expResult.length()));
  }
コード例 #3
0
ファイル: TessAPI1Test.java プロジェクト: zhaojianping/tess4j
  /**
   * Test of TessBaseAPIGetComponentImages method, of class TessAPI1.
   *
   * @throws java.lang.Exception
   */
  @Test
  public void testTessBaseAPIGetComponentImages() throws Exception {
    logger.info("TessBaseAPIGetComponentImages");
    File image = new File(this.testResourcesDataPath, "eurotext.png");
    int expResult = 12; // number of lines in the test image
    Pix pix = Leptonica1.pixRead(image.getPath());
    TessAPI1.TessBaseAPIInit3(handle, datapath, language);
    TessAPI1.TessBaseAPISetImage2(handle, pix);
    PointerByReference pixa = null;
    PointerByReference blockids = null;
    Boxa boxes =
        TessAPI1.TessBaseAPIGetComponentImages(
            handle, TessPageIteratorLevel.RIL_TEXTLINE, TRUE, pixa, blockids);
    //        boxes = TessAPI1.TessBaseAPIGetRegions(handle, pixa); // equivalent to
    // TessPageIteratorLevel.RIL_BLOCK
    int boxCount = Leptonica1.boxaGetCount(boxes);
    for (int i = 0; i < boxCount; i++) {
      Box box = Leptonica1.boxaGetBox(boxes, i, L_CLONE);
      if (box == null) {
        continue;
      }
      TessAPI1.TessBaseAPISetRectangle(handle, box.x, box.y, box.w, box.h);
      Pointer utf8Text = TessAPI1.TessBaseAPIGetUTF8Text(handle);
      String ocrResult = utf8Text.getString(0);
      TessAPI1.TessDeleteText(utf8Text);
      int conf = TessAPI1.TessBaseAPIMeanTextConf(handle);
      System.out.print(
          String.format(
              "Box[%d]: x=%d, y=%d, w=%d, h=%d, confidence: %d, text: %s",
              i, box.x, box.y, box.w, box.h, conf, ocrResult));
    }

    // release Pix resource
    PointerByReference pRef = new PointerByReference();
    pRef.setValue(pix.getPointer());
    Leptonica1.pixDestroy(pRef);

    assertEquals(expResult, boxCount);
  }