如何在 C# 中创建 OMR 答案表检查器

在本指南主题中,我们将向您展示如何在 C# 中创建 OMR 答案表检查器。在此分步指南之后,您将能够扫描 C# 代码中的多项选择答题纸。本主题有助于将 C# 应用程序中的光学标记识别应用于图像。

在 C# 中创建 OMR 答案表检查器的步骤

  1. 从 NuGet.org 安装 Aspose.OMR for .NET
  2. 使用 Aspose.OMRAspose.OMR.Api 命名空间在 C# 中扫描答题纸
  3. 使用 SetLicense 方法为 .NET API 许可证设置 Aspose.OMR
  4. 使用 OmrEngine class 将 OMR 模板读入 TemplateProcessor object
  5. 扫描和识别 PNG 图像以将结果提取为 CSV 数据
  6. 将提取的 CSV 数据保存为输出 CSV 文件

上述步骤可帮助您快速轻松地阅读 C# 中的多项选择答题纸。您无需任何外部软件即可阅读 C# 应用程序中的答题纸。 Aspose.OMR for .NET 可以解决这个问题。

在 C# 中创建 OMR 答案表检查器的代码

using System;
using System.IO;
//Add reference to Aspose.OMR for .NET API
//Use following namespaces to create OMR answer sheet checker
using Aspose.OMR;
using Aspose.OMR.Api;
namespace CreateOMRAnswerSheetChecker
{
class Program
{
static void Main(string[] args)
{
//Set Aspose license before creating OMR answer sheet checker
//using Aspose.OMR for .NET
Aspose.OMR.License AsposeOMRLicense = new Aspose.OMR.License();
AsposeOMRLicense.SetLicense(@"c:\asposelicense\license.lic");
//Load template file into template processor
OmrEngine OMREngine = new OmrEngine();
TemplateProcessor OMRTemplateProcessor = OMREngine.GetTemplateProcessor("OMRTemplate.omr");
//Get CSV values from the actual image
String ExtractedCSVFromImage = OMRTemplateProcessor.RecognizeImage("AnswerSheetImageToOMR.png").GetCsv();
//Save output as CSV
File.WriteAllText("OutputExtractedCSVValues.csv", ExtractedCSVFromImage);
}
}
}

在上面的代码中,我们在 PNG 图像上应用了 optical mark recognition 并在 C# 中读取答案表。请注意,我们使用 OMR 模板来识别多项选择答题纸。最后,我们将提取的数据保存在 CSV 文件中。

 简体中文