3 Star 10 Fork 5

greyCode / ocrlite

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 4.78 KB
一键复制 编辑 原始数据 按行查看 历史
Calvin Yu 提交于 2022-05-19 14:08 . Update README.md

Contributors Forks Stargazers Issues MIT License

OcrLite

介绍

本项目是对 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"

3.x.x 版本

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 版本


2.x.x 版本

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);

1.x.x 版本

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 。

Java
1
https://gitee.com/greycode/ocrlite.git
git@gitee.com:greycode/ocrlite.git
greycode
ocrlite
ocrlite
master

搜索帮助