Created
August 25, 2020 21:47
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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