---
title: "Extracting data from images using OCR | Nutrient Python SDK"
canonical_url: "https://www.nutrient.io/guides/python/extraction/extract-data-from-image-ocr/"
md_url: "https://www.nutrient.io/guides/python/extraction/extract-data-from-image-ocr.md"
last_updated: "2026-06-09T10:32:42.848Z"
description: "Extract text from images using fast OCR with Nutrient Python SDK. Optimized for high-throughput processing and simple text-based documents."
---

# Extracting data from images using OCR

Use Adaptive OCR to extract text from images for high-throughput workflows.

Common use cases include:

- Invoice and receipt processing

- Search indexing pipelines

- Real-time text capture

- Large-scale document digitization

OCR focuses on text extraction and word-level coordinates. It doesn’t perform full semantic layout analysis like ICR.

[Download sample](https://www.nutrient.io/downloads/samples/python/extract-data-from-image-ocr.zip)

## How Nutrient helps

Nutrient Python SDK handles Adaptive OCR configuration, extraction, and JSON output.

The SDK handles:

- OCR engine and model configuration details

- Word-level bounding box calculations

- Text line detection and reading order handling

- Multi-language recognition internals

## Prerequisites

Before following this guide, ensure you have:

- Python 3.8 or higher installed

- Nutrient Python SDK installed (`pip install nutrient-sdk`)

- An image file to process (PNG, JPEG, or other supported formats)

- Basic familiarity with Python [context manager](https://docs.python.org/3/reference/datamodel.html#context-managers) and the `with` statement

For initial SDK setup and configuration, refer to the [getting started](https://www.nutrient.io/sdk/python/getting-started.md) guide.

## Complete implementation

This example extracts OCR text and writes the output as JSON:

```python

from nutrient_sdk import Document, Vision, VisionEngine

```

## Configuring Adaptive OCR mode

Open the image and set the vision engine to Adaptive OCR.

In this sample:

- The document opens in a [context manager](https://docs.python.org/3/reference/datamodel.html#context-managers).

- `document.settings.vision_settings.engine = VisionEngine.ADAPTIVE_OCR` enables Adaptive OCR mode.

- For image inputs like this sample, Adaptive OCR behaves like a fast OCR extraction pipeline.

```python

with Document.open("input_ocr_multiple_languages.png") as document:
    # Configure OCR engine for fast text extraction

    document.settings.vision_settings.engine = VisionEngine.ADAPTIVE_OCR

```

## Creating a vision instance and extracting content

Create a vision instance and call `extract_content()`.

In this sample:

- `Vision.set(document)` binds OCR extraction to the opened document.

- `extract_content()` returns OCR results as a JSON string.

- The output includes extracted text and coordinates.

```python

    vision = Vision.set(document)
    content_json = vision.extract_content()

```

Write the JSON string to a file for downstream processing.

Use this output for indexing, analytics, or storage:

```python

    with open("output.json", "w") as f:
        f.write(content_json)

```

## Understanding the output

`extract_content()` in Adaptive OCR mode returns JSON optimized for text and word-level positions.

OCR output includes:

- **Text content** — Extracted text with line structure

- **Bounding boxes** — Pixel coordinates for text regions

- **Word-level data** — Per-word positions for highlighting or targeting

- **Language detection** — May be available in OCR output depending on the content and extraction result

### Key output fields

These are the most commonly used fields in OCR JSON output:

- **`text`** — Extracted text for the element.

- **`words`** — Per-word OCR results.

- **`bounds`** — Bounding box coordinates for the element or word.

- **`confidence`** — Confidence score for the element or word.

- **`readingOrder`** — Sequence in which elements should be read.

- **`id`** — Unique identifier for the extracted element.

- **`pageNumber`** — Source page number.

- **`type` / `role`** — Semantic type of the extracted block when available.

When an element contains only one word, element-level and word-level `bounds`/`confidence` can appear identical.

Unlike ICR output, OCR output focuses on text and positions instead of semantic document structure.

## Error handling

Vision API raises `VisionException` when OCR extraction fails.

Common failure scenarios include:

- The image file can’t be read because of path or permission issues.

- Image data is corrupted or uses unsupported encoding.

- OCR models are missing or inaccessible.

- The available memory is insufficient for large images.

- The image format or resolution is unsupported.

In production code:

- Catch `VisionException`.

- Return a clear error message.

- Log failure details for debugging.

## Conclusion

Use this workflow for Adaptive OCR-based text extraction:

1. Open the image document using a [context manager](https://docs.python.org/3/reference/datamodel.html#context-managers) for automatic resource cleanup.

2. Configure the vision settings with the `engine` property assigned to `VisionEngine.ADAPTIVE_OCR` for fast text extraction.

3. For image inputs, Adaptive OCR focuses on character recognition and word extraction without semantic analysis or layout detection.

4. Create a vision instance with `Vision.set()` to bind text extraction operations to the document.

5. Call `extract_content()` to invoke the OCR engine for character recognition.

6. The OCR engine performs word detection, calculates bounding boxes, and generates JSON output with text and coordinates.

7. The method returns a JSON-formatted string containing extracted text with word-level bounding boxes in pixel coordinates.

8. OCR processing is optimized for speed, minimizing computational overhead for high-throughput scenarios.

9. Write the JSON content to a file using Python’s built-in file handling with [context manager](https://docs.python.org/3/reference/datamodel.html#context-managers) syntax.

10. Handle `VisionException` errors for robust error recovery in production environments.

11. The JSON output enables integration with search indexing (Elasticsearch, Solr), text analysis, and database storage.

12. Adaptive OCR mode is ideal for invoice processing, receipt scanning, search indexing, and document digitization where speed is critical.

For related image extraction workflows, refer to the [Python SDK guides](https://www.nutrient.io/guides/python.md).

Download [this ready-to-use sample package](https://www.nutrient.io/downloads/samples/python/extract-data-from-image-ocr.zip) to explore the Vision API capabilities with preconfigured OCR settings.
---

## Related pages

- [Speeding up first ICR operation by predownloading models](/guides/python/extraction/speed-up-first-icr-by-downloading-requirements.md)
- [Extracting text from PDF documents](/guides/python/extraction/pdf-to-text.md)
- [Extracting text from multilingual images](/guides/python/extraction/read-text-from-image-multi-language.md)
- [Extracting structured data from documents](/guides/python/extraction/extract-structured-data.md)
- [Generating image descriptions using Claude](/guides/python/extraction/describe-image-with-claude.md)
- [Extracting data from images using vision language models](/guides/python/extraction/extract-data-from-image-vlm.md)
- [Generating image descriptions using OpenAI](/guides/python/extraction/describe-image-with-openai.md)
- [Extracting text from images](/guides/python/extraction/read-text-from-image.md)
- [Generating image descriptions using local AI](/guides/python/extraction/describe-image-with-local-ai.md)
- [Nutrient Python SDK extraction guides](/guides/python/extraction.md)
- [Applying OCR to a PDF document](/guides/python/extraction/apply-ocr-to-pdf.md)
- [Extracting form fields from images](/guides/python/extraction/extract-form-fields-from-image.md)
- [Applying OCR to a PDF page](/guides/python/extraction/apply-ocr-to-pdf-page.md)
- [Labeling form fields with a vision language model](/guides/python/extraction/label-form-fields-with-vlm.md)
- [Extracting structured JSON data from PDF documents](/guides/python/extraction/json-data-extraction.md)
- [Extracting data from images using ICR](/guides/python/extraction/extract-data-from-image-icr.md)

