> For the complete documentation index, see [llms.txt](https://docs.wisej.com/ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wisej.com/ai/components/api/services/iocrservice/wisej.ai.services.defaultocrservice.md).

# DefaultOCRService

Namespace: **Wisej.AI.Services**

Assembly: **Wisej.AI** (3.5.0.0)

Represents a default implementation of the [IOCRService](/ai/components/api/services/iocrservice.md) interface using Tesseract for Optical Character Recognition (OCR).

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

```csharp
public class DefaultOCRService : IOCRService, IDisposable
```

{% endtab %}

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

```visual-basic
Public Class DefaultOCRService
    Inherits IOCRService
    Implements IDisposable
```

{% endtab %}
{% endtabs %}

## Constructors

### ![](/files/ptrKjmmRoQB76pvrIqh0) DefaultOCRService()

Initializes a new instance of the [DefaultOCRService](/ai/components/api/services/iocrservice/wisej.ai.services.defaultocrservice.md) class.

## Properties

### ![](/files/ptrKjmmRoQB76pvrIqh0) Language

[CultureInfo](https://docs.microsoft.com/dotnet/api/system.globalization.cultureinfo): Gets or sets the language used for OCR processing.

The language should be specified as a [CultureInfo](https://docs.microsoft.com/dotnet/api/system.globalization.cultureinfo) object. If the language is not set, the default language used is English ("eng").

## Methods

### ![](/files/ptrKjmmRoQB76pvrIqh0) Dispose()

Releases all resources used by the [DefaultOCRService](/ai/components/api/services/iocrservice/wisej.ai.services.defaultocrservice.md).

This method should be called when the service is no longer needed to free up resources.

### ![](/files/ptrKjmmRoQB76pvrIqh0) ScanImageAsync(image)

Scans an image and performs OCR to extract text from it.

| Parameter | Type                                                                | Description                                                                                                                                 |
| --------- | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| **image** | [Image](https://docs.microsoft.com/dotnet/api/system.drawing.image) | The image to be scanned. It should be a valid [Image](https://docs.microsoft.com/dotnet/api/system.drawing.image) object. Defaults to null. |

**Returns:** [Task\<String>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A [Task](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task) representing the asynchronous operation, with the recognized text as the result.

This method performs OCR on the provided image using the specified language set in the [Language](#language) property. If the language is not set, English is used by default.\
Example usage:

```csharp

DefaultOCRService ocrService = new DefaultOCRService
{
Language = new CultureInfo("eng")
};
Image image = Image.FromFile("sample.png");
string text = await ocrService.ScanImageAsync(image);
Console.WriteLine(text);

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown if the *image* parameter is null.

### ![](/files/ptrKjmmRoQB76pvrIqh0) ScanImageAsync(imageUrl)

Asynchronously scans an image from a URL and returns the recognized text.

| Parameter    | Type                                                          | Description                                                                              |
| ------------ | ------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **imageUrl** | [String](https://docs.microsoft.com/dotnet/api/system.string) | The URL of the image to be scanned for text recognition. This parameter is not optional. |

**Returns:** [Task\<String>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task representing the asynchronous operation, with the recognized text as the result.

This method retrieves an image from the provided URL and utilizes the Tesseract OCR engine to recognize text. The language used for OCR is specified by the [Language](#language) property.\
Example usage:

```csharp

var ocrService = new DefaultOCRService();
ocrService.Language = new CultureInfo("eng");
string recognizedText = await ocrService.ScanImageAsync("http://example.com/image.jpg");
Console.WriteLine(recognizedText);

```

**Throws:**

* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception)\
  Thrown when *imageUrl* is null or empty.

## Implements

| Name                                                      | Description                                                                                                                 |
| --------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| [IOCRService](/ai/components/api/services/iocrservice.md) | Represents an OCR (Optical Character Recognition) service that can scan images and extract text using a specified language. |


---

# 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, and the optional `goal` query parameter:

```
GET https://docs.wisej.com/ai/components/api/services/iocrservice/wisej.ai.services.defaultocrservice.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
