https://github.com/swhl/mergetextboxes
Merge text boxes in the same row or column.
https://github.com/swhl/mergetextboxes
text-detection
Last synced: about 1 year ago
JSON representation
Merge text boxes in the same row or column.
- Host: GitHub
- URL: https://github.com/swhl/mergetextboxes
- Owner: SWHL
- License: apache-2.0
- Created: 2024-02-23T01:47:11.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-23T14:00:42.000Z (about 2 years ago)
- Last Synced: 2024-04-23T15:26:44.489Z (about 2 years ago)
- Topics: text-detection
- Language: Python
- Homepage:
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### Introduction
This repo is mainly used to merge peer text boxes. The code is modified from the [merge_text_boxs](https://github.com/zcswdt/merge_text_boxs) project and further organized and expanded.
### Installation
```bash
pip install merge_text_boxes
```
### Usage
```python
import copy
import cv2
import numpy as np
from merge_text_boxes import MergeTextBoxes
rects = [
[144, 5, 192, 25],
[25, 6, 64, 25],
[66, 6, 141, 25],
[193, 5, 275, 33],
[269, 30, 354, 50],
[26, 30, 182, 52],
[185, 28, 265, 55],
[25, 56, 89, 76],
[93, 56, 229, 78],
[232, 56, 262, 76],
[264, 52, 343, 81],
]
show_image = np.zeros([100, 500, 3], np.uint8) + 255
connector = MergeTextBoxes(max_dist=15, overlap_threshold=0.2)
new_rects = connector(rects, 500)
tmp_img = copy.deepcopy(show_image)
for rect in rects:
cv2.rectangle(tmp_img, (rect[0], rect[1]), (rect[2], rect[3]), (0, 0, 255), 1)
cv2.imwrite("origin.png", tmp_img)
for rect in new_rects:
cv2.rectangle(show_image, (rect[0], rect[1]), (rect[2], rect[3]), (255, 0, 0), 1)
cv2.imwrite("res.png", show_image)
```
### Visualization
Before merging:

After merging:

### Acknowledgements
- [OCR文字检测框的合并](https://blog.csdn.net/jhsignal/article/details/107840145)
- [merge_text_boxs](https://github.com/zcswdt/merge_text_boxs)
### Contributing
Pull requests are welcome. For major changes, please open an issue first
to discuss what you would like to change.
Please make sure to update tests as appropriate.
### [Sponsor](https://rapidai.github.io/RapidOCRDocs/docs/sponsor/)
If you want to sponsor the project, you can directly click the **Buy me a coffee** image, please write a note (e.g. your github account name) to facilitate adding to the sponsorship list below.
### License
This project is released under the [Apache 2.0 license](../LICENSE).
