How to Work with the OMR Model in Python
A RecognitionResult holds one IOmrElement per recognized question. This guide shows how to read and export recognized answers.
Step-by-Step Guide
Step 1: Install the Package
git clone https://github.com/aspose-omr-foss/Aspose.OMR-FOSS-for-Python.git
cd Aspose.OMR-FOSS-for-Python
pip install -e .python -c "import omr; print('Aspose.OMR FOSS for Python is ready.')"Step 2: Import Required Classes
from omr.api import OmrEngine, FormValidationLogicStep 3: Recognize a Scan
engine = OmrEngine()
processor = engine.GetTemplateProcessor("out/final-exam.omr", FormValidationLogic.Ignore)
result = processor.Recognize("scan.png")Step 4: Read Individual Answers
Each entry in result.OmrElements implements IOmrElement: QuestionName identifies the question, and GetAnswer() returns its recognized value (an empty string if nothing passed the recognition threshold).
for element in result.OmrElements:
print(element.QuestionName, element.GetAnswer())Step 5: Export the Whole Result
print(result.GetCsv()) # also GetJson() / GetXml()Common Issues and Fixes
GetAnswer() returns an empty string for a mark I can clearly see on the scan. The recognition threshold may be too strict for that mark’s darkness. Pass -100 to Recognize() for auto-calibration, or call Recalculate() with a looser threshold on the existing result.
I need the raw answer data in a format other than CSV/JSON/XML. Iterate result.OmrElements yourself and build whatever structure you need from each IOmrElement’s GetAnswer()/GetCsv().
Frequently Asked Questions
Does Recalculate() re-read the scanned image?
No — it re-scores the already-recognized result in place with a new threshold.
What does QuestionName correspond to?
The Name you set on the template element (e.g. AnswerSheetConfig.Name or ChoiceBoxConfig.Name) that element’s mark was recognized against.
Can I export only some elements instead of the whole result?
RecognitionResult’s export methods cover the full result; filter OmrElements yourself first if you need a subset.