GetcharZp commited on
Commit
86ef3fc
·
1 Parent(s): dbefef8

:sparkles: update onnx runtime to v1.28

Browse files
README.md CHANGED
@@ -1,6 +1,9 @@
1
  ---
2
  license: mit
3
  pipeline_tag: image-to-text
 
 
 
4
  ---
5
  <div align="center" style="text-align: center;">
6
  <img src="./assets/logo.png" alt="logo" width="300" style="display: block; margin: 0 auto;" />
@@ -18,49 +21,45 @@ pipeline_tag: image-to-text
18
  </a>
19
  </p>
20
 
21
- go-ocr 是一款基于 Golang + ONNX 构建的 OCR 工具库,专注于为 Go 生态提供简单易用、可扩展的文字识别能力。
22
- 目前已完成与 PaddleOCR、DdddOCR 的对接,支持快速实现图像文字检测与识别。
 
23
 
24
- ## 安装
 
25
 
26
- ### 1. 安装 Go 依赖
 
 
27
 
28
  ```shell
29
  go get -u github.com/getcharzp/go-ocr
30
  ```
31
 
32
- ### 2. 按需下载模型与动态链接库
33
 
34
- 模型与动态链接库存放在独立仓库(HuggingFace,含 ModelScope 国内镜像),**无需全量下载**,请根据实际使用的引擎按需下载所需文件。
35
 
36
- - HuggingFace 仓库地址:https://huggingface.co/getcharzp/go-ocr
37
- - ModelScope 镜像地址:https://www.modelscope.cn/getcharzp/go-ocr
38
 
39
- **目录结构**
40
 
41
- ```txt
42
- paddle_weights/ # PaddleOCR 所需
43
- ddddocr_weights/ # DdddOCR 所需
44
- lib/ # onnxruntime 动态链接库(按平台选择)
45
- ```
46
 
47
- **动态链接库选择**
48
-
49
- onnxruntime 动态链接库需按运行平台选择:
50
-
51
- | 平台 | 文件 |
52
  | --- | --- |
53
  | Linux | `lib/onnxruntime_amd64.so` |
54
  | Windows | `lib/onnxruntime.dll` |
55
  | macOS | `lib/onnxruntime_amd64.dylib` |
56
 
57
- ## 快速开始
58
 
59
  ### PaddleOCR
60
 
61
- **示例代码**
62
 
63
- 通过 OCR 引擎的 `RunOCR()` 方法能直接进行完整的检测与识别,也可以通过 `RunDetect()` 仅进行文字区域检测。
64
 
65
  ```go
66
  package main
@@ -73,51 +72,51 @@ import (
73
  )
74
 
75
  func main() {
76
- // 按实际情况配置下述路径
77
  config := paddle.Config{
78
  OnnxRuntimeLibPath: "./lib/onnxruntime_amd64.so",
79
  DetModelPath: "./paddle_weights/det.onnx",
80
  RecModelPath: "./paddle_weights/rec.onnx",
81
  DictPath: "./paddle_weights/dict.txt",
82
- // ThreadCount: 4, // (可选) 并行识别 Session 数, 默认 1
83
  }
84
 
85
- // 初始化引擎(返回对象实现了 ocr.Engine 接口)
86
  var engine ocr.Engine
87
  engine, err := paddle.NewEngine(config)
88
  if err != nil {
89
- log.Fatalf("创建 OCR 引擎失败: %v\n", err)
90
  }
91
  defer engine.Destroy()
92
 
93
- // 打开图像
94
  imagePath := "./test.jpg"
95
  img, err := imageutil.Open(imagePath)
96
  if err != nil {
97
- log.Fatalf("加载图像失败: %v\n", err)
98
  }
99
 
100
- // OCR识别
101
  results, err := engine.RunOCR(img)
102
  if err != nil {
103
- log.Fatalf("运行 OCR 失败: %v\n", err)
104
  }
105
  for _, result := range results {
106
- log.Printf("识别结果: %v\n", result)
107
  }
108
  }
109
  ```
110
 
111
- **示例效果**
112
 
113
- | 原图 | 检测结果 |
114
  |-----------------------------------------------------|----------------------------------------------------|
115
  | <img width="100%" src="./examples/test.jpg" alt=""> | <img width="100%" src="./examples/det.jpg" alt=""> |
116
 
117
 
118
  ### DdddOCR
119
 
120
- **示例代码**
121
 
