Skip to main content

Fast and accurate text detection library built on CRAFT implementation

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

craft-text-detector_updated-0.4.7.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

craft_text_detector_updated-0.4.7-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file craft-text-detector_updated-0.4.7.tar.gz.

File metadata

File hashes

Hashes for craft-text-detector_updated-0.4.7.tar.gz
Algorithm Hash digest
SHA256 e8811a7bfc70df5aa1a70ded0aaaa82acd7693eced8862dbc40273d8458ac102
MD5 5d507a024c3e4d18df1f7ae397cc1f79
BLAKE2b-256 778ae90d31219f2d8625057f9a1360978694f8e106ee30a519581c5b11fc3a62

See more details on using hashes here.

File details

Details for the file craft_text_detector_updated-0.4.7-py3-none-any.whl.

File metadata

File hashes

Hashes for craft_text_detector_updated-0.4.7-py3-none-any.whl
Algorithm Hash digest
SHA256 0b1d59a42c9e6cb421416465bc98ef34fac9bae5c767576b0a3362adad13121e
MD5 273f7b75637e017251b39f426462b23d
BLAKE2b-256 1149c489ca5d46c02989621398aa1f4fd903a88ff9fb63dcacf74f0fea29d850

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page