- 使用Java将图像转换为文本
- 使用Java转换具有单行文本的图像
目前,Java版Aspose.OCR升级到v20.5版,感兴趣的朋友可点击下方按钮下载最新版。

使用Java将图像转换为文本
最常见的是,OCR的图像是扫描的文档,发票,收据,账单等的页面,其中文本由多行组成。在这种情况下,您需要从图像中检索整个文本。以下是使用Java版Aspose.OCR在具有多行文本的图像上执行OCR的步骤。
- 创建一个AsposeOcr 类的实例 。
- 通过传递图像的路径,使用AsposeOcr.recognizePage(String fullPath)方法将图像转换为文本。
- 将转换后的文本转换为字符串对象。
下面的代码示例演示如何使用Java对图像执行OCR并将图像转换为文本。
// The path to the documents directory.String dataDir = Utils.getSharedDataDir(PerformOCROnPage.class);// The image pathString imagePath = dataDir + "p3.png";//Create api instanceAsposeOCR api = new AsposeOCR();// Recognize page by full path to filetry {String result = api.RecognizePage(imagePath);System.out.println("Result: " + result);} catch (IOException e) {e.printStackTrace();}
转换具有单行文本的图像
有时可能会出现图像包含一行文字的情况。在这种情况下,可以相应地配置API。以下是转换具有单行文本的图像的步骤。
- 创建一个AsposeOcr 类的对象 。
- 使用AsposeOcr.recognizeLine(String fullPath) 方法将图像转换为文本。
- 将结果放入字符串对象。
下面的代码示例演示如何使用Java在具有一行文本的图像上执行OCR。
// The path to the documents directory.String dataDir = Utils.getSharedDataDir(RecognizeLine.class);// The image pathString imagePath = dataDir + "0001460985.Jpeg";//Create api instanceAsposeOCR api = new AsposeOCR();try {String result = api.RecognizeLine(imagePath);System.out.println("File: " + imagePath);System.out.println("Result line: " + result);} catch (IOException e) {e.printStackTrace();}
还想要更多吗可以点击阅读【2020 · Aspose最新资源整合】,查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!