Optical Mark Recognition,縮寫為 OMR,經常用於評估問卷、調查和其他信息收集標準。在本文中,您可以了解如何在 .NET 應用程序中使用 C# 語言創建和檢查 OMR 問題和氣泡答題紙。我們將簡要探討以下方法:

OMR Template Creator and Checker 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. 在 TXT 文件中寫入 CSV 輸出

下面的代碼片段顯示瞭如何在 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 操作對於不同的研究方法非常有幫助。此外,如有任何疑慮或疑問,您可以通過 免費支持論壇 與我們聯繫。

也可以看看