CodexIT.OmrKit.Core 5.0.0

dotnet add package CodexIT.OmrKit.Core --version 5.0.0
                    
NuGet\Install-Package CodexIT.OmrKit.Core -Version 5.0.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="CodexIT.OmrKit.Core" Version="5.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CodexIT.OmrKit.Core" Version="5.0.0" />
                    
Directory.Packages.props
<PackageReference Include="CodexIT.OmrKit.Core" />
                    
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 CodexIT.OmrKit.Core --version 5.0.0
                    
#r "nuget: CodexIT.OmrKit.Core, 5.0.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 CodexIT.OmrKit.Core@5.0.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=CodexIT.OmrKit.Core&version=5.0.0
                    
Install as a Cake Addin
#tool nuget:?package=CodexIT.OmrKit.Core&version=5.0.0
                    
Install as a Cake Tool

CodexIT.OmrKit.Core

Core runtime for answer-sheet generation and OMR scanning.

NuGet package ID: CodexIT.OmrKit.Core
C# namespace remains Codex.OmrKit.Core.

Package Boundary

This is the production runtime package.

  • Owns layout, rendering, QR payload behavior, alignment, and bubble detection.
  • Depends on CodexIT.OmrKit.Abstractions for stable contracts.
  • Is independent from API/UI hosts.

Install

dotnet add package CodexIT.OmrKit.Core --version 5.0.0

This also pulls CodexIT.OmrKit.Abstractions.

License

This package requires a permanent OMRKIT2 LicenseKey.
To request a license, contact WhatsApp: 00218917128473 (open chat).

Issue keys with tools/Codex.OmrKit.LicenseIssuer. The NuGet runtime verifies licenses only; it does not ship the private signing key.

Consumer prerequisites

Requirement Notes
OMRKIT2 LicenseKey Required for generation and licensed scan entry points (IOmrKit, GenerateSheet, Scan, etc.).
QuestPDF PDF generation uses QuestPDF with LicenseType.Community inside this library. Confirm QuestPDF licensing for your organization and revenue before production.
OpenCvSharp runtimes Package references include OpenCvSharp4.runtime.win and OpenCvSharp4.official.runtime.linux-x64.slim for bubble detection and alignment.
.NET Targets net8.0 and net10.0.

Migration Notes (v5.0.0)

  • Added: GenerateAnswerKeyTemplate, ScanAnswerKeyTemplate → TemplateScanResult.
  • Added: IOmrKit with ScanAnswerSheets (multi-file / multi-page PDF) and ScanAnswerKeyTemplate.
  • Breaking: GenerateSheet(TestSheetSpec) removed — use AnswerSheetSpec or testSheetSpec.ToAnswerSheetSpec().
  • See: CHANGELOG.md for release details.

Migration Notes (v4.0.0)

  • Breaking: QuestionType numeric values changed.
    • QuestionType.MultipleChoice = 1
    • QuestionType.TrueFalse = 2
  • Breaking: legacy OMRKIT HMAC licenses are rejected. Licenses now use the asymmetric OMRKIT2 format and must be issued with the private issuer tool.

QR compatibility policy

  • Minimum readable QR schema: 1 (QrPayloadCodec.MinimumSupportedVersion).
  • Current and only emitted QR schema: 7 (QrPayloadCodec.CurrentVersion).
  • Future versions above 7 are rejected until the installed library explicitly supports them.
  • Supported historical geometry is fixed by schema version:
    • v1: classic-ltr-v1 or classic-rtl-v1
    • v2-v4: compact-ltr-v2 or compact-rtl-v2
    • v5: compact-ltr-v3 or compact-rtl-v3
    • v6-v7: compact-ltr-v4 or compact-rtl-v4
  • Layout identifiers are never guessed or replaced with the current layout. Unknown identifiers, version/layout mismatches, and language/direction contradictions are rejected.
  • Legacy v1-v6 payloads may use token instead of paperId only when its value is a valid, non-empty GUID. New v7 payloads always encode paperId.

DI Registration

services.AddCodexOmrKit(options =>
{
    configuration.GetSection("CodexOmrKit").Bind(options);
});

