Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/84c0f9fd33379d21e68132bd1333b570 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/84c0f9fd33379d21e68132bd1333b570 to your computer and use it in GitHub Desktop.
Read the complete article about creating OMR sheet checker or scanner with Java by visiting the following link.
https://blog.aspose.com/2021/08/05/create-omr-sheet-checker-or-scanner-with-java/
// Source and output directory paths
String sourceDirectory = "SourceDirectory\\OMR\\Generation\\";
String outputDirectory = "OutputDirectory\\";
// Create an instance of the OmrEngine class
OmrEngine engine = new OmrEngine();
// Generate template using the text markup
GenerationResult res = engine.generateTemplate(sourceDirectory + "Grid.txt");
// Check in case of errors
if (res.getErrorCode() != 0)
{
System.out.println("ERROR CODE: " + res.getErrorCode());
}
// Save the generation result: image and .omr template
res.save(outputDirectory, "Grid");
// Source and output directory paths
String sourceDirectory = "SourceDirectory\\OMR\\";
String outputDirectory = "OutputDirectory\\";
String TemplateName = "Sheet.omr";
String[] UserImages = new String[] { "Sheet1.jpg", "Sheet2.jpg" };
String[] UserImagesNoExt = new String[] { "Sheet1", "Sheet2" };
// Create an instance of the OmrEngine class
OmrEngine engine = new OmrEngine();
// Load the template file
TemplateProcessor templateProcessor = engine.getTemplateProcessor(sourceDirectory + "Sheet.omr");
System.out.println("Template loaded.");
// Loop through the images
for (int i = 0; i < UserImages.length; i++) {
// Recognize image and receive result
RecognitionResult result = templateProcessor.recognizeImage(sourceDirectory + UserImages[i]);
// Export results as csv string
String csvResult = result.getCsv();
// Save csv to the output folder
PrintWriter wr = new PrintWriter(new FileOutputStream(outputDirectory + UserImagesNoExt[i] + ".csv"), true);
wr.println(csvResult);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment