dotnet add package RecursiveAI.OneOcr dotnet add package RecursiveAI.OneOcr.Models.Arabic
Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
// RecursiveAI.OneOcr brings in OneImage. using OneImage; using OneOcr; var engine = OcrEngine.LoadBundled() .WithoutDetector(); 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 and dotnet run.
The printed text in notice.png (included in the zip):
المكتبة مفتوحة اليوم يرجى إغلاق الباب
What the example prints:
المكتبة مفتوحة اليوم يرجى إغلاق الباب
The example uses OneOcr’s built-in line finder via WithoutDetector(). On this two-line notice, the default page detector split the text and returned fragments; the built-in finder read both lines.
Try WithoutDetector() for a single block of text, such as a sign or notice;
keep the default detector for pages with columns or photos.
If an Arabic line is left unread, check that the Arabic model is installed in the app that runs the OCR, not just in a different project in the solution.
Variations
Use an Arabic language hint. Replace the last line when you know the page is Arabic:
var options = new OcrOptions { Languages = ["ar"] }; Console.WriteLine(image.ToText(engine, options));
Related recipes
The short answer
Install RecursiveAI.OneOcr and RecursiveAI.OneOcr.Models.Arabic, then call image.ToText(engine) on a PNG loaded with Image.Load. The Arabic package adds the recognizer for Arabic, Persian and Urdu. The example reads printed text and returns a C# string, not a translation.
How do you convert an Arabic image to text without uploading it?
The NuGet package places the Arabic model in oneocr-models/ beside the application. OcrEngine.LoadBundled() picks it up there, checks the model and makes it available to the local OCR engine. There’s no separate model download at runtime. If you’re moving the app to another machine, deploy the model directory with the rest of the application output.
There are two distinct steps: finding the rows of text in the image, and recognizing the characters in those rows. Switching to WithoutDetector() changes the first step, not the Arabic model. It helped on the plain notice above. For a scan with columns or photos, try the default detector first and compare the reading order and line breaks against the original. A language hint narrows the set of recognizers; it doesn’t tell the engine where the lines are. Leave it off if you want the engine to pick among the installed scripts.
Arabic text comes back in logical Unicode order: the order you would type it. Display it in a right-to-left-aware editor or UI; don’t reverse the string. The script documentation also describes how OneOcr handles left-to-right runs such as digits inside right-to-left lines. If a label contains an important number or a word distinguished by a dot, compare that field against the pixels before using the result.