# OCR

This function block extracts printed or handwritten text from an image and returns both visual and textual results. It is designed for easy use: supply an image, adjust sensitivity, and enable auto-rotation or text overlay as needed.

## 📥 Inputs <a href="#inputs" id="inputs"></a>

`Image` This input socket accepts the image you want to read text from.

## 📤 Outputs <a href="#outputs" id="outputs"></a>

`Result` Annotated image with detected text boxes drawn (if an output viewer is connected).

`Whole Text` Concatenated detected text as a single string.

`Texts` List of detected text strings (multiple outputs possible).

`Boxes` Detected bounding boxes for each text instance (coordinates).

## 🕹️ Controls <a href="#controls" id="controls"></a>

`Auto Rotation` Toggle to allow the block to try reading rotated or upside-down text.

`Show Texts` Toggle to draw recognized text and confidence on the annotated image.

`Threshold` Slider to control minimum confidence required for a detection to be accepted (lower = more results, higher = fewer but more reliable results).

## 🎯 Features <a href="#features" id="features"></a>

* Real-time text extraction from images fed into the block.
* Option to auto-rotate input images so upside-down or rotated text can be read.
* Confidence threshold to filter out low-confidence recognitions.
* Visual output with bounding boxes and optional text overlay for quick verification.
* Provides both structured outputs (list of texts and boxes) and a single concatenated text output for easy downstream use.

## ⚙️ How it runs <a href="#running-mechanism" id="running-mechanism"></a>

When an image is provided to the input socket, the block runs the OCR process and returns:

* an annotated image on `Result` (if any output is connected),
* the full recognized text on `Whole Text`,
* individual detected strings on `Texts`,
* and bounding box coordinates on `Boxes`.

Use `Auto Rotation` to improve detection on rotated images. Use `Threshold` to exclude low-confidence results.

## 📝 Usage Instructions <a href="#usage" id="usage"></a>

1. Connect an image source to `Image` (e.g., camera or image loader).
2. Toggle `Auto Rotation` if your images may be rotated.
3. Set the `Threshold` slider to balance recall vs. precision.
4. Enable `Show Texts` if you want the annotated image to display recognized strings.
5. Read outputs from `Whole Text`, `Texts`, and `Boxes` for logging or downstream processing.

## 💡 Tips and Tricks <a href="#tips-and-tricks" id="tips-and-tricks"></a>

* For clearer OCR results, preprocess the image with `Contrast Optimization` and `Blur` to reduce noise and improve character contrast.
* If you only need to focus on a specific area, crop first using `Image ROI Select` then feed the cropped image into this block.
* When working with very large images, use `Image Resizer` to reduce size before OCR to speed up processing.
* Use `Show Image` to preview the annotated output quickly during development.
* If you prefer a different OCR engine or need an alternative approach, try `OCR (EasyOCR)` and compare results.
* Save recognized frames and logs with `Image Logger` for offline review or audit trails.

(hint: combine these blocks in your flow to improve detection quality and performance: `Image ROI Select`, `Image Resizer`, `Contrast Optimization`, `Blur`, `Show Image`, `Image Logger`, `OCR (EasyOCR)`.)

## 🛠️ Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

* If no text is detected, check that the input image contains legible text and try increasing contrast or lowering the `Threshold` value.
* If results are noisy (many false positives), raise the `Threshold` to filter low-confidence detections.
* For rotated or upside-down text, enable `Auto Rotation` before increasing threshold.
* If annotated image is not appearing, connect a viewer or use `Show Image` to ensure the visual output is routed.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.augelab.com/function-blocks/ai-blocks/ocr.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
