Optical Mark Recognition (OMR) is frequently used to check surveys, questionnaires, and multiple-choice examination papers. It is a fast and accurate way of processing forms. In this article, you will learn how to create OMR templates and check filled answer sheets using Java.
- Java API for Generating OMR Templates and Performing OMR Operation
- Create OMR Template and Answer Sheet Image using Java
- Perform OMR Operation on Bubble Answer Sheets using Java
Java API for Generating OMR Templates and Performing OMR Operation
Aspose.OMR for Java is an optical mark recognition API that can perform OMR operations on PNG, GIF, JPEG, TIFF, etc. images. The API also supports generating OMR templates. You can either download the API directly from the downloads section or install it using the following Maven configuration.
<repositories> <repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>http://repository.aspose.com/repo/</url> </repository> </repositories>
<dependency> <groupId>com.aspose</groupId> <artifactId>aspose-omr</artifactId> <version>19.12</version> <classifier>jdk6</classifier> </dependency> <dependency> <groupId>com.aspose</groupId> <artifactId>aspose-omr</artifactId> <version>19.12</version> <classifier>javadoc</classifier> </dependency>
Create OMR Template and Answer Sheet Image using Java
In this section, you will learn how to generate OMR template files and answer sheet images using simple text markup. We will store the text markup in a TXT file and use it in the Java code to generate the OMR template. Given below is the text markup that we will use in this example to generate the OMR template.
?text=Name__________________________________ Date____________ ?grid=ID sections_count=8 #What is Aspose.OMR main function? () OCR () Capture human-marked data () There is no main function () Enhance images #Can Aspose.OMR process not only scans, but also photos? () Yes, indeed! () No #Aspose.OMR is available on any platform, because it is: () Cross-platform code () Cloud service #Aspose.OMR works with any kind of OMR forms: tests, exams, questionnaires, surveys, etc. () Yes, indeed! () No #Excellent recognition results can be achieved only for filled bubbles at least for: () 40% () 60% () 75% () 98% #Do you have to mark up every question on the page? (Yes) Yes, that will help a lot! (No) No #Rate your preference from 0 to 9 with "0" being preference towards performance and "9" being preference towards flexibility. (0) (1) (2) (3) (4) (5) (6) (7) (8) (9) #I found aspose omr to be a useful tool. (5 - strongly agree, 1 - strongly disagree) (5) (4) (3) (2) (1) ?text= Answer sheet section ?answer_sheet=MainQuestions elements_count=10 columns_count=5 ?text=Sign________________________________
Now that we have the text markup ready, we will follow the steps given below to generate the OMR template.
- Firstly, create an instance of the OmrEngine class.
- Process the text markup using the OmrEngine.generateTemplate(String markupPath) method.
- Save the OMR template and image using the GenerationResult.save(String folder, String name) method.
The following sample code shows how to generate an OMR template using text markup with Java.
The above code will generate an OMR template file and an image of the answer sheet. The following is the image of the generated answer sheet.
Perform OMR Operation on Bubble Answer Sheets using Java
After you have collected the responses on the generated answer sheet, you can capture their images and then perform OMR operations on them. In this example, we will perform the OMR operation on two images; the first is shown below.
The following are the steps to perform OMR operation on images.
- Create an instance of the OmrEngine class.
- Load the template file using the OmrEngine.getTemplateProcessor(String templatePath) method.
- Process the image using the TemplateProcessor.recognizeImage(String imagePath) method.
- Get the result in CSV format using the RecognitionResult.getCsv() method.
The following sample code shows how to perform OMR operation on images using Java.
The following is the CSV output for the first image generated by the above code.
Element Name,Value, MainQuestions1,"A" MainQuestions2,"B" MainQuestions3,"D" MainQuestions4,"C" MainQuestions5,"C" MainQuestions6,"A" MainQuestions7,"B" MainQuestions8,"B" MainQuestions9,"C" MainQuestions10,"B" MainQuestions11,"D" MainQuestions12,"A" MainQuestions13,"C" MainQuestions14,"B" MainQuestions15,"D" MainQuestions16,"A" MainQuestions17,"C" MainQuestions18,"B" MainQuestions19,"A" MainQuestions20,"A" MainQuestions21,"A" MainQuestions22,"C" MainQuestions23,"D" MainQuestions24,"B" MainQuestions25,"A" MainQuestions26,"C" MainQuestions27,"B" MainQuestions28,"D" MainQuestions29,"C" MainQuestions30,"A" MainQuestions31,"C" MainQuestions32,"B" MainQuestions33,"D" MainQuestions34,"A" MainQuestions35,"C" MainQuestions36,"B" MainQuestions37,"D" MainQuestions38,"C" MainQuestions39,"B" MainQuestions40,"A" MainQuestions41,"D" MainQuestions42,"C" MainQuestions43,"B" MainQuestions44,"A" MainQuestions45,"C" MainQuestions46,"B" MainQuestions47,"D" MainQuestions48,"C" MainQuestions49,"A" MainQuestions50,"C" MainQuestions51,"B" MainQuestions52,"D" MainQuestions53,"B" MainQuestions54,"C" MainQuestions55,"B" MainQuestions56,"A" MainQuestions57,"C" MainQuestions58,"B" MainQuestions59,"D" MainQuestions60,"B" MainQuestions61,"A" MainQuestions62,"C" MainQuestions63,"B" MainQuestions64,"D" MainQuestions65,"C" MainQuestions66,"B" MainQuestions67,"A" MainQuestions68,"C" MainQuestions69,"B" MainQuestions70,"D" MainQuestions71,"C" MainQuestions72,"B" MainQuestions73,"B" MainQuestions74,"A" MainQuestions75,"C" MainQuestions76,"B" MainQuestions77,"D" MainQuestions78,"D" MainQuestions79,"C" MainQuestions80,"B" ID,"27860000"
Get a Free License
You can try the API without evaluation limitations by requesting a free temporary license.
In this article, you have learned how to generate OMR templates and answer sheet images using Java. Furthermore, you have learned how to perform OMR operations on images and get the result as CSV. Aspose.OMR for Java is a robust API for your OMR-related tasks that you can explore in detail by visiting the official documentation. If you have any questions regarding any aspect of the API, please feel free to reach us at our free support forum.