122
  ```go
123
  package main
@@ -139,19 +138,19 @@ func main() {
139
 
140
  engine, err := ddddocr.NewEngine(config)
141
  if err != nil {
142
- log.Fatalf("创建 OCR 引擎失败: %v\n", err)
143
  }
144
  defer engine.Destroy()
145
 
146
  imagePath := "./captcha_det.png"
147
  img, err := imageutil.Open(imagePath)
148
  if err != nil {
149
- log.Fatalf("加载图像失败: %v\n", err)
150
  }
151
 
152
  boxes, err := engine.Detect(img)
153
  if err != nil {
154
- log.Fatalf("运行检测失败: %v\n", err)
155
  }
156
 
157
  tagImg := image.NewRGBA(img.Bounds())
@@ -165,9 +164,12 @@ func main() {
165
  }
166
  ```
167
 
168
- **示例效果**
169
 
170
- | 原图 | 检测结果 |
171
  |-------------------------------------------------------------|-------------------------------------------------------------------|
172
  | <img width="100%" src="./examples/captcha_det.png" alt=""> | <img width="100%" src="./examples/captcha_det_result.png" alt=""> |
173
 
 
 
 
 
1
  ---
2
  license: mit
3
  pipeline_tag: image-to-text
4
+ language:
5
+ - en
6
+ - zh
7
  ---
8
  <div align="center" style="text-align: center;">
9
  <img src="./assets/logo.png" alt="logo" width="300" style="display: block; margin: 0 auto;" />
 
21
  </a>
22
  </p>
23
 
24
+ <p align="center">
25
+ English | <a href="./docs/README_zh.md">简体中文</a>
26
+ </p>
27
 
28
+ go-ocr is an OCR library built on Golang + ONNX, focused on providing simple, easy-to-use and extensible text recognition capabilities for the Go ecosystem.
29
+ It already integrates with PaddleOCR and DdddOCR, so you can quickly implement image text detection and recognition.
30
 
31
+ ## Installation
32
+
33
+ ### 1. Install the Go dependency
34
 
35
  ```shell
36
  go get -u github.com/getcharzp/go-ocr
37
  ```
38
 
39
+ ### 2. Download the models and dynamic libraries you need
40
 
41
+ Models and dynamic libraries are hosted in a separate repository (HuggingFace, with a ModelScope mirror for mainland China). **There is no need to download everything** — download only the files required by the engine you actually use.
42
 
43
+ - HuggingFace repository: https://huggingface.co/getcharzp/go-ocr
44
+ - ModelScope mirror: https://www.modelscope.cn/getcharzp/go-ocr
45
 
46
+ **Choosing the dynamic library**
47
 
48
+ Pick the onnxruntime dynamic library that matches your runtime platform:
 
 
 
 
49
 
50
+ | Platform | File |
 
 
 
 
51
  | --- | --- |
52
  | Linux | `lib/onnxruntime_amd64.so` |
53
  | Windows | `lib/onnxruntime.dll` |
54
  | macOS | `lib/onnxruntime_amd64.dylib` |
55
 
56
+ ## Quick Start
57
 
58
  ### PaddleOCR
59
 
60
+ **Example code**
61
 
62
+ Calling `RunOCR()` on the engine performs full detection and recognition, while `RunDetect()` performs text region detection only.
63
 
64
  ```go
65
  package main
 
72
  )
73
 
74
  func main() {
75
+ // Configure these paths for your environment
76
  config := paddle.Config{
77
  OnnxRuntimeLibPath: "./lib/onnxruntime_amd64.so",
78
  DetModelPath: "./paddle_weights/det.onnx",
79
  RecModelPath: "./paddle_weights/rec.onnx",
80
  DictPath: "./paddle_weights/dict.txt",
81
+ // ThreadCount: 4, // (optional) number of parallel recognition sessions, defaults to 1
82
  }
83
 
84
+ // Initialize the engine (the returned value implements the ocr.Engine interface)
85
  var engine ocr.Engine
86
  engine, err := paddle.NewEngine(config)
87
  if err != nil {
88
+ log.Fatalf("failed to create OCR engine: %v\n", err)
89
  }
90
  defer engine.Destroy()
91
 
92
+ // Open the image
93
  imagePath := "./test.jpg"
94
  img, err := imageutil.Open(imagePath)
95
  if err != nil {
96
+ log.Fatalf("failed to load image: %v\n", err)
97
  }
98
 
99
+ // Run OCR
100
  results, err := engine.RunOCR(img)
101
  if err != nil {
102
+ log.Fatalf("failed to run OCR: %v\n", err)
103
  }
104
  for _, result := range results {
105
+ log.Printf("result: %v\n", result)
106
  }
107
  }
108
  ```
109
 
110
+ **Example output**
111
 
112
+ | Original image | Detection result |
113
  |-----------------------------------------------------|----------------------------------------------------|
114
  | <img width="100%" src="./examples/test.jpg" alt=""> | <img width="100%" src="./examples/det.jpg" alt=""> |
115
 
116
 
117
  ### DdddOCR
118
 
119
+ **Example code**
120
 
