本项目是对 PaddleOCR (3.0.0 以上版本)的一个简单封装,详情请参考 PaddleOCR 文档。
该项目为 Java 客户端,C++ JNI 代码请参考 PaddleOCRJni
3.0.0 以下版本封装的 OCR 为 chineseocr_lite ,已停止维护更新,但仍然可用且更加轻量级。
需要安装 Oracle JDK 和 Maven
请根据自身环境选择下载 Release 中的代码样例包:
下载后解压到工作目录,执行如下命令:
cd demo-win
mvn clean compile exec:java -Dexec.mainClass="io.github.greycode.DemoApp"
Maven 添加依赖:
<dependency>
<groupId>io.github.greycode</groupId>
<artifactId>ocrlite</artifactId>
<version>3.0.0</version>
</dependency>
将 3.x.x 版本专用的 动态链接库 放到 resouces
目录下。
测试代码:
// 注意请务必使用绝对路径
String imagePath = "run-test/test_imgs/c.png";
OcrDriver.initialize();
List<List<OCRPredictResult>> ocrResult = OcrDriver.ocr(imagePath);
JAR 包自带的模型为超轻量模型,如果打算使用自定义模型文件,那么请将模型文件放到 resource (编译后为 classes 文件根目录)下,如果您的文件结构如下:
resources/
|-- det_db
| |--inference.pdiparams
| |--inference.pdmodel
|-- rec_rcnn
| |--inference.pdiparams
| |--inference.pdmodel
|-- cls
| |--inference.pdiparams
| |--inference.pdmodel
那么可以使用如下代码初始化引擎:
// 注意请务必使用绝对路径
String imagePath = "run-test/test_imgs/c.png";
OcrDriver
.initializeCustomModel("paddle_models")
.init();
List<List<OCRPredictResult>> ocrResult = OcrDriver.ocr(imagePath);
如果您的文件结构与以上不同,那么需要使用其他初始化方法:
OcrDriver
.initializeCustomModel(
"det_db",
"cls",
"rec_crnn",
"ppocr_keys_v1.txt",
"paddle_models")
.init();
注意:上面代码中的
det_db
等仍是相对于 resource 目录的子目录地址
注意:如果使用自定义模型,则可以使用更轻量的 -RELEASE 版本
Maven 添加依赖:
<dependency>
<groupId>io.github.greycode</groupId>
<artifactId>ocrlite</artifactId>
<version>2.0.2</version>
</dependency>
将 2.x.x 版本专用的 动态链接库 放到 resouces
目录下。
测试代码:
OcrDriver.initializeEngine();
String imagePath = "run-test/test_imgs/c.png";
OcrTextResult ocrResult = OcrDriver.detect(imagePath);
Maven 添加依赖:
<dependency>
<groupId>io.github.greycode</groupId>
<artifactId>ocrlite</artifactId>
<version>1.0.3-RELEASE</version>
</dependency>
将最新的 动态链接库 和 模型文件 放到 resouces
目录下。
测试代码:
OcrDriver.initializeEngine();
String imagePath = "run-test/test_imgs/c.png";
OcrTextResult ocrResult = OcrDriver.detect(imagePath);
特别注意:
1.0.3-RELEASE 为最新的简易封装版本。
2.x.x 版本为实验版本,原项目自带的动态链接库不适用。
3.x.x 版本改为封装 PaddleOCR 。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。