Skip to main content

CRAFT: Character-Region Awareness For Text detection

downloads downloads fcakyon twitter
Build status PyPI version License: MIT

Packaged, Pytorch-based, easy to use, cross-platform version of the CRAFT text detector | Paper |

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.

teaser

Getting started

Installation

  • Install using pip:
pip install craft-text-detector-updated

Basic Usage

# 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

# 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()

Metadata

Release files for craft-text-detector-updated 0.4.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for craft-text-detector-updated 0.4.7
File Size Uploaded
craft-text-detector_updated-0.4.7.tar.gz 19.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for craft-text-detector-updated 0.4.7
File Interpreter ABI Platform
craft_text_detector_updated-0.4.7-py3-none-any.whl Python 3 none any Details

Total release size: 38.6 kB

Release files / craft-text-detector_updated-0.4.7.tar.gz

Download URL craft-text-detector_updated-0.4.7.tar.gz
Size 19.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e8811a7bfc70df5aa1a70ded0aaaa82acd7693eced8862dbc40273d8458ac102
BLAKE2b-256 checksum
How to use checksums
778ae90d31219f2d8625057f9a1360978694f8e106ee30a519581c5b11fc3a62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.1

Release files / craft_text_detector_updated-0.4.7-py3-none-any.whl

Download URL craft_text_detector_updated-0.4.7-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0b1d59a42c9e6cb421416465bc98ef34fac9bae5c767576b0a3362adad13121e
BLAKE2b-256 checksum
How to use checksums
1149c489ca5d46c02989621398aa1f4fd903a88ff9fb63dcacf74f0fea29d850
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.1

Release history Release notifications | RSS feed

This release

0.4.7 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page