SmartSchool appsettings.json:

{
  "CodexOmrKit": {
    "LicenseKey": "OMRKIT2....",
    "DefaultLanguage": "Arabic",
    "DefaultEngine": "OpenCvOtsu",
    "IncludeVisualPreview": true,
    "MaxUploadBytes": 26214400,
    "MaxDecodedPixels": 40000000,
    "MaxImageWidth": 10000,
    "MaxImageHeight": 14000,
    "MaxQrPayloadLength": 4096,
    "MaxBatchPages": 500,
    "MaxLogoBytes": 5242880
  }
}

Paste a license issued by the product owner into LicenseKey. The runtime package and sample API can only verify licenses; they do not contain the private signing key and cannot issue licenses. GenerateSheet, licensed scan methods, and IOmrKit scan entry points fail with configuration_error until a valid key is configured. Validate, DecodeQrPayload, and Prepare are intentional unlicensed pre-checks so hosts can inspect quality/QR before a license-gated scan.

For external apps (for example SmartSchool), inject IOmrKit and use two operations. Each runs quality validation, alignment/rotation, QR decode, and bubble detection internally.

Method Purpose
ScanAnswerSheets(uploads, engineKind?) One or more JPG/PNG/PDF uploads; every PDF page becomes one scan. Returns OmrAnswerSheetScanBatch.
ScanAnswerKeyTemplate(upload, engineKind?) Single teacher template (image or PDF). Returns TemplateScanResult.

Async wrappers: ScanAnswerSheetsAsync, ScanAnswerKeyTemplateAsync.

IOmrKit omrKit = serviceProvider.GetRequiredService<IOmrKit>();

// Multiple files and/or multi-page PDF (class scan export)
OmrAnswerSheetScanBatch batch = omrKit.ScanAnswerSheets([pdfBytes, photoBytes]);
foreach (OmrAnswerSheetScanItem item in batch.Items)
{
    Guid paperId = item.Result.PaperId;
    // grade using paperId
}

TemplateScanResult template = omrKit.ScanAnswerKeyTemplate(templateUpload);

IOmrScanService remains available for fine-grained flows (Prepare then ScanPrepared, quality-only checks, engine experiments). New integrations should prefer IOmrKit.

Expanded page count is limited by MaxBatchPages (same option as generation batches).

If you build a standalone console/service host, also reference Microsoft.Extensions.DependencyInjection to call BuildServiceProvider(). ASP.NET hosts already provide it.

Platform support

  • Image scanning (JPG/PNG) works on Windows and Linux x64.
  • PDF first-page scanning works on Windows and Linux via Docnet/PDFium + OpenCvSharp PNG encoding.
  • The Core package ships OpenCvSharp4.runtime.win and OpenCvSharp4.official.runtime.linux-x64.slim.
  • Linux containers can stay headless; the slim OpenCV runtime does not require GTK.

Resource limits

Reject oversized inputs before heavy OpenCV work:

  • MaxUploadBytes / stream reads
  • MaxDecodedPixels, MaxImageWidth, MaxImageHeight
  • MaxQrPayloadLength
  • MaxBatchPages
  • MaxLogoBytes

Set IncludeVisualPreview to false for high-volume scanning to skip JPEG preview generation.

Async wrappers (ScanAsync, GenerateSheetAsync, stream overloads) accept CancellationToken and run the existing pipeline on the thread pool.

Exception Mapping for SmartSchool

Catch OmrKitException and map behavior by ex.Code:

  • validation_error: invalid test/question input or resource limits
  • quality_gate_rejected: scan image quality is too low
  • alignment_failed: sheet markers/alignment failed
  • decode_error: unsupported or corrupted upload
  • configuration_error: runtime configuration/engine registration/license issue
  • engine_error: selected engine failed during detection
  • payload_error: invalid QR payload contract

See docs/error-catalog.md for stable MessageKey values.

try
{
    // Paper ID, language, counts, schema version, and layout come from the QR.
    var scan = scanService.Scan(fileBytes);
}
catch (OmrKitException ex)
{
    logger.LogWarning("OMR error {Code} key={Key} stage={Stage}", ex.Code, ex.MessageKey, ex.Context?.Stage);
    throw;
}

