光学标记识别,缩写为 OMR,经常用于评估问卷、调查和其他信息收集标准。在本文中,您可以了解如何在 .NET 应用程序中使用 C# 语言创建和检查 OMR 问题和气泡答案表。我们将简要探讨以下方法:

OMR 模板创建器和检查器 API – 安装 使用 C# 创建 OMR 问题表模板、图像和 PDF 文件 使用 C# 对多项选择气泡答题纸图像执行 OMR

OMR 模板创建器和检查器 API – 安装

为了在 C# 或 VB.NET 应用程序中创建 OMR 模板和执行 OMR 操作,首先我们需要安装 Aspose.OMR for .NET API。您可以从 New Releases 或使用以下 NuGet 命令轻松下载它:

Install-Package Aspose.OMR -Version 20.6.0

因此,我们现在已准备好使用 C# 使用 API 创建多项选择题表资源:

使用 C# 创建 OMR 问题表模板、图像和 PDF 文件

让我们探索创建 OMR 问题表资源。在这里,我们将示例问题存储在 TXT 文件中,稍后 OMR 引擎将使用该文件来创建 OMR 试卷模板、图像和 PDF 文件。此外,以下是我们将用作 OMR 引擎输入的文本标记:

?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________________________________

现在我们将使用 C# 代码按照以下步骤创建 OMR 多项选择题表:

  1. 初始化 OMR 引擎
  2. 使用文本标记调用 GenerateTemplate 方法
  3. 保存 OMR 输出问题表

以下代码片段基于这些步骤,展示了如何使用 C# 创建 OMR 问题表模板、图像和 PDF 文件:

// 初始化 OMR 引擎
OmrEngine engine = new OmrEngine();

// 调用模板生成提供带有标记的 txt 文件的路径
GenerationResult res = engine.GenerateTemplate(Path.Combine(testFolderPath, "Grid.txt"));

// 检查是否有错误
if (res.ErrorCode != 0)
{
    Console.WriteLine("ERROR CODE: " + res.ErrorCode);
}

// 您可以使用以下任一方法
// 保存生成结果:PDF 和 .omr 模板
res.SaveAsPdf(testFolderPath , "Grid");
// 保存生成结果:图像和 .omr 模板
res.Save(testFolderPath, "Grid");

因此,我们创建了 OMR 试卷,如下面的屏幕截图所示。您可以根据您的要求通过打印生成的 PDF 文件或图像来分发论文。

OMR 模板

使用 C# 对多项选择气泡答题纸图像执行 OMR

最后,您将收集生成的气泡答题纸上的响应,然后捕获图像,或扫描它们以使用 C# 执行 OMR。在此示例中,让我们考虑以下示例图像。 Aspose.OMR for .NET API 将创建一个逗号分隔 (CSV) 文件作为执行 OMR 的输出。

创建 omr

让我们按照以下步骤使用 C# 执行 OMR:

  1. 指定模板文件路径
  2. 指定扫描图像文件路径
  3. 初始化 TemplateProcessor
  4. 使用 RecognizeImage 方法识别图像
  5. 将 CSV 输出写入 TXT 文件

下面的代码片段显示了如何在 C# 中对多项选择气泡答题纸图像执行 OMR:

string TemplateName = @"Sheet.omr";
string[] UserImages = new string[] { "Sheet1.jpg" };

// 输入输出准备
string testFolderPath = dataDir;
string templatePath = Path.Combine(testFolderPath, TemplateName);

// 实际的 OMR API 调用
OmrEngine engine = new OmrEngine();
TemplateProcessor templateProcessor = engine.GetTemplateProcessor(templatePath);
Console.WriteLine("Template loaded.");

for (int i = 0; i < UserImages.Length; i++)
{
    string imagePath = Path.Combine(testFolderPath, UserImages[i]);
    string csvResult = templateProcessor.RecognizeImage(imagePath).GetCsv();

    File.WriteAllText(Path.Combine(outputPath, Path.GetFileNameWithoutExtension(UserImages[i]) + ".csv"), csvResult);
    Console.WriteLine("Result exported. Path: " + Path.Combine(testFolderPath, Path.GetFileNameWithoutExtension(UserImages[i]) + ".csv"));
}

以下屏幕截图显示了使用 Aspose.OMR for .NET API 生成输出 CSV 文件的效率和准确性。现在可以根据您的系统设计进一步处理此 CSV 信息。

执行 omr

结论

简而言之,我们学习了如何创建问题表,然后使用 C# 执行 OMR 操作以标记气泡答卷图像。这种 OMR 表创建然后对图像执行 OMR 操作在不同的研究方法中非常有帮助。此外,如有任何疑虑或疑问,您可以通过 免费支持论坛 与我们联系。

也可以看看