---
title: "OCR Hindi (Devanagari) text in C#"
url: https://recursiveai.org/oneocr/cookbook/ocr-hindi-devanagari-text-csharp/
description: "Extract printed Hindi text from a PNG with the OneOcr Indic model for .NET. See the exact Devanagari output and how to inspect the words."
version: "1.2.1"
---

# OCR Hindi (Devanagari) text in C#

**OneOcr** is a free, open-source OCR library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneOcr.Models.Indic) · [GitHub](https://github.com/recursive-ai-oss/oneocr-csharp) · [Docs](https://recursiveai.org/oneocr/docs/) · [Download example (.zip)](https://recursiveai.org/oneocr/cookbook/ocr-hindi-devanagari-text-csharp/ocr-hindi-devanagari-text-csharp.zip)

```shell
dotnet add package RecursiveAI.OneOcr
dotnet add package RecursiveAI.OneOcr.Models.Indic
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OneImage;
using OneOcr;

var engine = OcrEngine.LoadBundled();
var image = Image.Load("notice.png");
Console.WriteLine(image.ToText(engine));
```

Paste the code above into Program.cs of a new `dotnet new console` project and `dotnet run`, or unzip [the example](https://recursiveai.org/oneocr/cookbook/ocr-hindi-devanagari-text-csharp/ocr-hindi-devanagari-text-csharp.zip) and `dotnet run`.

The printed text in `notice.png` (included in the zip):

```text
आज पुस्तकालय खुला है
कृपया दरवाजा बंद करें
```

What the example prints:

```text
आज पुस्तकालय खुला है	है
कृपया दरवाजा बंद करें
```

Both source lines were read, but OneOcr added a second `है` to the first line. That word is part of the OCR output, not part of the image; check the result before reusing it.

## Variations

**Inspect the script and text of each word.** Replace the last line with:

```csharp
var page = image.Ocr(engine);
foreach (var word in page.Words)
    Console.WriteLine($"{word.Script}: {word.Text}");
```

`Deva` is the script code for Devanagari. The extra word is also labeled `Deva`, so the label alone won’t filter it out.

**Filter the extra word on this sample.** Replace the print call with:

```csharp
var page = image.Ocr(engine);
foreach (var word in page.Words)
    if (word.Confidence >= 0.95f)
        Console.WriteLine(word.Text);
```

On this notice, `0.95` drops the extra word and keeps all eight source words.
Don’t assume the same cutoff will work on other images.

## Related recipes

- [Export OCR word boxes to TSV](https://recursiveai.org/oneocr/cookbook/export-ocr-word-boxes-to-tsv/)
- [Flag low-confidence OCR words](https://recursiveai.org/oneocr/cookbook/flag-low-confidence-ocr-words/)

---

## The short answer

Install `RecursiveAI.OneOcr.Models.Indic` with `RecursiveAI.OneOcr`. `OcrEngine.LoadBundled()` finds the installed model, and `image.ToText(engine)` returns the recognized Hindi as editable text. Use the Indic package even if your program only reads Hindi: the recognizer is packaged by script family, not as one model per language.

## How can I extract Hindi text from an image?

With the Indic model installed, OneOcr decides which script to read from the image by default.
For pages with separate Hindi and English lines, leave automatic script selection on so OneOcr can choose a recognizer for each line.
OneOcr 1.2.1 does not support handwriting. There’s no manual step to split the Devanagari letters or separate vowel signs before passing in the image. Use the same PNG-loading call on a scan of your own printed text. Keep the entire line in frame, including vowel signs that extend above and below the letters. A crop that cuts those pixels off gives OCR less information than the original image.

The image-to-text call is useful when you want to copy the whole notice into another document. For a form where each field has a specific location, inspect `image.Ocr(engine)` instead. The result associates words with boxes in the image. Compare a suspicious word’s box with the source rather than deleting every short word: even on this notice, `है` occurs both in the original and in the extra output.

## Is the extracted Hindi text Unicode?

Yes. The result is a .NET string containing Devanagari characters, not a picture of the line or a transliteration into Latin letters. Save it as UTF-8 if you write it to a text file, and open it with a font that supports Devanagari. Display and recognition are separate: a font can render a recognized character correctly, but it can’t restore a vowel sign the recognizer missed. When proofreading the result, compare whole words against the image, including marks attached to a letter.
