在 C# 中使用條碼建立 OMR 表 |讀取 OMR 條碼 C#

光學標記辨識(OMR)是一種可用於從標記形式的影像中讀取和提取資料的技術。 OMR 通常用於標準化測驗、調查和投票,但它也可用於各種其他應用,例如對學生作業進行評分和追蹤庫存。在這篇文章中,我們將向您展示如何使用 C# 建立和讀取帶有條碼的 OMR 表。

本文涵蓋以下主題:

  1. 使用條碼建立和讀取 OMR - C# API
  2. 建立帶有條碼的 OMR 表
  3. 讀取帶有條碼的 OMR 表
  4. 免費學習資源

使用條碼建立和讀取 OMR - C# API

我們將使用 Aspose.OMR for .NET API 在 C# 中建立和讀取帶有條碼的 OMR 表。它允許開發人員快速輕鬆地設計、呈現和識別 .NET 應用程式中的手填答題表、調查、應用程式和類似表單。

下載 API 的 DLL 或使用 NuGet 安裝它。

PM> Install-Package Aspose.OMR

在 C# 中建立帶有條碼的 OMR 表

我們可以按照以下步驟使用簡單的文字標記輕鬆建立 OMR 模板 (.omr) 檔案和工作表圖像:

  1. 建立 OmrEngine 類別的實例。
  2. 之後,透過以文字檔案路徑作為參數呼叫GenerateTemplate()方法來取得GenerationResult物件。
  3. 最後呼叫Save()方法將產生的圖片和.omr模板檔案儲存到本機磁碟。

以下程式碼範例展示如何使用 C# 建立帶有條碼的 OMR 表。

// 輸入輸出檔目錄
string dataDir = "C:\\Files\\";

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

GenerationResult res = engine.GenerateTemplate(Path.Combine(dataDir, "OMRTestWithBarcode.txt"));

// 檢查是否有錯誤
if (res.ErrorCode != 0)
{
    Console.WriteLine("ERROR: " + res.ErrorCode + ": " + res.ErrorMessage);
}

// 儲存生成結果:圖像和.omr模板
res.Save(dataDir, "OMRTestWithBarcode");
在 C# 中建立帶有條碼的 OMR 表

使用 C# 建立帶有條碼的 OMR 表。

您可以進一步檢查以下用於建立 OMR 範本的簡單文字標記:

?barcode=AsposeWebsite
	value=aspose.com
	barcode_type=qr
	qr_version=1
	x=1900
	y=250
	height=360

?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

?text= Answer sheet section
?answer_sheet=MainQuestions
	elements_count=12
	columns_count=4

?text=Sign________________________________

請在此下載產生的 OMR 範本

用 C# 讀取帶條碼的 OMR 表

我們可以對帶有條碼的 OMR 表的填充掃描影像執行 OMR 操作,並將資料提取到 CSV 檔案中。為此,我們需要準備好的 OMR 範本 (.omr) 和圖像(使用者填寫的表格/工作表)。請依照下列步驟讀取帶有條碼的 OMR 表並提取 CSV 格式的資料。

  1. 建立 OmrEngine 類別的實例。
  2. 呼叫 GetTemplateProcessor() 方法並初始化 TemplateProcessor 類別物件。它將 OMR 模板檔案路徑作為參數。
  3. 透過以影像路徑作為參數呼叫 Recognize() 方法來取得 RecognitionResult 物件。
  4. 之後,使用 GetCsv() 方法取得 CSV 字串形式的辨識結果。
  5. 最後,將CSV結果儲存為本機磁碟上的CSV檔案。

以下程式碼範例展示如何使用 C# 讀取帶有條碼的 OMR 表中的資料並提取資料。

// 此程式碼範例示範如何對影像執行 OMR 並提取數據
// OMR範本檔案路徑
string TemplateName = @"OMRTestWithBarcode.omr";
string UserImage = @"OMRTestWithBarcode.png";

// 輸入輸出檔路徑
string dataDir = "C:\\Files\\";
string templatePath = Path.Combine(dataDir, TemplateName);

// 初始化OMR引擎
OmrEngine engine = new OmrEngine();
TemplateProcessor templateProcessor = engine.GetTemplateProcessor(templatePath);
Console.WriteLine("Template loaded.");

// 取得 CSV 格式的結果
string imagePath = Path.Combine(dataDir, UserImage);
string csvResult = templateProcessor.Recognize(imagePath).GetCsv();

// 儲存 CSV 文件
File.WriteAllText(Path.Combine(dataDir, Path.GetFileNameWithoutExtension(UserImage) + ".csv"), csvResult);
Console.WriteLine("Result exported. Path: " + Path.Combine(dataDir, Path.GetFileNameWithoutExtension(UserImage) + ".csv"));

Console.WriteLine(csvResult);
用 C# 讀取帶條碼的 OMR 表

使用 C# 讀取帶有條碼的 OMR 表。

取得免費許可證

您可以獲得免費的臨時許可證來試用該庫,而不受評估限制。

Aspose.OMR for .NET – 學習資源

除了從圖像中提取 OMR 資料之外,您還可以使用以下資源了解有關 Aspose.OMR 的更多資訊並探索該程式庫的其他功能:

結論

在本文中,我們學習如何在 C# 中建立和讀取帶有條碼的 OMR 表。我們也了解如何提取 OMR 資料並將其儲存為 CSV 格式。透過遵循本文中概述的步驟,您可以利用 Aspose.OMR 並開發您自己的 OMR 應用程式。如有任何疑問,請隨時透過我們的免費支援論壇與我們聯繫。

也可以看看