
You can recognize specific marks on images by performing optical mark recognition operations. For example, you can recognize bubbles filled for a questionnaire, survey, or an exam in the form of Multiple Choice Questions. Please refer to the following sections for further details:
- Optical Mark Recognition – C# API Installation
- Recognize Image from MemoryStream using OMR in C#
- Batch Processing the Images for Recognition with OMR using C#
Optical Mark Recognition – C# API Installation
You can configure Aspose.OMR for .NET API in your C# applications by downloading the DLL from the Downloads sections, or via NuGet gallery with the following installation command:
PM> Install-Package Aspose.OMR
Recognize Image from MemoryStream using OMR in C#
Sometimes the images are stored in database or some remote resource and you can load those files in a MemoryStream. Likewise, there can be many scenarios where saving an image on the disk and then loading it for processing can be an overhead. So you can conveniently load the image into a Stream and perform OMR operations on it. Below are the steps to recognize an image from MemoryStream:
- Get the template to recognize.
- Initialize OmrEngine class object.
- Recognize image in the MemoryStream with the RecognizeImage method.
- Save output file with RecognitionResult class instance.
The following code shows how to recognize the image from a MemoryStream with OMR in C#:
// Get template to recognize | |
string templatePath = "Sheet.omr"; | |
// Get image for recognize | |
string imagePath = "Sheet1.JPG"; | |
// Initialize OmrEngine class object | |
OmrEngine engine = new OmrEngine(); | |
// Set template for recognize | |
TemplateProcessor templateProcessor = engine.GetTemplateProcessor(templatePath); | |
using (Image image = Image.FromFile(imagePath)) | |
{ | |
using (MemoryStream ms = new MemoryStream()) | |
{ | |
image.Save(ms, image.RawFormat); | |
ms.Flush(); | |
// Recognize image | |
Aspose.OMR.Model.RecognitionResult result = templateProcessor.RecognizeImage(ms); | |
var stringRes = result.GetCsv(); | |
File.WriteAllText(Path.GetFileNameWithoutExtension(imagePath) + ".csv", stringRes); | |
} | |
} |
Batch Processing the Images for Recognition with OMR using C#
You can process a batch of images in a folder and recognize the marks with optical mark recognition. Please follow the following steps for recognizing a batch of images:
- Get the OMR template to recognize.
- Get RecognitionResult of all the images using RecognizeFolder method.
- Save output as a CSV file.
The code below explains how to process a batch of images for optical mark recognition programmatically using C#:
// Get template to recognize | |
string templatePath = "Sheet.omr"; | |
// Get folder contains images for recognize | |
string folderPath = "D:\images\"; | |
OmrEngine engine = new OmrEngine(); | |
// Set template for recognize | |
TemplateProcessor templateProcessor = engine.GetTemplateProcessor(templatePath); | |
// Recognize images from folder | |
Aspose.OMR.Model.RecognitionResult[] result = templateProcessor.RecognizeFolder(folderPath); | |
for (int i = 0; i < result.Length; i++) | |
{ | |
var stringRes = result[i].GetCsv(); | |
File.WriteAllText(folderPath + (i+1) + ".csv", stringRes); | |
} |
Get Free API License
You can evaluate the API without any limitations by requesting a Free Temporary License.
Conclusion
In this article, you have learned how to recognize an image from a MemoryStream using OMR in C#. It also discusses recognizing all the images in a folder and saving the output result as CSV, comma-separated values, files. Moreover, you can take a look at other features of the API by visiting the Documentation. You can always get in touch with us at Free Support Forum for any of your concerns.