Skip to content

Instantly share code, notes, and snippets.

@aspose-omr-gists
Created February 14, 2024 13:51
Show Gist options
  • Save aspose-omr-gists/7cc720f05d39e6867f442c4f06b4bab9 to your computer and use it in GitHub Desktop.
Save aspose-omr-gists/7cc720f05d39e6867f442c4f06b4bab9 to your computer and use it in GitHub Desktop.
Read Bubble Answer Sheet in Java - OMR Sheet JPG
package com.example;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import com.aspose.omr.OmrEngine;
import com.aspose.omr.RecognitionResult;
import com.aspose.omr.TemplateProcessor;
public class Main {
// Read Bubble Answer Sheet in Java - OMR Sheet JPG
public static void main(String[] args) throws Exception {
String UserImages = "/SimpleSurvey.jpg";
String UserImagesNoExt = "/Sheet1";
String templatePath = "/SimpleSurvey.omr";
// Instantiate an instance of the the OmrEngine class that handles the creation of the template and image processing classes and GUI components.
OmrEngine engine = new OmrEngine();
// Load the .omr file by calling the getTemplateProcessor method and assign it to an object of the TemplateProcessor class.
TemplateProcessor templateProcessor = engine.getTemplateProcessor(templatePath);
// recognize image and receive result by invoking the recognizeImage method and assign the results to the instance of the RecognitionResult class.
RecognitionResult result = templateProcessor.recognizeImage(UserImages);
// Call the getCsv method to export data to csv string.
String csvResult = result.getCsv();
// Save the csv file to the output folder.
PrintWriter wr = new PrintWriter(new FileOutputStream(UserImagesNoExt + ".csv"), true);
wr.println(csvResult);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment