CRAFT: Character-Region Awareness For Text detection
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.
Getting started
Installation
pip install craft-text-detector
Basic Usage
from craft_text_detector import Craft
image = 'figures/idcard.png'
output_dir = 'outputs/'
craft = Craft(output_dir=output_dir, crop_type="poly", cuda=False)
prediction_result = craft.detect_text(image)
craft.unload_craftnet_model()
craft.unload_refinenet_model()
Advanced Usage
from craft_text_detector import (
read_image,
load_craftnet_model,
load_refinenet_model,
get_prediction,
export_detected_regions,
export_extra_results,
empty_cuda_cache
)
image = 'figures/idcard.png'
output_dir = 'outputs/'
image = read_image(image)
refine_net = load_refinenet_model(cuda=True)
craft_net = load_craftnet_model(cuda=True)
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
)
exported_file_paths = export_detected_regions(
image=image,
regions=prediction_result["boxes"],
output_dir=output_dir,
rectify=True
)
export_extra_results(
image=image,
regions=prediction_result["boxes"],
heatmaps=prediction_result["heatmaps"],
output_dir=output_dir
)
empty_cuda_cache()