翻譯|使用教程|編輯:胡濤|2022-05-06 15:37:14.870|閱讀 264 次
概述:在本文中,我們將學習如何使用 C# 執行 OMR 和提取數據,歡迎查閱!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
為了執行 OMR 操作和從圖像中導出數據,我們將使用 Aspose.OMR for .NET API。它允許設計、創建和識別答題紙、測試、MCQ 試卷、測驗、反饋表、調查和選票。
PM> Install-Package Aspose.OMR
為了對圖像執行 OMR 操作,我們需要準備好的 OMR 模板 (.omr) 和圖像(用戶填寫的表格/表格)來執行 OMR。我們可以按照以下步驟對圖像執行 OMR 操作并提取數據:
以下代碼示例展示 了如何使用 C# 對圖像執行 OMR 并以 CSV 格式提取數據。
// OMR Template file path string templatePath = @"D:\Files\OMR\Sheet.omr"; // Image file path string imagePath = @"D:\Files\OMR\Sheet1.jpg"; // Initialize OMR Engine OmrEngine engine = new OmrEngine(); // Get template processor TemplateProcessor templateProcessor = engine.GetTemplateProcessor(templatePath); // Recognize image RecognitionResult result = templateProcessor.RecognizeImage(imagePath); // Get results in CSV string csvResult = result.GetCsv(); // Save CSV file File.WriteAllText(@"D:\Files\OMR\Sheet1.csv", csvResult);
我們可以對多個圖像執行 OMR 操作,并按照前面提到的步驟將數據提取到每個圖像的單獨 CSV 文件中。但是,我們需要對所有圖像一張一張地重復步驟 #3、4 和 5。
以下代碼示例展示 了如何使用 C# 對多個圖像執行 OMR 并以 CSV 格式提取數據。
// OMR Template file path string templatePath = @"D:\Files\OMR\Sheet.omr"; // Images folder file path string imageFolderPath = @"D:\Files\OMR\"; // Output directory path string outputPath = @"D:\Files\OMR\"; // Images to be processed string[] UserImages = new string[] { "Sheet1.jpg", "Sheet2.jpg" }; // Initialize OMR Engine OmrEngine engine = new OmrEngine(); // Get template processor TemplateProcessor templateProcessor = engine.GetTemplateProcessor(templatePath); // Process images one by one for (int i = 0; i < UserImages.Length; i++) } string imagePath = Path.Combine(imageFolderPath, UserImages[i]); // Recognize image RecognitionResult result = templateProcessor.RecognizeImage(imagePath); // Get results in CSV string csvResult = result.GetCsv(); // Save CSV file File.WriteAllText(Path.Combine(outputPath, Path.GetFileNameWithoutExtension(UserImages[i]) + ".csv"), csvResult); }
該 API 還提供了在 OMR 操作期間檢測和識別圖像上可用的任何條形碼的功能。這是 OMR 操作的默認功能。我們可以按照前面提到的步驟進行 OMR 操作并識別條形碼。
我們可以在對圖像執行 OMR 操作時應用閾值。根據需要,閾值的值可以從 0 到 100。閾值越高,API 對突出顯示答案就越嚴格。請按照前面提到的步驟使用閾值執行 OMR。但是,我們只需要在第 3 步中調用重載的RecognizeImage(string, int32)方法。它將圖像文件路徑和閾值作為參數。
以下代碼示例顯示 了如何使用 C# 執行具有閾值的 OMR。
// OMR Template file path string templatePath = @"D:\Files\OMR\Sheet.omr"; // Image file path string imagePath = @"D:\Files\OMR\Sheet1.jpg"; // Threshold value int CustomThreshold = 40; // Initialize OMR Engine OmrEngine engine = new OmrEngine(); // Get template processor TemplateProcessor templateProcessor = engine.GetTemplateProcessor(templatePath); // Recognize image RecognitionResult result = templateProcessor.RecognizeImage(imagePath, CustomThreshold); // Get results in CSV string csvResult = result.GetCsv(); // Save CSV file File.WriteAllText(@"D:\Files\OMR\Sheet1_threshold.csv", csvResult);
在某些情況下,我們可能需要使用不同的閾值重新計算 OMR 結果。為此,我們可以將 API 配置為使用 TemplateProcessor.recalculate() 方法自動重新計算。它允許通過更改閾值設置來多次處理圖像以獲得所需的結果。我們可以按照以下給出的步驟執行帶有重新計算的 OMR 操作:
// OMR Template file path string templatePath = @"D:\Files\OMR\Sheet.omr"; // Image file path string imagePath = @"D:\Files\OMR\Sheet1.jpg"; // Threshold value int CustomThreshold = 40; // Initialize OMR Engine OmrEngine engine = new OmrEngine(); // Get template processor TemplateProcessor templateProcessor = engine.GetTemplateProcessor(templatePath); // Timer for performance measure Stopwatch sw = Stopwatch.StartNew(); // Recognize image RecognitionResult result = templateProcessor.RecognizeImage(imagePath, CustomThreshold); sw.Stop(); // Get results in CSV string csvResult = result.GetCsv(); // Save CSV file File.WriteAllText(@"D:\Files\OMR\Sheet1.csv", csvResult); sw.Restart(); // Recalculate templateProcessor.Recalculate(result, CustomThreshold); sw.Stop(); // Get recalculated results in CSV csvResult = result.GetCsv(); // Save recalculated resultant CSV file File.WriteAllText(@"D:\Files\OMR\Sheet1_Recalculated.csv", csvResult);
歡迎下載|體驗更多Aspose產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn