光学标记识别API-Aspose.OMR实操指南:使用 Java 创建 OMR Sheet Checker 或 Scanner

光学标记识别 (OMR) 经常用于检查调查、问卷和多项选择题试卷。它是一种快速而准确的处理表格的方式。在本文中,将学习如何使用 Java 创建 OMR 模板和检查填写的答卷。


使用 Java 创建 OMR 模板和答卷图像

在本节中,将学习如何使用简单的文本标记生成 OMR 模板文件和答卷图像。我们将文本标记存储在一个 TXT 文件中,并在 Java 代码中使用它来生成 OMR 模板。下面给出的是我们将在本示例中用于生成 OMR 模板的文本标记:

ext=Name__________________________________ Date____________rid=IDsections_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 pageYes) Yes, that will help a lot! (No) No#Rate your preference from 0 to 9 with "0" being preference towards performanceand "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)ext= Answer sheet sectionnswer_sheet=MainQuestionselements_count=10columns_count=5ext=Sign________________________________

现在我们已经准备好了文本标记,我们将按照下面给出的步骤来生成 OMR 模板。

  • 首先,创建OmrEngine的实例
  • 使用OmrEngine.generateTemplate(String markupPath)方法处理文本标记
  • 使用GenerationResult.save(String folder, String name)方法保存 OMR 模板和图像

以下示例代码展示了如何使用 Java 文本标记生成 OMR 模板。

// Source and output directory pathsString sourceDirectory = "SourceDirectory\OMR\Generation\";String outputDirectory = "OutputDirectory\";// Create an instance of the OmrEngine classOmrEngine engine = new OmrEngine();// Generate template using the text markupGenerationResult res = engine.generateTemplate(sourceDirectory + "Grid.txt");// Check in case of errorsif (res.getErrorCode() != 0){    System.out.println("ERROR CODE: " + res.getErrorCode());}// Save the generation result: image and .omr templateres.save(outputDirectory, "Grid");

上面的代码会生成一个 OMR 模板文件和一张答卷的图片。以下是生成的答卷图片。

光学标记识别API-Aspose.OMR实操指南:使用 Java 创建 OMR Sheet Checker 或 Scanner

使用 Java 在气泡答题纸上执行 OMR 操作

在生成的答卷上收集到答案后,您可以捕获它们的图像,然后对其执行 OMR 操作。在这个例子中,我们将对两个图像执行 OMR 操作;第一个如下所示。

光学标记识别API-Aspose.OMR实操指南:使用 Java 创建 OMR Sheet Checker 或 Scanner

以下是对图像进行 OMR 操作的步骤。

  • 创建OmrEngine的实例
  • 使用OmrEngine.getTemplateProcessor(String templatePath)方法加载模板文件
  • 使用TemplateProcessor.recognizeImage(String imagePath)方法处理图像
  • 使用RecognitionResult.getCsv()方法以 CSV 格式获取结果

以下示例代码展示了如何使用 Java 对图像执行 OMR 操作。

// Source and output directory pathsString 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 classOmrEngine engine = new OmrEngine();// Load the template fileTemplateProcessor templateProcessor = engine.getTemplateProcessor(sourceDirectory + "Sheet.omr");System.out.println("Template loaded.");// Loop through the imagesfor (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); }

如果你想试用Aspose的全部完整功能,可联系在线客服获取30天临时授权体验。


如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询
标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年7月6日
下一篇 2021年7月6日

相关推荐

发表回复

登录后才能评论