recognize method

recognize

Performs OCR processing on an image.

def recognize(self, context):
    ...
Parameter Type Description
context OcrContext The OCR processing context.

Returns: The recognized text.

Example

import io

from groupdocs.search.options import IndexingOptions

try:
    import pytesseract  # pip install pytesseract
    from PIL import Image  # pip install pillow
except ImportError:
    pytesseract = None


class TesseractOcrConnector(object):
    def recognize(self, context):
        image = context.image_stream.read()  # Read the whole image stream
        if pytesseract is None:
            print("pytesseract is not installed: an image of %d bytes is not recognized" % len(image))
            return None
        with Image.open(io.BytesIO(image)) as picture:
            return pytesseract.image_to_string(picture)


options = IndexingOptions()
options.ocr_indexing_options.enabled_for_separate_images = True
options.ocr_indexing_options.ocr_connector = TesseractOcrConnector()

Aliases

These names call recognize too, limited to the overloads listed.

Alias Accepts
recognize_ocr_context recognize_ocr_context(context)

See Also