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 QuestionName to match a recognized element back to the question it came from, rather than relying on list order.
  • Use the ...AsStream export variants (GetCsvAsStream, GetJsonAsStream, GetXmlAsStream) when writing results to a non-filesystem destination.
  • TemplateProcessor.Recalculate() updates an existing RecognitionResult in place — re-read OmrElements afterward rather than keeping references from before the recalculation.

Common Issues

IssueCauseFix
An element’s answer is an empty stringThe recognition threshold was too strict for that mark, or Recalculate() was called with an impossibly strict valueLower 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/MethodDescription
RecognitionResult.OmrElementsList of recognized IOmrElement entries
RecognitionResult.GetCsv / GetJson / GetXmlExport the full result
IOmrElement.GetAnswer / GetCsvPer-element recognized value

See Also