Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active December 23, 2021 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/a9d1baca3598602f46e7d857cc19f730 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/a9d1baca3598602f46e7d857cc19f730 to your computer and use it in GitHub Desktop.
Recognize Image from MemoryStream using OMR in 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 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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment