The Recognition Model
The Recognition Model
omr.model defines the shape of a recognition result: RecognitionResult and the IOmrElement interface.
RecognitionResult
TemplateProcessor.Recognize() returns a RecognitionResult. It exposes OmrElements (a list of recognized elements), plus ImagePath, Images, PageName, and TemplateName. At the result level, GetCsv(encoding), GetJson(encoding), and GetXml(encoding) export the whole result; each has a matching ...AsStream variant returning a BytesIO.
from omr.api import OmrEngine, FormValidationLogic
engine = OmrEngine()
processor = engine.GetTemplateProcessor("out/final-exam.omr", FormValidationLogic.Ignore)
result = processor.Recognize("scan.png")
print(result.GetJson())IOmrElement
Each entry in RecognitionResult.OmrElements implements IOmrElement: QuestionName and SortWeight identify the element, and GetAnswer() / GetCsv() read its recognized value.
for element in result.OmrElements:
print(element.QuestionName, element.GetAnswer())Tips and Best Practices
- Read
QuestionNameto match a recognized element back to the question it came from, rather than relying on list order. - Use the
...AsStreamexport variants (GetCsvAsStream,GetJsonAsStream,GetXmlAsStream) when writing results to a non-filesystem destination. TemplateProcessor.Recalculate()updates an existingRecognitionResultin place — re-readOmrElementsafterward rather than keeping references from before the recalculation.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
| An element’s answer is an empty string | The recognition threshold was too strict for that mark, or Recalculate() was called with an impossibly strict value | Lower the threshold, or pass -100 to Recognize() for auto-calibration |
FAQ
What does GetAnswer() return for an unmarked question?
An empty string — the same representation Recalculate() produces when a stricter threshold rejects every mark.
Can I export only some elements instead of the whole result?
RecognitionResult’s GetCsv/GetJson/GetXml export the full result; filter OmrElements yourself first if you need a subset.
API Reference Summary
| Class/Method | Description |
|---|---|
RecognitionResult.OmrElements | List of recognized IOmrElement entries |
RecognitionResult.GetCsv / GetJson / GetXml | Export the full result |
IOmrElement.GetAnswer / GetCsv | Per-element recognized value |