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
<PackageReference Include="CodexIT.OmrKit.Core" Version="5.0.0" />
<PackageVersion Include="CodexIT.OmrKit.Core" Version="5.0.0" />
<PackageReference Include="CodexIT.OmrKit.Core" />
paket add CodexIT.OmrKit.Core --version 5.0.0
#r "nuget: CodexIT.OmrKit.Core, 5.0.0"
#:package CodexIT.OmrKit.Core@5.0.0
#addin nuget:?package=CodexIT.OmrKit.Core&version=5.0.0
#tool nuget:?package=CodexIT.OmrKit.Core&version=5.0.0
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.Abstractionsfor 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:
IOmrKitwithScanAnswerSheets(multi-file / multi-page PDF) andScanAnswerKeyTemplate. - Breaking:
GenerateSheet(TestSheetSpec)removed — useAnswerSheetSpecortestSheetSpec.ToAnswerSheetSpec(). - See: CHANGELOG.md for release details.
Migration Notes (v4.0.0)
- Breaking:
QuestionTypenumeric values changed.QuestionType.MultipleChoice = 1QuestionType.TrueFalse = 2
- Breaking: legacy
OMRKITHMAC licenses are rejected. Licenses now use the asymmetricOMRKIT2format 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
7are rejected until the installed library explicitly supports them. - Supported historical geometry is fixed by schema version:
- v1:
classic-ltr-v1orclassic-rtl-v1 - v2-v4:
compact-ltr-v2orcompact-rtl-v2 - v5:
compact-ltr-v3orcompact-rtl-v3 - v6-v7:
compact-ltr-v4orcompact-rtl-v4
- v1:
- 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
tokeninstead ofpaperIdonly when its value is a valid, non-empty GUID. New v7 payloads always encodepaperId.
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.
Recommended scan API (IOmrKit)
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.winandOpenCvSharp4.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 readsMaxDecodedPixels,MaxImageWidth,MaxImageHeightMaxQrPayloadLengthMaxBatchPagesMaxLogoBytes
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 limitsquality_gate_rejected: scan image quality is too lowalignment_failed: sheet markers/alignment faileddecode_error: unsupported or corrupted uploadconfiguration_error: runtime configuration/engine registration/license issueengine_error: selected engine failed during detectionpayload_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 | Versions 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. |
-
net10.0
- CodexIT.OmrKit.Abstractions (>= 5.0.0)
- Docnet.Core (>= 2.6.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- OpenCvSharp4 (>= 4.13.0.20260627)
- OpenCvSharp4.official.runtime.linux-x64.slim (>= 4.13.0.20260627)
- OpenCvSharp4.runtime.win (>= 4.13.0.20260627)
- QRCoder (>= 1.8.0)
- QuestPDF (>= 2026.8.0)
-
net8.0
- CodexIT.OmrKit.Abstractions (>= 5.0.0)
- Docnet.Core (>= 2.6.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- OpenCvSharp4 (>= 4.13.0.20260627)
- OpenCvSharp4.official.runtime.linux-x64.slim (>= 4.13.0.20260627)
- OpenCvSharp4.runtime.win (>= 4.13.0.20260627)
- QRCoder (>= 1.8.0)
- QuestPDF (>= 2026.8.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
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.