> For the complete documentation index, see [llms.txt](https://assetstore.easymlkit.voxelbusters.com/tutorials/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://assetstore.easymlkit.voxelbusters.com/tutorials/features/text-recognizer.md).

# Text Recognizer

The ML Kit Text Recognition API can recognize text in any Latin-based character set. It can also be used to automate data-entry tasks such as processing credit cards, receipts, and business cards.The ML Kit Text Recognition API can recognize text in any Latin-based character set. It can also be used to automate data-entry tasks such as processing credit cards, receipts, and business cards.

* **Recognize text across Latin-based languages** Supports recognizing text using Latin script
* **Analyze structure of text** Supports detection of words/elements, lines and paragraphs
* **Identify language of text** Identifies the language of the recognized text
* **Real-time recognition** Can recognize text in real-time on a wide range of devices

> Import VoxelBusters.EasyMLKit and VoxelBusters.CoreLibrary namespaces

```csharp
using VoxelBusters.EasyMLKit;
using VoxelBusters.CoreLibrary;
```

#### Create Instance

Create an instance of the **TextRecognizer** instance.

```csharp
private TextRecognizer CreateTextRecognizer()
{
    TextRecognizer scanner = new TextRecognizer();   
    return scanner;
}
```

#### Prepare

For preparing, you need to pass an instance to input source, instance of **TextRecognizerOptions** and a callback to know when prepare is complete.

```csharp
private IInputSource CreateImageInputSource(Texture2D texture)
{
    return new ImageInputSource(texture);
}

private IInputSource CreateLiveCameraInputSource()
{
    IInputSource inputSource = new LiveCameraInputSource()
    {
        EnableFlash = false,
        IsFrontFacing = false
    };

    return inputSource;
}

private TextRecognizerOptions CreateTextRecognizerOptions()
{
    TextRecognizerOptions.Builder builder = new TextRecognizerOptions.Builder();
    builder.SetInputLanguage(TextRecognizerInputLanguage.Latin); //TextRecognizerInputLanguage.Japanese or TextRecognizerInputLanguage.Korean
    return builder.Build();
}

private void Prepare()
{
    IInputSource inputSource = CreateImageInputSource(TEXTURE);//TEXTURE -> "Readable" Texture 2D instance
    TextRecognizerOptions options = CreateTextRecognizerOptions();
    Debug.Log("Starting prepare...");
    scanner.Prepare(inputSource, options, OnPrepareComplete);
}

private void OnPrepareComplete(TextRecognizer scanner, Error error)
{
        Debug.Log("Prepare complete..." + error);
        if (error == null)
        {
            Debug.Log("Prepare completed successfully!");
        }
        else
        {
            Debug.Log("Failed preparing Text recognizer : " + error.Description);
        }
}
```

#### Process

Once prepare is complete, you can start processing which gives the result in a callback.

```csharp
private void OnPrepareComplete(TextRecognizer scanner, Error error)
{
        Debug.Log("Prepare complete..." + error);
        if (error == null)
        {
            Debug.Log("Prepare completed successfully!");
            scanner.Process(OnProcessUpdate);
        }
        else
        {
            Debug.Log("Failed preparing Text Recognizer : " + error.Description);
        }
}

private void OnProcessUpdate(TextRecognizer scanner, TextRecognizerResult result)
{
    if (!result.HasError())
    {
        Debug.Log(string.Format("Received {0}", result.TextGroup));

        if(result.TextGroup != null)
        {
            scanner.Close(null);
        }
    }
    else
    {
        Debug.Log("Text Recognizer failed processing : " + result.Error.Description, false);
    }
});
```

#### Close

Close the scanner once you are done processing.

```csharp
scanner.Close(null);//Or pass a callback to know once its complete
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://assetstore.easymlkit.voxelbusters.com/tutorials/features/text-recognizer.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.
