|
13 | 13 |
|
14 | 14 | - **2024.11.15**
|
15 | 15 | - 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 | + |
17 | 19 | ### Introduction
|
18 | 20 |
|
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) |
20 | 25 |
|
21 |
| -### Online Experience |
| 26 | +### Online Demo |
22 | 27 | [modelscope](https://www.modelscope.cn/studios/jockerK/DocUnwrap) [huggingface](https://huggingface.co/spaces/Joker1212/RapidUnwrap)
|
23 | 28 |
|
24 |
| -### Effect Demonstration |
25 |
| - |
| 29 | +### Effect Showcase |
| 30 | + |
| 31 | + |
26 | 32 |
|
27 | 33 | ### Installation
|
28 | 34 | ``` python {linenos=table}
|
29 |
| -pip install rapid-unwrap |
| 35 | +pip install rapid-undistorted |
30 | 36 | ```
|
31 | 37 |
|
32 | 38 | ### Quick Start
|
33 | 39 |
|
34 | 40 | ``` python {linenos=table}
|
35 | 41 | import cv2
|
36 | 42 |
|
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"]) |
41 | 54 | 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. |
43 | 62 |
|
| 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) |
44 | 70 | ```
|
| 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 |
45 | 104 |
|
| 105 | +``` |
| 106 | +#### Execution Parameters |
| 107 | +```python |
| 108 | +engine(img_path, task_list) |
| 109 | +engine(img_path, ["unwrap", "unshadow", ("unblur", "OpenCvBilateral")]) |
| 110 | +``` |
46 | 111 |
|
47 | 112 | ### Acknowledgments
|
48 | 113 |
|
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 | + |
50 | 119 |
|
51 | 120 |
|
52 | 121 | ### Contribution Guidelines
|
|
0 commit comments