Starshot.OneOcr 0.2.0

dotnet add package Starshot.OneOcr --version 0.2.0
                    
NuGet\Install-Package Starshot.OneOcr -Version 0.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Starshot.OneOcr" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Starshot.OneOcr" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Starshot.OneOcr" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Starshot.OneOcr --version 0.2.0
                    
#r "nuget: Starshot.OneOcr, 0.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Starshot.OneOcr@0.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Starshot.OneOcr&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Starshot.OneOcr&version=0.2.0
                    
Install as a Cake Tool

Starshot.OneOcr

C# bindings for OneOCR — the OCR engine embedded in the Windows Photos app and Snipping Tool. Falls back to the system engine (Windows.Media.Ocr) when OneOCR is unavailable, and squashes the extra spaces that both engines insert between CJK characters.

This package does NOT contain the engine itself. OneOCR is a Microsoft proprietary component; you must obtain the two files yourself and place them next to your app exe:

  • oneocr.dll (~39 MB)
  • oneocr.onemodel (~56 MB, encrypted — the decryption key is included in this library)

Where to get them: copy from the local Windows Snipping Tool package (%ProgramFiles%\WindowsApps\Microsoft.ScreenSketch_*\SnippingTool\) or the Photos app package root, via Windows.Management.Deployment.PackageManager. Redistribution of these files is your own responsibility.

Requirements

  • .NET 10, net10.0-windows10.0.26100.0 (Windows App SDK projection)
  • Win2D 1.3.2+ (any compatible build)
  • Serilog (used for engine logging)

Quick start

using Starshot.OneOcr;

// 1) On the UI thread (GPU readback must stay on the device's thread):
var (pixels, width, height, scale) = OcrHelper.PreparePixels(canvasBitmap);

// 2) Any thread — oneocr first, Windows.Media.Ocr fallback:
var result = await OcrHelper.RecognizeAsync(pixels, width, height, scale);

if (result is null)
{
    // no engine available at all (files missing AND no OCR language pack)
}
else if (result.Lines.Count == 0)
{
    // recognized nothing
}
else
{
    Console.WriteLine($"engine: {result.Engine}");  // OneOcr or Legacy (incl. fallback)
    foreach (var line in result.Lines)
    {
        Console.WriteLine(line.Text);          // full-line text, spaces already squashed
        foreach (var word in line.Words)
        {
            // word.Text + word.Rect (original-image pixel coordinates)
        }
    }
}

Pass preferOneOcr: false to RecognizeAsync to skip OneOCR and use the system engine directly.

API surface

Member Purpose
OcrHelper.PreparePixels(CanvasBitmap) GPU: any pixel format → BGRA8 bytes (HDR float sources converted without tonemap). Must run on the UI thread.
OcrHelper.RecognizeAsync(bytes, w, h, scale, preferOneOcr) CPU-only recognition, thread-pool safe. Returns OcrResult (lines + which engine actually ran), null = no engine. Coordinates are original-image pixels.
OcrHelper.IsOneOcrReady File-existence check for the two engine files.
OcrHelper.ResetEngineCache() Call after fetching/replacing/deleting engine files so init is retried.
OcrHelper.JoinWords(words) Word-sequence joining for text selection (Latin gets spaces, CJK doesn't).
OcrLine / OcrWord Result records: text + original-image pixel rect.
OcrResult / OcrEngineUsed Recognition result wrapper: lines + the engine that actually ran (OneOcr, or Legacy including fallback).

Notes

  • OneOCR failures (missing or corrupt engine files, runtime errors) automatically fall back to the system engine; check OcrResult.Engine to see which engine actually processed the image.
  • The OneOCR pipeline is created lazily on first use and cached for the process lifetime; RunOcrPipeline calls are serialized with a lock (thread safety of the native engine is unknown).
  • Both engines' line text is token-space-joined; SquashCjkSpaces removes spaces only when neither neighbor is a Latin letter/digit — CJK gets glued, English keeps its spaces.
  • Coordinates from oversized inputs (legacy engine MaxImageDimension limit) are pre-scaled on the GPU and multiplied back so both engines return original-image pixels.
Product Compatible and additional computed target framework versions.
.NET net10.0-windows10.0.26100 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.0 90 9/1/2026
0.1.0 85 9/1/2026