# IOCRService

Namespace: **Wisej.AI.Services**

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

Represents an OCR (Optical Character Recognition) service that can scan images and extract text using a specified language.

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

```csharp
public interface IOCRService : IDisposable
```

{% endtab %}

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

```visual-basic
Public Interface IOCRService
    Inherits IDisposable
```

{% endtab %}
{% endtabs %}

This interface defines methods for extracting text from images using OCR technology. Implementations of this interface should provide functionality to handle image input in various formats and return the recognized text. The service is also disposable to ensure any system resources are correctly released.

## Properties

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

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

This property allows the user to specify the language in which the text is expected to be recognized. Setting the correct language can improve the accuracy of the OCR process.

## Methods

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

Asynchronously scans the provided image and extracts text from it.

| Parameter | Type                                                                | Description                                                                             |
| --------- | ------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
| **image** | [Image](https://docs.microsoft.com/dotnet/api/system.drawing.image) | The image from which text is to be extracted. Ensure the image is valid and accessible. |

**Returns:** [Task\<String>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task that represents the asynchronous operation. The task result contains the text extracted from the image.

This method processes the given image using OCR techniques to extract and return text data. The method is asynchronous and will not block the calling thread.\
Example usage:

```csharp

  IOCRService ocrService = GetOCRService();
  Image image = Image.FromFile("sample.jpg");
  string result = await ocrService.ScanImageAsync(image);
  Console.WriteLine(result);

```

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

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

Scans an image from a specified URL to extract text content asynchronously.

| Parameter    | Type                                                          | Description                                                                             |
| ------------ | ------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
| **imageUrl** | [String](https://docs.microsoft.com/dotnet/api/system.string) | The URL of the image to scan. This parameter is required and must not be null or empty. |

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

This method performs an OCR scan on an image located at the specified URL and returns the recognized text. The operation is performed asynchronously, allowing other tasks to execute while the scan is in progress.\
The URL should directly point to an image file accessible over the network. It supports data base64 URLs.\
Example usage:

```csharp

  var ocrService = new YourOCRServiceImplementation();
  string imageUrl = "http://example.com/image.jpg";
  string extractedText = await ocrService.ScanImageAsync(imageUrl);
  Console.WriteLine(extractedText);

```

**Throws:**

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

## Implemented By

| Name                                                                                                | Description                                                                                                                                                             |
| --------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [DefaultOCRService](/ai/components/api/services/iocrservice/wisej.ai.services.defaultocrservice.md) | Represents a default implementation of the [IOCRService](/ai/components/api/services/iocrservice.md) interface using Tesseract for Optical Character Recognition (OCR). |


---

# 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/api/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.
