mittagessen / kraken

OCR engine for all the languages
http://kraken.re
Apache License 2.0
746 stars 131 forks source link

How to get OCR using API #213

Closed rathorology closed 3 years ago

rathorology commented 4 years ago

$ kraken -i image.tif image.txt binarize segment ocr

How can I do this in python script using Kraken API

rathorology commented 4 years ago

from kraken.lib.models import load_any from kraken import rpred, binarization from PIL import Image

img = Image.open("path_of_image")

## ---Binarization of image--- genrator_image = Image.fromarray(img) genrator_image = binarization.nlbin(genrator_image)

## ---Loading Kraken Model---download model and provide path here) model = load_any("en-default.mlmodel")

x,y,w,h should be determined and feed here to extract text from specific ROI.**

cord = [x, y, x + w, y + h] bound = {'boxes': [tuple(cord)], 'text_direction': 'horizontal-lr'}

## Using Kraken API generator = rpred.rpred(network=model, im=genrator_image, bounds=bound) nxt_gen = next(generator) text = nxt_gen.prediction

alem-memic commented 3 years ago

I think this should be written in README.md

mittagessen commented 3 years ago

The API docs now include a tutorial style documentation for the 3.0 release.