翻譯|使用教程|編輯:胡濤|2022-08-05 10:37:01.977|閱讀 266 次
概述:在本文中,我們將學習如何使用 C# 開發基于 GUI 的 OMR Sheet Reader 應用程序。在本文中,我們將學習如何使用 C# 開發基于 GUI 的 OMR Sheet Reader 應用程序。在本文中,我們將學習如何使用 C# 開發基于 GUI 的 OMR Sheet Reader 應用程序。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
光學標記識別 (OMR) 是一種自動捕獲和分析標記在特殊類型文檔表單上的數據的過程。這種特殊類型的文件可以由人們在調查表、測試表和其他紙質文件上標記/填寫。在本文中,我們將學習如何使用 C# 開發基于 GUI 的 OMR Sheet Reader 應用程序。我們的解決方案將掃描的 OMR 表圖像作為本地磁盤的輸入,然后識別標記,最后以CSV格式導出標記的注冊號和陰影答案。完成上述步驟后,我們將擁有.NET 中的 C# 光學標記識別 (OMR) 軟件。那么讓我們開始吧。
我們的光學標記識別 (OMR) 軟件將具有以下功能:
Aspose.OMR for .NET API 允許設計、創建和識別答題卡、測試、MCQ 試卷、測驗、反饋表、調查和選票。此外,它還提供了一個圖形用戶界面控件,可以添加到 .NET UI 應用程序中。我們將在 .NET UI 應用程序中集成 Aspose.OMR for .NET UI 控件,以開發 OMR 掃描儀/閱讀器應用程序。請下載API 的 DLL 或使用NuGet安裝它。
PM> Install-Package Aspose.OMR
我們可以按照以下步驟開發基于 GUI 的 OMR 掃描儀/閱讀器應用程序:
internal class DialogHelper
{
/// <summary>
/// The filter string for the dialog that opens template images.
/// </summary>
private static readonly string ImageFilesFilterPrompt = "Image files |*.jpg; *.jpeg; *.png; *.gif; *.tif; *.tiff;";
/// <summary>
/// The filter string for the dialog that saves recognition results
/// </summary>
private static readonly string DataExportFilesFilterPrompt = "Comma-Separated Values (*.csv)" + " | *.csv";
/// <summary>
/// Shows Open Image file dialog.
/// </summary>
/// <returns>Path to selected file, or <c>null</c> if no file was selected.</returns>
public static string ShowOpenImageDialog(string suggestedDir = null)
{
OpenFileDialog dialog = new OpenFileDialog();
return ShowDialog(dialog, ImageFilesFilterPrompt, suggestedDir);
}
/// <summary>
/// Shows Save Recognition Results file dialog.
/// </summary>
/// <returns>Path to selected file, or <c>null</c> if no file was selected.</returns>
public static string ShowSaveDataDialog(string suggestedName)
{
SaveFileDialog dialog = new SaveFileDialog();
return ShowDialog(dialog, DataExportFilesFilterPrompt, suggestedName);
}
/// <summary>
/// Displays given dialog and returns its result as a <c>string</c>.
/// </summary>
/// <param name="dialog">The dialog to show.</param>
/// <param name="filter">File type filter string.</param>
/// <param name="suggestedDir">Suggested dialog initial directory</param>
/// <param name="suggestedName">Suggested file name</param>
/// <returns>Path to selected file, or <c>null</c> if no file was selected.</returns>
private static string ShowDialog(FileDialog dialog, string filter, string suggestedDir = null, string suggestedName = null)
{
string fileName = null;
dialog.Filter = filter;
dialog.RestoreDirectory = true;
if (suggestedName != null)
{
dialog.FileName = suggestedName;
}
if (suggestedDir != null)
{
dialog.InitialDirectory = suggestedDir;
}
bool? result = dialog.ShowDialog();
if (result == true)
{
fileName = dialog.FileName;
}
return fileName;
}
}
<Window x:Class="OMR_APP.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:OMR_APP"
mc:Ignorable="d"
Title="Aspose OMR Demo" Height="880" Width="1100">
<Grid Background="WhiteSmoke">
<Grid.RowDefinitions>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<ToolBar Grid.Row="0" Background="LightGray">
<TextBox Name="txtTemplatePath" Margin="5" Width="400" Height="30" Background="White"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
</TextBox>
<Button Margin="5" Width="100" Height="30" Background="White"
Content="Get control" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
Click="GetButtonClicked"/>
<Separator/>
<Button Margin="5" Width="100" Height="30" Background="White"
Content="Select Image" Click="SelectImageClicked"/>
<Button Margin="5" Width="100" Height="30" Background="White"
Content="Recognize Image" Click="RecognizeImageClicked"/>
<Button Margin="5" Width="100" Height="30" Background="White"
Content="Export Results" Click="ExportResultsClicked"/>
</ToolBar>
<ContentControl Grid.Row="1" x:Name="CustomContentControl"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</Window>
view rawOMR-Software-CSharp_MainWindow.xaml hosted with ? by GitHub
之后,替換MainWindow.xaml.cs文件中的以下內容。
/// <summary>
/// Template for testing
/// </summary>
private static readonly string TemplateFilePath = @"C:\Files\OMR\Sheet.omr";
/// <summary>
/// Path to the license Aspose.OMR.NET.lic file
/// </summary>
private static readonly string LicensePath = @"";
private CorrectionControl control;
public MainWindow()
{
InitializeComponent();
// Set and show template file path
txtTemplatePath.Text = TemplateFilePath;
// Set license, provide License file Path and uncomment to test full results
//License lic = new License();
//lic.SetLicense(LicensePath);
}
public string UserImagePath { get; set; }
public string DataFolderPath { get; set; }
/// <summary>
/// Loads and displays CorrectionControl
/// </summary>
private void GetButtonClicked(object sender, RoutedEventArgs e)
{
string path = txtTemplatePath.Text;
try
{
OmrEngine engine = new OmrEngine();
TemplateProcessor processor = engine.GetTemplateProcessor(path);
control = engine.GetCorrectionControl(processor);
CustomContentControl.Content = control;
control.Initialize();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"Exception");
}
}
/// <summary>
/// Select and display image
/// </summary>
private void SelectImageClicked(object sender, RoutedEventArgs e)
{
if (control == null)
{
return;
}
string imagePath = DialogHelper.ShowOpenImageDialog(this.DataFolderPath);
if (string.IsNullOrEmpty(imagePath))
{
return;
}
this.UserImagePath = imagePath;
control.LoadAndDisplayImage(imagePath);
}
/// <summary>
/// Recognize loaded image
/// </summary>
private void RecognizeImageClicked(object sender, RoutedEventArgs e)
{
if (control == null)
{
return;
}
control.RecognizeImage();
}
/// <summary>
/// Export results to CSV
/// </summary>
private void ExportResultsClicked(object sender, RoutedEventArgs e)
{
if (control == null)
{
return;
}
string imageName = Path.GetFileNameWithoutExtension(this.UserImagePath);
string path = DialogHelper.ShowSaveDataDialog(imageName);
if (string.IsNullOrEmpty(path))
{
return;
}
control.ExportResults(path);
MessageBox.Show("The exported resultant CSV file can be found here : " + path, "Operation Successful");
}
以下是我們剛剛創建的 OMR Scanner/Reader 應用程序的演示。
在本文中,我們學習了如何
歡迎下載|體驗更多Aspose產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn