We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Generate OMR Template with Images using JSON Markdown

Does anyone have a JSON example for generating an Aspose.OMR template for a test that mixes small images with text for the Questions and multiple choice Answers?
Is this possible with the Aspose.OMR API?
Thanks, Mike

@mcard

Please check the following JSON Markdown example to generate OMR Template with images:

In case you are still unable to achieve your requirements, please share your expected output files so that we can investigate and share our feedback with you accordingly.

I am writing down all the OMR related templates with JSON Markdown -
[Generate-OMR-Template-Java.java]

String outputDirectory = “GenerationResult”;
String[] GenerationMarkups = new String[] { “Sheet.txt”, “Grid.txt”, “AsposeTest.txt” };
String[] GenerationMarkupsNoExt = new String[] { “Sheet”, “Grid”, “AsposeTest” };
OmrEngine engine = new OmrEngine();
for (int i = 0; i < GenerationMarkups.length; i++)
{
// call template generation providing path to the txt file with markup
GenerationResult res = engine.generateTemplate(GenerationMarkups[i]);
// check in case of errors
if (res.getErrorCode() != 0)
{
System.out.println("ERROR CODE: " + res.getErrorCode());
}
// save generation result: image and .omr template
res.save(outputDirectory, GenerationMarkupsNoExt[i]);
}

[Raw]

[OMR-in-Images-Recalculation-using-Java.java]

String[] UserImages = new String[] { “Sheet1.jpg”, “Sheet2.jpg” };
String[] UserImagesNoExt = new String[] { “Sheet1”, “Sheet2” };
String outputDirectory = “Result”;
String templatePath = “Sheet.omr”;
// init engine and get template processor
OmrEngine engine = new OmrEngine();
TemplateProcessor templateProcessor = engine.getTemplateProcessor(templatePath);
System.out.println(“Template loaded.”);
// Set custom threshold to use in recalculation
// this value is in range (0 to 100)
// represents the percentage of required black pixels on bubble image to be recognized
// i.e. the lower the value - the less black pixels required for bubble to be counted as filled and vice versa
int CustomThreshold = 40;
// images loop
for (int i = 0; i < UserImages.length; i++)
{
String image = UserImages[i];
String imagePath = image;
System.out.println("Processing image: " + imagePath);
// recognize image
RecognitionResult result = templateProcessor.recognizeImage(imagePath);
// get export csv string
String stringRes = result.getCsv();
// save csv to output folder
String outputName = UserImagesNoExt[i] + “.csv”;
PrintWriter wr = new PrintWriter(new FileOutputStream(outputName), true);
wr.println(stringRes);
System.out.println("Export done. Path: " + outputName);
// recalculate recognition results with custom threshold
templateProcessor.recalculate(result, CustomThreshold);
// get export csv string
stringRes = result.getCsv();
// save recalculated results
outputName = UserImagesNoExt[i] + “_recalculated.csv”;
wr = new PrintWriter(new FileOutputStream(outputName), true);
wr.println(stringRes);
System.out.println("Recalculated result export done. Path: " + outputName);
System.out.println();
}

Basically, I have to migrate this JSON on my project remote onboarding software and related things.
[Raw]

[OMR-in-Images-Threshold-using-Java.java]

String[] UserImages = new String[] { “Sheet1.jpg”, “Sheet2.jpg” };
String[] UserImagesNoExt = new String[] { “Sheet1”, “Sheet2” };
String outputDirectory = “Result”;
String templatePath = “Sheet.omr”;
int customThreshold = 40;
// initialize engine and get template processor providing path to the .omr file
OmrEngine engine = new OmrEngine();
TemplateProcessor templateProcessor = engine.getTemplateProcessor(templatePath);
System.out.println(“Template loaded.”);
// images loop
for (int i = 0; i < UserImages.length; i++) {
// path to the image to be recognized
String imagePath = UserImages[i];
System.out.println("Processing image: " + imagePath);
// recognize image and receive result
RecognitionResult result = templateProcessor.recognizeImage(imagePath, customThreshold);
// export results as csv string
String csvResult = result.getCsv();
String json = result.getJson();
// save csv to the output folder
PrintWriter wr = new PrintWriter(new FileOutputStream(UserImagesNoExt[i] + “.csv”), true);
wr.println(csvResult);
}

[Raw]

[OMR-in-Images-using-Java.java]

String[] UserImages = new String[] { “Sheet1.jpg”, “Sheet2.jpg” };
String[] UserImagesNoExt = new String[] { “Sheet1”, “Sheet2” };
String outputDirectory = “Result”;
String templatePath = “Sheet.omr”;
// initialize engine and get template processor providing path to the .omr file
OmrEngine engine = new OmrEngine();
TemplateProcessor templateProcessor = engine.getTemplateProcessor(templatePath);
System.out.println(“Template loaded.”);
// images loop
for (int i = 0; i < UserImages.length; i++) {
// path to the image to be recognized
String imagePath = UserImages[i];
System.out.println("Processing image: " + imagePath);
// recognize image and receive result
RecognitionResult result = templateProcessor.recognizeImage(imagePath);
// export results as csv string
String csvResult = result.getCsv();
String json = result.getJson();
// save csv to the output folder
PrintWriter wr = new PrintWriter(new FileOutputStream(UserImagesNoExt[i] + “.csv”), true);
wr.println(csvResult);
}

Hope this code will help you proeprly.

This example is a big help for me to understand the capabilities. We have not purchased Aspose.OMR yet, but just evaluating for our project. Thanks so much.

@mcard

Please keep evaluating the API and feel free to create a new topic in case you need further assistance.