Skip to content

Commit 58cfff3

Browse files
committed
Release v1.0
1 parent 653b637 commit 58cfff3

30 files changed

Lines changed: 1745 additions & 19 deletions
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
2+
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path
3+
4+
name: Maven Package
5+
6+
on:
7+
release:
8+
types: [created]
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
packages: write
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Set up JDK 11
20+
uses: actions/setup-java@v3
21+
with:
22+
java-version: '11'
23+
distribution: 'temurin'
24+
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
25+
settings-path: ${{ github.workspace }} # location for the settings.xml file
26+
27+
- name: Build with Maven
28+
run: mvn -B package --file pom.xml
29+
30+
- name: Publish to GitHub Packages Apache Maven
31+
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
32+
env:
33+
GITHUB_TOKEN: ${{ github.token }}

.gitignore

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,41 @@
1-
# Compiled class file
2-
*.class
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
35

4-
# Log file
5-
*.log
6+
### IntelliJ IDEA ###
7+
.idea/modules.xml
8+
.idea/jarRepositories.xml
9+
.idea/compiler.xml
10+
.idea/libraries/
11+
*.iws
12+
*.iml
13+
*.ipr
614

7-
# BlueJ files
8-
*.ctxt
15+
### Eclipse ###
16+
.apt_generated
17+
.classpath
18+
.factorypath
19+
.project
20+
.settings
21+
.springBeans
22+
.sts4-cache
923

10-
# Mobile Tools for Java (J2ME)
11-
.mtj.tmp/
24+
### NetBeans ###
25+
/nbproject/private/
26+
/nbbuild/
27+
/dist/
28+
/nbdist/
29+
/.nb-gradle/
30+
build/
31+
!**/src/main/**/build/
32+
!**/src/test/**/build/
1233

13-
# Package Files #
14-
*.jar
15-
*.war
16-
*.nar
17-
*.ear
18-
*.zip
19-
*.tar.gz
20-
*.rar
34+
### VS Code ###
35+
.vscode/
2136

22-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23-
hs_err_pid*
37+
### Mac OS ###
38+
.DS_Store
39+
40+
### idea
41+
.idea/

README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,39 @@
1-
# ddddocr-for-java
1+
# ddddocr-for-java
2+
<div style="text-align: center">
3+
4+
![AUR](https://img.shields.io/badge/license-Apache%202.0-blue.svg)
5+
![Java](https://img.shields.io/badge/Java%2014.0.2-passing-success.svg)
6+
![Maven](https://img.shields.io/badge/Maven%203.6.3-building-success.svg)
7+
8+
</div>
9+
10+
基于[sml2h3](https://github.com/sml2h3)开源的[ddddocr](https://github.com/sml2h3/ddddocr)构建的java开源项目。源项目只提供pypi版本,不能满足java开发者的需求,特此尝试开发本项目。
11+
12+
## 基本使用
13+
目前只支持了ddddocr的OCR功能,使用了`common_old.onnx`模型。可以通过`mvn install`安装项目或者使用[github packages源](https://github.com/GCS-ZHN/ddddocr-for-java/packages),并添加maven依赖。
14+
```xml
15+
<dependency>
16+
<groupId>top.gcszhn</groupId>
17+
<artifactId>d4ocr</artifactId>
18+
<version>1.0</version>
19+
</dependency>
20+
```
21+
下面是简单的示例代码
22+
```java
23+
import java.awt.image.BufferedImage;
24+
25+
import top.gcszhn.d4ocr.OCREngine;
26+
import top.gcszhn.d4ocr.utils.IOUtils;
27+
28+
public class Test {
29+
public static void main(String[] args) {
30+
OCREngine engine = OCREngine.instance();
31+
BufferedImage image = IOUtils.read("AENZ.png");
32+
String predict = engine.recognize(image);
33+
System.out.println(predict);
34+
}
35+
}
36+
```
37+
38+
## 声明
39+
模型版权归原作者[sml2h3](https://github.com/sml2h3)所有,仅供学习交流使用,任何问题欢迎发issue或加入[Telegram交流群](https://t.me/zjuers)

pom.xml

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>top.gcszhn</groupId>
8+
<artifactId>d4ocr</artifactId>
9+
<version>1.0</version>
10+
<packaging>jar</packaging>
11+
<name>ddddocr for java</name>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<maven.compiler.source>11</maven.compiler.source>
16+
<maven.compiler.target>11</maven.compiler.target>
17+
</properties>
18+
19+
<dependencies>
20+
<!-- https://mvnrepository.com/artifact/com.microsoft.onnxruntime/onnxruntime -->
21+
<dependency>
22+
<groupId>com.microsoft.onnxruntime</groupId>
23+
<artifactId>onnxruntime</artifactId>
24+
<version>1.11.0</version>
25+
</dependency>
26+
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
27+
<dependency>
28+
<groupId>com.alibaba</groupId>
29+
<artifactId>fastjson</artifactId>
30+
<version>1.2.76</version>
31+
</dependency>
32+
<!--lombok插件-->
33+
<dependency>
34+
<groupId>org.projectlombok</groupId>
35+
<artifactId>lombok</artifactId>
36+
<version>1.18.20</version>
37+
<scope>provided</scope>
38+
</dependency>
39+
<!--slf4j-->
40+
<dependency>
41+
<groupId>org.slf4j</groupId>
42+
<artifactId>slf4j-api</artifactId>
43+
<version>1.7.25</version>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.slf4j</groupId>
47+
<artifactId>jcl-over-slf4j</artifactId>
48+
<version>1.7.25</version>
49+
<scope>runtime</scope>
50+
</dependency>
51+
<!--log4j2-->
52+
<dependency>
53+
<groupId>org.apache.logging.log4j</groupId>
54+
<artifactId>log4j-api</artifactId>
55+
<version>2.17.2</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.apache.logging.log4j</groupId>
59+
<artifactId>log4j-core</artifactId>
60+
<version>2.17.2</version>
61+
</dependency>
62+
<!--log4j2+slf4j桥接-->
63+
<dependency>
64+
<groupId>org.apache.logging.log4j</groupId>
65+
<artifactId>log4j-slf4j-impl</artifactId>
66+
<version>2.17.2</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>junit</groupId>
70+
<artifactId>junit</artifactId>
71+
<version>4.13</version>
72+
<scope>test</scope>
73+
</dependency>
74+
</dependencies>
75+
<build>
76+
<plugins>
77+
<plugin>
78+
<artifactId>maven-clean-plugin</artifactId>
79+
<version>3.1.0</version>
80+
</plugin>
81+
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
82+
<plugin>
83+
<artifactId>maven-resources-plugin</artifactId>
84+
<version>3.0.2</version>
85+
</plugin>
86+
<plugin>
87+
<artifactId>maven-compiler-plugin</artifactId>
88+
<version>3.8.0</version>
89+
</plugin>
90+
<plugin>
91+
<artifactId>maven-surefire-plugin</artifactId>
92+
<version>2.22.1</version>
93+
<configuration>
94+
<!--打包构建时跳过单元测试-->
95+
<skipTests>true</skipTests>
96+
</configuration>
97+
</plugin>
98+
<!--配置生成源码包-->
99+
<plugin>
100+
<groupId>org.apache.maven.plugins</groupId>
101+
<artifactId>maven-source-plugin</artifactId>
102+
<version>3.0.1</version>
103+
<executions>
104+
<execution>
105+
<id>attach-sources</id>
106+
<goals>
107+
<goal>jar</goal>
108+
</goals>
109+
</execution>
110+
</executions>
111+
</plugin>
112+
<plugin>
113+
<artifactId>maven-project-info-reports-plugin</artifactId>
114+
<version>3.0.0</version>
115+
</plugin>
116+
<!-- https://mvnrepository.com/artifact/com.mycila/license-maven-plugin -->
117+
<plugin>
118+
<groupId>com.mycila</groupId>
119+
<artifactId>license-maven-plugin</artifactId>
120+
<version>4.1</version>
121+
<executions>
122+
<execution>
123+
<?m2e execute onConfiguration?>
124+
<phase>generate-sources</phase>
125+
<goals>
126+
<goal>remove</goal>
127+
<goal>format</goal>
128+
</goals>
129+
</execution>
130+
</executions>
131+
<configuration>
132+
<quiet>true</quiet>
133+
<!--HEADER文件-->
134+
<header>${project.basedir}/templete/license.temp</header>
135+
<!--排除文件-->
136+
<excludes>
137+
<exclude>**/*.properties</exclude>
138+
<exclude>**/*.sh</exclude>
139+
<exclude>**/*.yml</exclude>
140+
<exclude>.editorconfig</exclude>
141+
<exclude>.gitignore</exclude>
142+
<exclude>**/*.md</exclude>
143+
<exclude>**/*.xml</exclude>
144+
<exclude>**/*.txt</exclude>
145+
<exclude>**/*.vm</exclude>
146+
</excludes>
147+
<!--严格检查-->
148+
<strictCheck>true</strictCheck>
149+
<mapping>
150+
<java>SLASHSTAR_STYLE</java>
151+
</mapping>
152+
</configuration>
153+
</plugin>
154+
<plugin>
155+
<groupId>org.projectlombok</groupId>
156+
<artifactId>lombok-maven-plugin</artifactId>
157+
<version>1.18.20.0</version>
158+
<executions>
159+
<execution>
160+
<phase>generate-sources</phase>
161+
<goals>
162+
<goal>delombok</goal>
163+
</goals>
164+
</execution>
165+
</executions>
166+
</plugin>
167+
</plugins>
168+
</build>
169+
<distributionManagement>
170+
<repository>
171+
<id>github</id>
172+
<name>Github maven package</name>
173+
<url>https://maven.pkg.github.com/gcs-zhn/ddddocr-for-java</url>
174+
</repository>
175+
</distributionManagement>
176+
</project>

settings.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
4+
http://maven.apache.org/xsd/settings-1.0.0.xsd">
5+
6+
<servers>
7+
<server>
8+
<id>github</id>
9+
<username>GCS-ZHN</username>
10+
<password>${env.GITHUB_TOKEN}</password>
11+
</server>
12+
</servers>
13+
</settings>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright © 2022 <a href="mailto:zhang.h.n@foxmail.com">Zhang.H.N</a>.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (thie "License");
5+
* You may not use this file except in compliance with the license.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://wwww.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language govering permissions and
14+
* limitations under the License.
15+
*/
16+
package top.gcszhn.d4ocr;
17+
18+
import java.awt.image.BufferedImage;
19+
20+
/**
21+
* 统一的OCR引擎接口,所有引擎扩展需要实现该接口
22+
* @author GCS-ZHN
23+
* */
24+
public interface OCREngine {
25+
/**
26+
* OCR文本识别的抽象API
27+
* @param image 图像
28+
* @return 识别的文本
29+
*/
30+
public String recognize(BufferedImage image);
31+
/**
32+
* 返回D4 OCR引擎实例
33+
* */
34+
public static OCREngine instance() {
35+
return new OCREngineOldImpl();
36+
}
37+
}

0 commit comments

Comments
 (0)