Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created August 25, 2020 21:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/f08b8b0277fe563d616a807aefce753d to your computer and use it in GitHub Desktop.
Save aspose-com-gists/f08b8b0277fe563d616a807aefce753d to your computer and use it in GitHub Desktop.
C# Create OMR Question and Answer Sheet Checker or Scanner Software
// initialize OMR engine
OmrEngine engine = new OmrEngine();
// call template generation providing path to the txt file with markup
GenerationResult res = engine.GenerateTemplate(Path.Combine(testFolderPath, "Grid.txt"));
// check in case of errors
if (res.ErrorCode != 0)
{
Console.WriteLine("ERROR CODE: " + res.ErrorCode);
}
// you can use either of the following approaches
// save generation result: PDF and .omr template
res.SaveAsPdf(testFolderPath , "Grid");
// save generation result: image and .omr template
res.Save(testFolderPath, "Grid");
string TemplateName = @"Sheet.omr";
string[] UserImages = new string[] { "Sheet1.jpg" };
// input and output preparation
string testFolderPath = dataDir;
string templatePath = Path.Combine(testFolderPath, TemplateName);
// actual OMR API calls
OmrEngine engine = new OmrEngine();
TemplateProcessor templateProcessor = engine.GetTemplateProcessor(templatePath);
Console.WriteLine("Template loaded.");
for (int i = 0; i < UserImages.Length; i++)
{
string imagePath = Path.Combine(testFolderPath, UserImages[i]);
string csvResult = templateProcessor.RecognizeImage(imagePath).GetCsv();
File.WriteAllText(Path.Combine(outputPath, Path.GetFileNameWithoutExtension(UserImages[i]) + ".csv"), csvResult);
Console.WriteLine("Result exported. Path: " + Path.Combine(testFolderPath, Path.GetFileNameWithoutExtension(UserImages[i]) + ".csv"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment