コード例 #1
0
ファイル: TessAPI1Test.java プロジェクト: zhaojianping/tess4j
 /**
  * Test of Orientation and script detection (OSD).
  *
  * @throws Exception while processing the image.
  */
 @Test
 public void testOSD() throws Exception {
   logger.info("OSD");
   int expResult = TessPageSegMode.PSM_AUTO_OSD;
   IntBuffer orientation = IntBuffer.allocate(1);
   IntBuffer direction = IntBuffer.allocate(1);
   IntBuffer order = IntBuffer.allocate(1);
   FloatBuffer deskew_angle = FloatBuffer.allocate(1);
   File tiff = new File(this.testResourcesDataPath, "eurotext.tif");
   BufferedImage image =
       ImageIO.read(new FileInputStream(tiff)); // require jai-imageio lib to read TIFF
   ByteBuffer buf = ImageIOHelper.convertImageData(image);
   int bpp = image.getColorModel().getPixelSize();
   int bytespp = bpp / 8;
   int bytespl = (int) Math.ceil(image.getWidth() * bpp / 8.0);
   TessAPI1.TessBaseAPIInit3(handle, datapath, language);
   TessAPI1.TessBaseAPISetPageSegMode(handle, expResult);
   int actualResult = TessAPI1.TessBaseAPIGetPageSegMode(handle);
   logger.info("PSM: " + Utils.getConstantName(actualResult, TessPageSegMode.class));
   TessAPI1.TessBaseAPISetImage(
       handle, buf, image.getWidth(), image.getHeight(), bytespp, bytespl);
   int success = TessAPI1.TessBaseAPIRecognize(handle, null);
   if (success == 0) {
     TessAPI1.TessPageIterator pi = TessAPI1.TessBaseAPIAnalyseLayout(handle);
     TessAPI1.TessPageIteratorOrientation(pi, orientation, direction, order, deskew_angle);
     logger.info(
         String.format(
             "Orientation: %s\nWritingDirection: %s\nTextlineOrder: %s\nDeskew angle: %.4f\n",
             Utils.getConstantName(orientation.get(), TessOrientation.class),
             Utils.getConstantName(direction.get(), TessWritingDirection.class),
             Utils.getConstantName(order.get(), TessTextlineOrder.class),
             deskew_angle.get()));
   }
   assertEquals(expResult, actualResult);
 }
コード例 #2
0
ファイル: TessAPI1Test.java プロジェクト: zhaojianping/tess4j
 /** Test of TessBaseAPIGetPageSegMode method, of class TessAPI1. */
 @Test
 public void testTessBaseAPIGetPageSegMode() {
   logger.info("TessBaseAPIGetPageSegMode");
   TessAPI1.TessBaseAPISetPageSegMode(handle, TessPageSegMode.PSM_SINGLE_CHAR);
   int expResult = TessPageSegMode.PSM_SINGLE_CHAR;
   int result = TessAPI1.TessBaseAPIGetPageSegMode(handle);
   assertEquals(expResult, result);
 }