121
  ```go
122
  package main
 
138
 
139
  engine, err := ddddocr.NewEngine(config)
140
  if err != nil {
141
+ log.Fatalf("failed to create OCR engine: %v\n", err)
142
  }
143
  defer engine.Destroy()
144
 
145
  imagePath := "./captcha_det.png"
146
  img, err := imageutil.Open(imagePath)
147
  if err != nil {
148
+ log.Fatalf("failed to load image: %v\n", err)
149
  }
150
 
151
  boxes, err := engine.Detect(img)
152
  if err != nil {
153
+ log.Fatalf("failed to run detection: %v\n", err)
154
  }
155
 
156
  tagImg := image.NewRGBA(img.Bounds())
 
164
  }
165
  ```
166
 
167
+ **Example output**
168
 
169
+ | Original image | Detection result |
170
  |-------------------------------------------------------------|-------------------------------------------------------------------|
171
  | <img width="100%" src="./examples/captcha_det.png" alt=""> | <img width="100%" src="./examples/captcha_det_result.png" alt=""> |
172
 
173
+ ## License
174
+
175
+ [MIT](./LICENSE)
docs/README_zh.md ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div align="center" style="text-align: center;">
2
+ <img src="../assets/logo.png" alt="logo" width="300" style="display: block; margin: 0 auto;" />
3
+ </div>
4
+
5
+ <p align="center">
6
+ <a href="https://github.com/getcharzp/go-ocr/fork" target="blank">
7
+ <img src="https://img.shields.io/github/forks/getcharzp/go-ocr?style=for-the-badge" alt="go-ocr forks"/>
8
+ </a>
9
+ <a href="https://github.com/getcharzp/go-ocr/stargazers" target="blank">
10
+ <img src="https://img.shields.io/github/stars/getcharzp/go-ocr?style=for-the-badge" alt="go-ocr stars"/>
11
+ </a>
12
+ <a href="https://github.com/getcharzp/go-ocr/pulls" target="blank">
13
+ <img src="https://img.shields.io/github/issues-pr/getcharzp/go-ocr?style=for-the-badge" alt="go-ocr pull-requests"/>
14
+ </a>
15
+ </p>
16
+
17
+ <p align="center">
18
+ <a href="../README.md">English</a> | 简体中文
19
+ </p>
20
+
21
+ go-ocr 是一款基于 Golang + ONNX 构建的 OCR 工具库,专注于为 Go 生态提供简单易用、可扩展的文字识别能力。
22
+ 目前已完成与 PaddleOCR、DdddOCR 的对接,支持快速实现图像文字检测与识别。
23
+
24
+ ## 安装
25
+
26
+ ### 1. 安装 Go 依赖
27
+
28
+ ```shell
29
+ go get -u github.com/getcharzp/go-ocr
30
+ ```
31
+
32
+ ### 2. 按需下载模型与动态链接库
33
+
34
+ 模型与动态链接库存放在独立仓库(HuggingFace,含 ModelScope 国内镜像),**无需全量下载**,请根据实际使用的引擎按需下载所需文件。
35
+
36
+ - HuggingFace 仓库地址:https://huggingface.co/getcharzp/go-ocr
37
+ - ModelScope 镜像地址:https://www.modelscope.cn/getcharzp/go-ocr
38
+
39
+ **动态链接库选择**
40
+
41
+ onnxruntime 动态链接库需按运行平台选择:
42
+
43
+ | 平台 | 文件 |
44
+ | --- | --- |
45
+ | Linux | `lib/onnxruntime_amd64.so` |
46
+ | Windows | `lib/onnxruntime.dll` |
47
+ | macOS | `lib/onnxruntime_amd64.dylib` |
48
+
49
+ ## 快速开始
50
+
51
+ ### PaddleOCR
52
+
53
+ **示例代码**
54
+
55
+ 通过 OCR 引擎的 `RunOCR()` 方法能直接进行完整的检测与识别,也可以通过 `RunDetect()` 仅进行文字区域检测。
56
+
57
+ ```go
58
+ package main
59
+
60
+ import (
61
+ ocr "github.com/getcharzp/go-ocr"
62
+ "github.com/getcharzp/go-ocr/paddle"
63
+ "github.com/up-zero/gotool/imageutil"
64
+ "log"
65
+ )
66
+
67
+ func main() {
68
+ // 按实际情况配置下述路径
69
+ config := paddle.Config{
70
+ OnnxRuntimeLibPath: "./lib/onnxruntime_amd64.so",
71
+ DetModelPath: "./paddle_weights/det.onnx",
72
+ RecModelPath: "./paddle_weights/rec.onnx",
73
+ DictPath: "./paddle_weights/dict.txt",
74
+ // ThreadCount: 4, // (可选) 并行识别 Session 数, 默认 1
75
+ }
76
+
77
+ // 初始化引擎(返回对象实现了 ocr.Engine 接口)
78
+ var engine ocr.Engine
79
+ engine, err := paddle.NewEngine(config)
80
+ if err != nil {
81
+ log.Fatalf("创建 OCR 引擎失败: %v\n", err)
82
+ }
83
+ defer engine.Destroy()
84
+
85
+ // 打开图像
86
+ imagePath := "./test.jpg"
87
+ img, err := imageutil.Open(imagePath)
88
+ if err != nil {
89
+ log.Fatalf("加载图像失败: %v\n", err)
90
+ }
91
+
92
+ // OCR识别
93
+ results, err := engine.RunOCR(img)
94
+ if err != nil {
95
+ log.Fatalf("运行 OCR 失败: %v\n", err)
96
+ }
97
+ for _, result := range results {
98
+ log.Printf("识别结果: %v\n", result)
99
+ }
100
+ }
101
+ ```
102
+
103
+ **示例效果**
104
+
105
+ | 原图 | 检测结果 |
106
+ |-----------------------------------------------------|----------------------------------------------------|
107
+ | <img width="100%" src="../examples/test.jpg" alt=""> | <img width="100%" src="../examples/det.jpg" alt=""> |
108
+
109
+
110
+ ### DdddOCR
111
+
112
+ **示例代码**
113
+
114
+ ```go
115
+ package main
116
+
117
+ import (
118
+ "github.com/getcharzp/go-ocr/ddddocr"
119
+ "github.com/up-zero/gotool/imageutil"
120
+ "image"
121
+ "image/color"
122
+ "image/draw"
123
+ "log"
124
+ )
125
+
126
+ func main() {
127
+ config := ddddocr.Config{
128
+ OnnxRuntimeLibPath: "../lib/onnxruntime.dll",
129
+ DetModelPath: "../ddddocr_weights/common_det.onnx",
130
+ }
131
+
132
+ engine, err := ddddocr.NewEngine(config)
133
+ if err != nil {
134
+ log.Fatalf("创建 OCR 引擎失败: %v\n", err)
135
+ }
136
+ defer engine.Destroy()
137
+
138
+ imagePath := "./captcha_det.png"
139
+ img, err := imageutil.Open(imagePath)
140
+ if err != nil {
141
+ log.Fatalf("加载图像失败: %v\n", err)
142
+ }
143
+
144
+ boxes, err := engine.Detect(img)
145
+ if err != nil {
146
+ log.Fatalf("运行检测失败: %v\n", err)
147
+ }
148
+
149
+ tagImg := image.NewRGBA(img.Bounds())
150
+ draw.Draw(tagImg, img.Bounds(), img, image.Point{}, draw.Src)
151
+
152
+ for _, box := range boxes {
153
+ imageutil.DrawThickRectOutline(tagImg, image.Rectangle{Min: image.Point{X: box.Box[0], Y: box.Box[1]},
154
+ Max: image.Point{X: box.Box[2], Y: box.Box[3]}}, color.Black, 2)
155
+ }
156
+ imageutil.Save("captcha_det_result.png", tagImg, 100)
157
+ }
158
+ ```
159
+
160
+ **示例效果**
161
+
162
+ | 原图 | 检测结果 |
163
+ |-------------------------------------------------------------|-------------------------------------------------------------------|
164
+ | <img width="100%" src="../examples/captcha_det.png" alt=""> | <img width="100%" src="../examples/captcha_det_result.png" alt=""> |
lib/onnxruntime.dll CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:dec964ab1ee36cc9b0ae247d13b376627992fc57dec0454354017ab8fd84f1ea
3
- size 14186016
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4d2774a5f64e4a230b16b74b167171e92f65b0683c19680c1d04fb284b92a6e2
3
+ size 15828832
lib/onnxruntime_amd64.so CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:126e4a0191d547839b28a41b9087375711158a3f2c5e7da65ef815f0af6cbe28
3
- size 22317880
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5a1ce74e56e8c4b278d5a9e9d12b7192d9f70811084dde9616da4fa1710efc5a
3
+ size 24301616
lib/onnxruntime_arm64.dylib CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:2b885992d3d6fa4130d39ec84a80d7504ff52750027c547bb22c86165f19406a
3
- size 33481272
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0c8707e83b3389849d03a3264308e905169b94b546f84df6bf662649bd89c3bb
3
+ size 39350024
lib/onnxruntime_arm64.so CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:0afd69a0ae38c5099fd0e8604dda398ac43dee67cd9c6394b5142b19e82528de
3
- size 17643256
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c17d9c3b522c69594ef2b077d7f27a92ff0635d9df0c68c8997b7cad7bf71c61
3
+ size 20657248