Single-engine scanning

Each scan executes exactly one engine. Pass the engine explicitly when the caller has made a selection:

var result = scanService.Scan(fileBytes, OmrEngineKind.OpenCvAdaptiveMean);

ScanEngineResult selectedEngineResult = result.EngineResult;

Calling Scan(fileBytes) executes only the configured DefaultEngine. Other registered engines remain available but are not executed.

Fill-based detection scores

The retained Confidence name is for API compatibility. It is a unitless, normalized ink-fill score from 0.0 (no detected ink in the measured bubble area) to 1.0 (fully detected ink coverage), not a probability that an answer is correct. Each OptionConfidence.Value has the same 0.0 to 1.0 fill-score semantics.

MarkedBubble.ConfidencePercentage is that fill score expressed in percent units from 0 to 100 and rounded to two decimal places. Engine values are clamped before they are returned through the public scan contracts.

ScannedQuestion question = result.EngineResult.Questions[0];
double fillScore = question.Confidence;                    // 0.0 to 1.0
double optionFillScore = question.OptionConfidences[0].Value; // 0.0 to 1.0
double fillPercent = result.MarkedBubbles[0].ConfidencePercentage; // 0 to 100

Sheet generation

GenerateAnswerKeyTemplate / GenerateAnswerKeyTemplateAsync create a one-page blank teacher key sheet. They accept language, multipleChoiceCount, and trueFalseCount, encode the reserved template PaperId (AnswerKeyTemplate.ReservedPaperId) in QR schema v7, and must not be used for student batches. Scan shaded templates with ScanAnswerKeyTemplate (returns TemplateScanResult); student scans (Scan / ScanPrepared) reject the reserved id. TemplateScanResult uses effective question counts (highest filled number per type) and two lists (MultipleChoiceAnswers, TrueFalseAnswers); gaps before the last filled mark are not filled.

Hosts must never assign AnswerKeyTemplate.ReservedPaperId to student papers.

GenerateSheet / GenerateSheetAsync create one PDF for one or many pages. Every student registration under every form becomes one page, and the result includes a page manifest. For a single page, build AnswerSheetSpec with one form and one student, or convert a TestSheetSpec via ToAnswerSheetSpec().

var request = new AnswerSheetSpec(
    "Mathematics",
    institution,
    [
        new AnswerSheetFormSpec(
            "A",
            multipleChoiceQuestions,
            trueFalseQuestions,
            [new AnswerSheetStudentSpec(student, paperId, PaperLanguage.English)])
    ]);

GeneratedAnswerSheetBatch generated = sheetGenerator.GenerateSheet(request);
byte[] pdf = generated.PdfBytes;

The consuming application creates every non-empty paperId. The request requires at least one form and one student per form. Form codes, paper IDs, and student assignments are validated before PDF rendering begins; form codes are printed but are not encoded in QR payloads.

Scanning returns PaperId and sheet geometry metadata only. The consuming application uses PaperId to resolve its registration/form and answer key before grading. Core does not decode, compare, or infer a form code, and form code never affects bubble geometry.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
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
5.0.0 82 11/22/2026
4.0.0 148 9/27/2026
3.0.0 114 9/21/2026
2.0.0 117 9/16/2026

5.0.0 - Answer-key template and consumer scan API.
- GenerateAnswerKeyTemplate / GenerateAnswerKeyTemplateAsync for blank teacher key sheets (reserved PaperId).
- ScanAnswerKeyTemplate returns TemplateScanResult with effective MC/TF counts and gap-filled answer lists.
- IOmrKit: ScanAnswerSheets (multi-image and multi-page PDF batch) and ScanAnswerKeyTemplate.
- Breaking: removed IAnswerSheetGenerator.GenerateSheet(TestSheetSpec); use AnswerSheetSpec or TestSheetSpec.ToAnswerSheetSpec().
- Requires OMRKIT2 LicenseKey. QuestPDF Community license is set by the library; verify QuestPDF terms for your deployment scale.
- Ships OpenCvSharp Windows and linux-x64.slim native runtimes (see README). See CHANGELOG.md for full history.