# CRAFT: Character-Region Awareness For Text detection
<p align="center">
<a href="https://pepy.tech/project/craft-text-detector"><img src="https://pepy.tech/badge/craft-text-detector" alt="downloads"></a>
<a href="https://pypi.org/project/craft-text-detector"><img src="https://img.shields.io/pypi/pyversions/craft-text-detector" alt="downloads"></a>
<a href="https://twitter.com/fcakyon"><img src="https://img.shields.io/twitter/follow/fcakyon?color=blue&logo=twitter&style=flat" alt="fcakyon twitter">
<br>
<a href="https://github.com/fcakyon/craft-text-detector/actions"><img alt="Build status" src="https://github.com/fcakyon/craft-text-detector/actions/workflows/ci.yml/badge.svg"></a>
<a href="https://badge.fury.io/py/craft-text-detector"><img src="https://badge.fury.io/py/craft-text-detector.svg" alt="PyPI version" height="20"></a>
<a href="https://github.com/fcakyon/craft-text-detector/blob/main/LICENSE"><img alt="License: MIT" src="https://img.shields.io/pypi/l/craft-text-detector"></a>
</p>
Packaged, Pytorch-based, easy to use, cross-platform version of the CRAFT text detector | [Paper](https://arxiv.org/abs/1904.01941) |
## Overview
PyTorch implementation for CRAFT text detector that effectively detect text area by exploring each character region and affinity between characters. The bounding box of texts are obtained by simply finding minimum bounding rectangles on binary map after thresholding character region and affinity scores.
<img width="1000" alt="teaser" src="./figures/craft_example.gif">
## Getting started
### Installation
- Install using pip:
```console
pip install craft-text-detector
```
### Basic Usage
```python
# import Craft class
from craft_text_detector import Craft
# set image path and export folder directory
image = 'figures/idcard.png' # can be filepath, PIL image or numpy array
output_dir = 'outputs/'
# create a craft instance
craft = Craft(output_dir=output_dir, crop_type="poly", cuda=False)
# apply craft text detection and export detected regions to output directory
prediction_result = craft.detect_text(image)
# unload models from ram/gpu
craft.unload_craftnet_model()
craft.unload_refinenet_model()
```
### Advanced Usage
```python
# import craft functions
from craft_text_detector import (
read_image,
load_craftnet_model,
load_refinenet_model,
get_prediction,
export_detected_regions,
export_extra_results,
empty_cuda_cache
)
# set image path and export folder directory
image = 'figures/idcard.png' # can be filepath, PIL image or numpy array
output_dir = 'outputs/'
# read image
image = read_image(image)
# load models
refine_net = load_refinenet_model(cuda=True)
craft_net = load_craftnet_model(cuda=True)
# perform prediction
prediction_result = get_prediction(
image=image,
craft_net=craft_net,
refine_net=refine_net,
text_threshold=0.7,
link_threshold=0.4,
low_text=0.4,
cuda=True,
long_size=1280
)
# export detected text regions
exported_file_paths = export_detected_regions(
image=image,
regions=prediction_result["boxes"],
output_dir=output_dir,
rectify=True
)
# export heatmap, detection points, box visualization
export_extra_results(
image=image,
regions=prediction_result["boxes"],
heatmaps=prediction_result["heatmaps"],
output_dir=output_dir
)
# unload models from gpu
empty_cuda_cache()
```
Raw data
{
"_id": null,
"home_page": "https://github.com/fcakyon/craft_text_detector",
"name": "craft-text-detector",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "machine-learning,deep-learning,ml,pytorch,text,text-detection,craft",
"author": "Fatih Cagatay Akyon",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/7d/60/474d6ebd09c6db746a49af2dee0ac48547c6df35c3eee48056193677c794/craft-text-detector-0.4.3.tar.gz",
"platform": null,
"description": "# CRAFT: Character-Region Awareness For Text detection\n\n<p align=\"center\">\n<a href=\"https://pepy.tech/project/craft-text-detector\"><img src=\"https://pepy.tech/badge/craft-text-detector\" alt=\"downloads\"></a>\n<a href=\"https://pypi.org/project/craft-text-detector\"><img src=\"https://img.shields.io/pypi/pyversions/craft-text-detector\" alt=\"downloads\"></a>\n<a href=\"https://twitter.com/fcakyon\"><img src=\"https://img.shields.io/twitter/follow/fcakyon?color=blue&logo=twitter&style=flat\" alt=\"fcakyon twitter\">\n<br>\n<a href=\"https://github.com/fcakyon/craft-text-detector/actions\"><img alt=\"Build status\" src=\"https://github.com/fcakyon/craft-text-detector/actions/workflows/ci.yml/badge.svg\"></a>\n<a href=\"https://badge.fury.io/py/craft-text-detector\"><img src=\"https://badge.fury.io/py/craft-text-detector.svg\" alt=\"PyPI version\" height=\"20\"></a>\n<a href=\"https://github.com/fcakyon/craft-text-detector/blob/main/LICENSE\"><img alt=\"License: MIT\" src=\"https://img.shields.io/pypi/l/craft-text-detector\"></a>\n</p>\n\nPackaged, Pytorch-based, easy to use, cross-platform version of the CRAFT text detector | [Paper](https://arxiv.org/abs/1904.01941) |\n\n## Overview\n\nPyTorch implementation for CRAFT text detector that effectively detect text area by exploring each character region and affinity between characters. The bounding box of texts are obtained by simply finding minimum bounding rectangles on binary map after thresholding character region and affinity scores.\n\n<img width=\"1000\" alt=\"teaser\" src=\"./figures/craft_example.gif\">\n\n## Getting started\n\n### Installation\n\n- Install using pip:\n\n```console\npip install craft-text-detector\n```\n\n### Basic Usage\n\n```python\n# import Craft class\nfrom craft_text_detector import Craft\n\n# set image path and export folder directory\nimage = 'figures/idcard.png' # can be filepath, PIL image or numpy array\noutput_dir = 'outputs/'\n\n# create a craft instance\ncraft = Craft(output_dir=output_dir, crop_type=\"poly\", cuda=False)\n\n# apply craft text detection and export detected regions to output directory\nprediction_result = craft.detect_text(image)\n\n# unload models from ram/gpu\ncraft.unload_craftnet_model()\ncraft.unload_refinenet_model()\n```\n\n### Advanced Usage\n\n```python\n# import craft functions\nfrom craft_text_detector import (\n read_image,\n load_craftnet_model,\n load_refinenet_model,\n get_prediction,\n export_detected_regions,\n export_extra_results,\n empty_cuda_cache\n)\n\n# set image path and export folder directory\nimage = 'figures/idcard.png' # can be filepath, PIL image or numpy array\noutput_dir = 'outputs/'\n\n# read image\nimage = read_image(image)\n\n# load models\nrefine_net = load_refinenet_model(cuda=True)\ncraft_net = load_craftnet_model(cuda=True)\n\n# perform prediction\nprediction_result = get_prediction(\n image=image,\n craft_net=craft_net,\n refine_net=refine_net,\n text_threshold=0.7,\n link_threshold=0.4,\n low_text=0.4,\n cuda=True,\n long_size=1280\n)\n\n# export detected text regions\nexported_file_paths = export_detected_regions(\n image=image,\n regions=prediction_result[\"boxes\"],\n output_dir=output_dir,\n rectify=True\n)\n\n# export heatmap, detection points, box visualization\nexport_extra_results(\n image=image,\n regions=prediction_result[\"boxes\"],\n heatmaps=prediction_result[\"heatmaps\"],\n output_dir=output_dir\n)\n\n# unload models from gpu\nempty_cuda_cache()\n```\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Fast and accurate text detection library built on CRAFT implementation",
"version": "0.4.3",
"project_urls": {
"Homepage": "https://github.com/fcakyon/craft_text_detector"
},
"split_keywords": [
"machine-learning",
"deep-learning",
"ml",
"pytorch",
"text",
"text-detection",
"craft"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4aa7371d03c2e9dae6b70f329efc84d6bb2d864e2c7d9d32f95ffab2d0771e6b",
"md5": "bfdccdb16e6cedde6b7f64368e74561a",
"sha256": "ea31b26eb53bc8d765f2a39d5896fa50f0b033c94a395543a5f323385c615ba5"
},
"downloads": -1,
"filename": "craft_text_detector-0.4.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bfdccdb16e6cedde6b7f64368e74561a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 18277,
"upload_time": "2022-05-09T10:55:53",
"upload_time_iso_8601": "2022-05-09T10:55:53.298580Z",
"url": "https://files.pythonhosted.org/packages/4a/a7/371d03c2e9dae6b70f329efc84d6bb2d864e2c7d9d32f95ffab2d0771e6b/craft_text_detector-0.4.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7d60474d6ebd09c6db746a49af2dee0ac48547c6df35c3eee48056193677c794",
"md5": "5cc2e339be1ece2b8bcf550cf75fcabc",
"sha256": "1fcd60a5115ebdc05c72d2a78eaae038346d89f3309f45db7ee1a69de622e1f9"
},
"downloads": -1,
"filename": "craft-text-detector-0.4.3.tar.gz",
"has_sig": false,
"md5_digest": "5cc2e339be1ece2b8bcf550cf75fcabc",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 16672,
"upload_time": "2022-05-09T10:55:55",
"upload_time_iso_8601": "2022-05-09T10:55:55.125618Z",
"url": "https://files.pythonhosted.org/packages/7d/60/474d6ebd09c6db746a49af2dee0ac48547c6df35c3eee48056193677c794/craft-text-detector-0.4.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-05-09 10:55:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "fcakyon",
"github_project": "craft_text_detector",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "torch",
"specs": [
[
">=",
"0.4.1"
]
]
},
{
"name": "torchvision",
"specs": [
[
">=",
"0.2.1"
]
]
},
{
"name": "opencv-python",
"specs": [
[
"==",
"3.4.8.29"
]
]
},
{
"name": "scipy",
"specs": [
[
">=",
"1.3.2"
]
]
},
{
"name": "gdown",
"specs": [
[
">=",
"3.10.1"
]
]
}
],
"lcname": "craft-text-detector"
}