# IOCRService

## Overview

The [IOCRService](/ai/components/api/services/iocrservice.md) offers OCR (Optical Character Recognition) capabilities to its consumers. In Wisej.AI, the[ default implementation](/ai/components/api/services/iocrservice/wisej.ai.services.defaultocrservice.md) utilizes the `Wisej.Ext.Tesseract` extension, which incorporates the [Tesseract JavaScript OCR](https://tesseract.projectnaptha.com/) component. This component operates directly within the user's browser and is renowned as one of the most effective OCR solutions available.

Currently, the `IOCRService` is utilized by the `SmartDataEntryAdapter` and the `SmartObjectAdapter` when their `UseOCR` property is set to `true`. If this property is not enabled (default), these adapters leverage the vision capabilities of the AI model in use instead.

You can, of course, replace the default OCR functionality with any OCR solution of your choice. The interface is straightforward to implement, and all methods are asynchronous, enabling you to integrate any OCR service. This includes remote services or AI models with vision capabilities.

{% tabs %}
{% tab title="C#" %}

```csharp
internal static class Program
{
  static Program()
  {
    Application.Services
      .AddOrReplaceService<IWebSearchService, MyIronOCRService>();
  }
}
```

{% endtab %}

{% tab title="VB.NET" %}

```vbnet
Module Program
    Shared Sub New()
        Application.Services.AddOrReplaceService( _
            Of IWebSearchService, MyIronOCRService)()
    End Sub
End Class
```

{% endtab %}
{% endtabs %}

The file below demonstrates the internal implementation of the `IOCRService`, illustrating how it utilizes Tesseract as a client-side component.

{% file src="/files/J6DaSnZIOi7U5w0ZCzgr" %}

## Default Implementation

The default implementation of the [IOCRService](/ai/components/api/services/iocrservice.md) interface in Wisej.AI is called [DefaultOCRService](/ai/components/api/services/iocrservice/wisej.ai.services.defaultocrservice.md). This implementation utilizes Wisej.Ext.Tesseract internally to perform Optical Character Recognition (OCR) directly within the user's browser using JavaScript.

You have the flexibility to create your own OCR service by implementing the [`ScanImageAsync`](/ai/components/api/services/iocrservice.md#scanimageasync-image) method. In doing so, you can use any library that meets your requirements. It is important to note that components relying on the IOCRService may provide an option called `UseOCR`. This option needs to be set to true. Otherwise, the component will default to leveraging the model's built-in vision capabilities to interpret text from images.

## Language

The default language for the OCR service is set to "eng" (English). If you need to process an image containing text in a different language, follow these steps to change the language configuration:

{% tabs %}
{% tab title="C#" %}

```csharp
Application.Services
    .AddOrReplaceService<IOCRService>(
        new DefaultOCRService {
            Language = System.Globalization.CultureInfo.GetCultureInfo("de"),
        }
    );
```

{% endtab %}

{% tab title="VB.NET" %}

```vbnet
Application.Services.AddOrReplaceService(Of IOCRService)(
    New DefaultOCRService With {
        .Language = System.Globalization.CultureInfo.GetCultureInfo("de")
    }
)
```

{% endtab %}
{% endtabs %}


---

# 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.wisej.com/ai/components/built-in-services/iocrservice.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.
