Show / Hide Table of Contents

Class OneOcrService

OneOCR engine implementation of IOCRService using P/Invoke into the native oneocr.dll (Windows 11 SnippingTool OCR engine). No WinRT, no Windows App SDK, no package identity required. Pass engine settings directly to CreateSessionAsync(IReadOnlyDictionary<string, object>, CancellationToken).

Inheritance
object
OneOcrService
Implements
IOCRService
IDisposable
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Zaya.OCR.Impl.OneOcr
Assembly: Zaya.OCR.Impl.OneOcr.dll
Syntax
public sealed class OneOcrService : IOCRService, IDisposable
Remarks

EngineId is oneocr. Settings are exposed via Settings as SettingDescriptor instances for UI hosts, and accepted as a string-keyed dictionary by CreateSessionAsync(IReadOnlyDictionary<string, object>, CancellationToken). Use OneOcrConfig for a typed alternative.

Setting keys

KeyTypeDefaultDescription
sourceenum stringauto Where to load engine files from. Values: auto (SnippingTool, then URL fallback), snippingtool, directory, url.
directoryPathdirectory path(none) Local folder with oneocr.dll, onnxruntime.dll, and oneocr.onemodel. Required when source is directory.
downloadUrlURLGitHub Zaya.External OneOCR.zip release Package URL used when source is url, and as fallback when source is auto.
cacheDirectorydirectory path%TEMP%\Zaya\OneOcr Writable cache for copied/extracted engine files (auto, snippingtool, url). Hosts such as ScreenTranslator may override this key.
minConfidenceinteger 0–10070Minimum word confidence (percent). Words below the threshold are dropped.

Example:

using var ocr = new OneOcrService();
using var session = await ocr.CreateSessionAsync(new Dictionary<string, object>
{
    ["source"] = "auto",
    ["minConfidence"] = 50,
});
var result = await session.RecognizeAsync(image);

Constructors

| Edit this page View Source

OneOcrService()

Initializes a new instance using Zaya.Logging.Services.EmptyLoggingWrapper.Instance.

Declaration
public OneOcrService()
| Edit this page View Source

OneOcrService(ILoggingWrapper)

Initializes a new instance with the specified logging wrapper.

Declaration
public OneOcrService(ILoggingWrapper loggingWrapper)
Parameters
Type Name Description
ILoggingWrapper loggingWrapper

Logging wrapper used when creating sessions.

Properties

| Edit this page View Source

Description

Gets the UI description for this engine (localized).

Declaration
public LocalizedString Description { get; }
Property Value
Type Description
LocalizedString
| Edit this page View Source

DisplayName

Gets the UI display name for this engine (localized).

Declaration
public LocalizedString DisplayName { get; }
Property Value
Type Description
LocalizedString
| Edit this page View Source

EngineId

Gets a unique identifier for this OCR engine (e.g., "oneocr", "tesseract"). Used for profile serialization and engine lookup.

Declaration
public string EngineId { get; }
Property Value
Type Description
string
| Edit this page View Source

IsAvailable

Gets whether this OCR engine is available on the current system.

Declaration
public bool IsAvailable { get; }
Property Value
Type Description
bool
| Edit this page View Source

PreferredPixelFormat

Gets the pixel format preferred by this OCR engine. The caller (e.g., a screenshot module) can use this to deliver pixels in the optimal format without extra conversion.

Declaration
public PixelFormat PreferredPixelFormat { get; }
Property Value
Type Description
PixelFormat
| Edit this page View Source

Settings

Gets the engine-specific settings declared by OneOCR (source, directoryPath, downloadUrl, cacheDirectory, minConfidence).

Declaration
public IReadOnlyList<SettingDescriptor> Settings { get; }
Property Value
Type Description
IReadOnlyList<SettingDescriptor>
Remarks

See the type-level remarks on OneOcrService for key names, defaults, and visibility rules.

Methods

| Edit this page View Source

CreateSessionAsync(IReadOnlyDictionary<string, object>, CancellationToken)

Creates a new OCR session with the specified engine settings.

Declaration
public Task<IOCRSession> CreateSessionAsync(IReadOnlyDictionary<string, object> settings, CancellationToken cancellationToken = default)
Parameters
Type Name Description
IReadOnlyDictionary<string, object> settings

Dictionary of setting keys (see type-level remarks). Missing keys use descriptor defaults.

CancellationToken cancellationToken

Token to cancel session creation (e.g. while downloading).

Returns
Type Description
Task<IOCRSession>

An active OCR session ready to recognize text.

| Edit this page View Source

CreateSessionAsync(CancellationToken)

Creates a new OCR session with the default engine settings.

Declaration
public Task<IOCRSession> CreateSessionAsync(CancellationToken cancellationToken = default)
Parameters
Type Name Description
CancellationToken cancellationToken

Token to cancel session creation.

Returns
Type Description
Task<IOCRSession>

An active OCR session ready to recognize text.

| Edit this page View Source

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
public void Dispose()

Implements

IOCRService
IDisposable
  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX