Skip to content

Commit 714b019

Browse files
committed
chore: update readme
1 parent 95b5ed6 commit 714b019

File tree

6 files changed

+157
-24
lines changed

6 files changed

+157
-24
lines changed

README.md

+75-11
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,107 @@
1515

1616
- **2024.11.15**
1717
- 完成初版代码,转换 [UVDoc](https://github.com/tanguymagne/UVDoc) 模型为onnx,完善前后处理
18+
- **2024.12.15**
19+
- 补充去模糊/去阴影/二值化的功能和模型,重新升级为 RapidUndistort
1820

1921

2022
### 简介
2123

22-
本仓库用于进行文档扭曲的修正,同时能一定程度缓解透视和旋转问题
23-
24+
本仓库用于进行文档扭曲的修正/文档去模糊/文档去阴影/文档二值化等问题 \
25+
提供多种模型和自由组合选择task,支持模型自动下载 \
26+
原始pytorch模型来源参考 [致谢](#致谢) \
27+
[快速使用](#快速使用) [使用建议](#使用建议) [参数说明](#参数说明) [模型地址](https://www.modelscope.cn/studios/jockerK/DocUnwrap/files)
2428

2529
### 在线体验
2630
[modelscope](https://www.modelscope.cn/studios/jockerK/DocUnwrap) [huggingface](https://huggingface.co/spaces/Joker1212/RapidUnwrap)
2731
### 效果展示
28-
![res_show.jpg](preview.jpg)
32+
![res_show.jpg](preview1.gif)
33+
![res_show1.jpg](preview2.gif)
2934

3035
### 安装
3136
``` python {linenos=table}
3237
# 建议使用清华源安装 https://pypi.tuna.tsinghua.edu.cn/simple
33-
pip install rapid-unwrap
38+
pip install rapid-undistorted
3439
```
3540

3641
### 快速使用
3742

3843
``` python {linenos=table}
3944
import cv2
4045

41-
from rapid_unwrap.inference import DocUnwrapper
42-
img_path = "img/demo4.jpg"
43-
doc_unwrapper = DocUnwrapper(img_path)
44-
unwrapped_img, elapse = doc_unwrapper(img_path)
46+
from rapid_undistorted.inference import InferenceEngine
47+
img_path = "img/demo.jpg"
48+
engine = InferenceEngine()
49+
# 扭曲修正->去阴影->去模糊 (指定去模糊模型)
50+
output_img, elapse = engine(img_path, ["unwrap", "unshadow", ("unblur", "OpenCvBilateral")])
51+
# 去阴影->去模糊 (指定去模糊模型)
52+
#output_img, elapse = engine(img_path, ["unshadow", ("unblur", "OpenCvBilateral")])
53+
# 默认选择yaml配置文件中第一个unblur模型
54+
#output_img, elapse = engine(img_path, ["unshadow", "unblur"])
55+
# 二值化替代去阴影方法
56+
#output_img, elapse = engine(img_path, ["unwrap", "binarize", "unblur"])
4557
print(f"doc unwrap elapse:{elapse}")
46-
cv2.imwrite("unwarped.png", unwrapped_img)
58+
cv2.imwrite("result.png", output_img)
4759

4860
```
4961

62+
### 使用建议
63+
- 英文及数字去模糊 NAFDPM 模型更好,但中文直接使用opencv方法更佳
64+
- 去阴影模型相对于二值化功能更丰富,效果更好,不建议直接使用二值化方法
65+
66+
67+
### 参数说明
68+
#### 初始化参数
69+
支持传入一个config配置文件,声明需要的task类型和对应的模型,以及path
70+
config_path = "configs/config.yaml"
71+
engine = InferenceEngine(config_path)
72+
```yaml
73+
tasks:
74+
unwrap:
75+
models:
76+
- type: "UVDoc"
77+
path:
78+
use_cuda: false
79+
80+
unshadow:
81+
models:
82+
- type: "GCDnet"
83+
sub_models:
84+
- type: "GCDnet"
85+
path:
86+
use_cuda: false
87+
use_dml: false
88+
- type: "DRnet"
89+
path:
90+
use_cuda: false
91+
92+
binarize:
93+
models:
94+
- type: "UnetCnn"
95+
path:
96+
use_cuda: false
97+
98+
unblur:
99+
models:
100+
- type: "OpenCvBilateral"
101+
path:
102+
- type: "NAFDPM"
103+
path:
104+
use_cuda: false
50105

51-
### 致谢
106+
```
107+
#### 执行参数
108+
```python
109+
engine(img_path, task_list)
110+
engine(img_path, ["unwrap", "unshadow", ("unblur", "OpenCvBilateral")])
111+
```
52112

53-
[UVDoc](https://github.com/tanguymagne/UVDoc)
113+
### 致谢
54114

115+
unwrap: [UVDoc](https://github.com/tanguymagne/UVDoc)
116+
unshadow: [GCDnet](https://github.com/ZZZHANG-jx/GCDRNet)
117+
unblur: [NAFDPM](https://github.com/ispamm/NAF-DPM)
118+
binarize: [UnetCnn](https://github.com/sajjanvsl/U-Net-CNN-for-binarization-of-Historical-Kannada-Handwritten-Palm-Leaf-Manuscripts)
55119

56120
### 贡献指南
57121

README_en.md

+81-12
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,109 @@
1313

1414
- **2024.11.15**
1515
- Completed the initial version of the code, converted the [UVDoc](https://github.com/tanguymagne/UVDoc) model to onnx, and improved pre- and post-processing.
16-
16+
- **2024.12.15**
17+
- Added deblurring/shadow removal/binarization functions and models, upgraded to RapidUndistort.
18+
1719
### Introduction
1820

19-
This repository is used for correcting document distortions and can also alleviate perspective and rotation issues to some extent.
21+
This repository is used for correcting document distortion, deblurring documents, shadow removal, and document binarization.
22+
It provides multiple models and flexible task combinations, supports automatic model downloading.
23+
Original PyTorch model sources can be found in the [Acknowledgments](#acknowledgments) section.
24+
[Quick Start](#quick-start) [Usage Suggestions](#usage-suggestions) [Parameter Explanation](#parameter-explanation) [Model Address](https://www.modelscope.cn/studios/jockerK/DocUnwrap/files)
2025

21-
### Online Experience
26+
### Online Demo
2227
[modelscope](https://www.modelscope.cn/studios/jockerK/DocUnwrap) [huggingface](https://huggingface.co/spaces/Joker1212/RapidUnwrap)
2328

24-
### Effect Demonstration
25-
![res_show.jpg](preview.jpg)
29+
### Effect Showcase
30+
![res_show.jpg](preview1.gif)
31+
![res_show1.jpg](preview2.gif)
2632

2733
### Installation
2834
``` python {linenos=table}
29-
pip install rapid-unwrap
35+
pip install rapid-undistorted
3036
```
3137

3238
### Quick Start
3339

3440
``` python {linenos=table}
3541
import cv2
3642

37-
from rapid_unwrap.inference import DocUnwrapper
38-
img_path = "img/demo4.jpg"
39-
doc_unwrapper = DocUnwrapper(img_path)
40-
unwrapped_img, elapse = doc_unwrapper(img_path)
43+
from rapid_undistorted.inference import InferenceEngine
44+
img_path = "img/demo.jpg"
45+
engine = InferenceEngine()
46+
# Distortion correction -> Shadow removal -> Deblurring (specify deblurring model)
47+
output_img, elapse = engine(img_path, ["unwrap", "unshadow", ("unblur", "OpenCvBilateral")])
48+
# Shadow removal -> Deblurring (specify deblurring model)
49+
#output_img, elapse = engine(img_path, ["unshadow", ("unblur", "OpenCvBilateral")])
50+
# Default selection of the first unblur model in the yaml configuration file
51+
#output_img, elapse = engine(img_path, ["unshadow", "unblur"])
52+
# Binarization as an alternative to shadow removal method
53+
#output_img, elapse = engine(img_path, ["unwrap", "binarize", "unblur"])
4154
print(f"doc unwrap elapse:{elapse}")
42-
cv2.imwrite("unwarped.png", unwrapped_img)
55+
cv2.imwrite("result.png", output_img)
56+
57+
```
58+
59+
### Usage Suggestions
60+
- For English and numeric deblurring, the NAFDPM model is better, but for Chinese text, using the OpenCV method is more suitable.
61+
- The shadow removal model has richer functionality and better results compared to binarization, so it is not recommended to directly use the binarization method.
4362

63+
64+
### Parameter Explanation
65+
#### Initialization Parameters
66+
Supports passing a config configuration file to declare the required task types and corresponding models, as well as paths.
67+
```python
68+
config_path = "configs/config.yaml"
69+
engine = InferenceEngine(config_path)
4470
```
71+
```yaml
72+
tasks:
73+
unwrap:
74+
models:
75+
- type: "UVDoc"
76+
path:
77+
use_cuda: false
78+
79+
unshadow:
80+
models:
81+
- type: "GCDnet"
82+
sub_models:
83+
- type: "GCDnet"
84+
path:
85+
use_cuda: false
86+
use_dml: false
87+
- type: "DRnet"
88+
path:
89+
use_cuda: false
90+
91+
binarize:
92+
models:
93+
- type: "UnetCnn"
94+
path:
95+
use_cuda: false
96+
97+
unblur:
98+
models:
99+
- type: "OpenCvBilateral"
100+
path:
101+
- type: "NAFDPM"
102+
path:
103+
use_cuda: false
45104

105+
```
106+
#### Execution Parameters
107+
```python
108+
engine(img_path, task_list)
109+
engine(img_path, ["unwrap", "unshadow", ("unblur", "OpenCvBilateral")])
110+
```
46111

47112
### Acknowledgments
48113

49-
[UVDoc](https://github.com/tanguymagne/UVDoc)
114+
unwrap: [UVDoc](https://github.com/tanguymagne/UVDoc)
115+
unshadow: [GCDnet](https://github.com/ZZZHANG-jx/GCDRNet)
116+
unblur: [NAFDPM](https://github.com/ispamm/NAF-DPM)
117+
binarize: [UnetCnn](https://github.com/sajjanvsl/U-Net-CNN-for-binarization-of-Historical-Kannada-Handwritten-Palm-Leaf-Manuscripts)
118+
50119

51120

52121
### Contribution Guidelines

preview.jpg

-73.9 KB
Binary file not shown.

preview1.gif

901 KB
Loading

preview2.gif

1.05 MB
Loading

rapid_undistorted/unwrap_predictor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(self, config):
1717
def __call__(self, img):
1818
s = time.time()
1919
size = img.shape[:2][::-1]
20-
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB).astype(np.float32) / 255
20+
img = img.astype(np.float32) / 255
2121
inp = self.preprocess(img.copy())
2222
outputs, _ = self.session([inp])
2323
elapse = time.time() - s

0 commit comments

Comments
 (0)