3 Star 10 Fork 5

greyCode / ocrlite

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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 。

MIT License Copyright (c) 2022 Calvin Yu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

本项目是对 PaddleOCR (3.0.0 以上版本)的一个简单封装,详情请参考 PaddleOCR 文档。 展开 收起
Java
MIT
取消

发行版 (1)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/greycode/ocrlite.git
git@gitee.com:greycode/ocrlite.git
greycode
ocrlite
ocrlite
master

搜索帮助