Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active May 12, 2020 19:33
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/9351fac3e25a64343d5920a7770ded08 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/9351fac3e25a64343d5920a7770ded08 to your computer and use it in GitHub Desktop.
This Gist contains code snippets of Aspose.OMR for .NET
This Gist contains code snippets of Aspose.OMR for .NET
// For complete examples and data files, please go to https://github.com/aspose-omr/Aspose.OMR-for-.NET
// input and output preparation
string testFolderPath = RunExamples.GetGenerationSourceDir();
string outputPath = RunExamples.GetResultDir();
string[] GenerationMarkups = new string[] { "Sheet.txt", "Grid.txt", "AsposeTest.txt" };
// initialize engine
OmrEngine engine = new OmrEngine();
for (int i = 0; i < GenerationMarkups.Length; i++)
{
// call template generation providing path to the txt file with markup
GenerationResult res = engine.GenerateTemplate(Path.Combine(testFolderPath, GenerationMarkups[i]));
// check in case of errors
if (res.ErrorCode != 0)
{
Console.WriteLine("ERROR: " + res.ErrorCode + ": " + res.ErrorMessage);
}
// save generation result: image and .omr template
res.SaveAsPdf(outputPath, Path.GetFileNameWithoutExtension(GenerationMarkups[i]));
}
// For complete examples and data files, please go to https://github.com/aspose-omr/Aspose.OMR-for-.NET
// input and output preparation
string testFolderPath = RunExamples.GetGenerationSourceDir();
string outputPath = RunExamples.GetResultDir();
// initialize engine
OmrEngine engine = new OmrEngine();
GenerationResult res = engine.GenerateTemplate(Path.Combine(testFolderPath, "AsposeTestWithBarcode.txt"));
// check in case of errors
if (res.ErrorCode != 0)
{
Console.WriteLine("ERROR: " + res.ErrorCode + ": " + res.ErrorMessage);
}
// save generation result: image and .omr template
res.Save(outputPath, "AsposeTestWithBarcode");
// For complete examples and data files, please go to https://github.com/aspose-omr/Aspose.OMR-for-.NET
// input and output preparation
string testFolderPath = RunExamples.GetGenerationSourceDir();
string outputPath = RunExamples.GetResultDir();
string[] images = { Path.Combine(testFolderPath, "Aspose.jpg") };
// initialize engine
OmrEngine engine = new OmrEngine();
GenerationResult res = engine.GenerateTemplate(Path.Combine(testFolderPath, "AsposeTestWithImage.txt"), images);
// check in case of errors
if (res.ErrorCode != 0)
{
Console.WriteLine("ERROR CODE: " + res.ErrorCode);
}
// save generation result: image and .omr template
res.Save(outputPath, "AsposeTestWithImage");
// For complete examples and data files, please go to https://github.com/aspose-omr/Aspose.OMR-for-.NET
string TemplateName = @"AsposeTestWithBarcode.omr";
string UserImage = "AsposeTestWithBarcode.jpg";
// input and output preparation
string testFolderPath = RunExamples.GetSourceDir();
string templatePath = Path.Combine(testFolderPath, TemplateName);
string outputPath = RunExamples.GetResultDir();
// actual OMR API calls
OmrEngine engine = new OmrEngine();
TemplateProcessor templateProcessor = engine.GetTemplateProcessor(templatePath);
Console.WriteLine("Template loaded.");
string imagePath = Path.Combine(testFolderPath, UserImage);
string csvResult = templateProcessor.RecognizeImage(imagePath).GetCsv();
File.WriteAllText(Path.Combine(outputPath, Path.GetFileNameWithoutExtension(UserImage) + ".csv"), csvResult);
Console.WriteLine("Result exported. Path: " + Path.Combine(outputPath, Path.GetFileNameWithoutExtension(UserImage) + ".csv"));
Console.WriteLine("OMROperationWithBarcodeRecognition executed successfully.\n\r");
// For complete examples and data files, please go to https://github.com/aspose-omr/Aspose.OMR-for-.NET
// Initialize license object
License omrLicense = new License();
// Set license
omrLicense.SetLicense(@"Aspose.OMR.lic");
// For complete examples and data files, please go to https://github.com/aspose-omr/Aspose.OMR-for-.NET
// Initialize license object
License omrLicense = new License();
// Load license in FileStream
FileStream myStream = new FileStream("Aspose.OMR.lic", FileMode.Open);
// Set license
omrLicense.SetLicense(myStream);
// For complete examples and data files, please go to https://github.com/aspose-omr/Aspose.OMR-for-.NET
// Initialize license object
License omrLicense = new License();
// Set license
omrLicense.SetLicense("Aspose.OMR.lic");
// Set the value to indicate that license will be embedded in the application
omrLicense.Embedded = true;
// For complete examples and data files, please go to https://github.com/aspose-omr/Aspose.OMR-for-.NET
// input and output preparation
string testFolderPath = RunExamples.GetSourceDir() + "Generation";
string outputPath = RunExamples.GetResultDir();
// initialize engine
OmrEngine engine = new OmrEngine();
// call template generation providing path to the txt file with markup
GenerationResult res = engine.GenerateTemplate(Path.Combine(testFolderPath, "Grid.txt"));
// check in case of errors
if (res.ErrorCode != 0)
{
Console.WriteLine("ERROR CODE: " + res.ErrorCode);
}
// save generation result: image and .omr template
res.Save(outputPath, "Grid");
// For complete examples and data files, please go to https://github.com/aspose-omr/Aspose.OMR-for-.NET
string TemplateName = @"Sheet.omr";
string[] UserImages = new string[] { "Sheet1.jpg", "Sheet2.jpg" };
// input and output preparation
string testFolderPath = RunExamples.GetSourceDir();
string templatePath = Path.Combine(testFolderPath, TemplateName);
string outputPath = RunExamples.GetResultDir();
// actual OMR API calls
OmrEngine engine = new OmrEngine();
TemplateProcessor templateProcessor = engine.GetTemplateProcessor(templatePath);
Console.WriteLine("Template loaded.");
for (int i = 0; i < UserImages.Length; i++)
{
string imagePath = Path.Combine(testFolderPath, UserImages[i]);
string csvResult = templateProcessor.RecognizeImage(imagePath).GetCsv();
File.WriteAllText(Path.Combine(outputPath, UserImages[i] + ".csv"), csvResult);
Console.WriteLine("Result exported. Path: " + Path.Combine(outputPath, UserImages[i] + ".csv"));
}
Console.WriteLine("PerformOMROnImages executed successfully.\n\r");
// For complete examples and data files, please go to https://github.com/aspose-omr/Aspose.OMR-for-.NET
string TemplateName = @"Sheet.omr";
string[] UserImages = new string[] { "Sheet1.jpg", "Sheet2.jpg" };
string testFolderPath = RunExamples.GetSourceDir();
string templatePath = Path.Combine(testFolderPath, TemplateName);
string outputPath = RunExamples.GetResultDir();
int CustomThreshold = 40;
// init engine and get template processor
OmrEngine engine = new OmrEngine();
TemplateProcessor templateProcessor = engine.GetTemplateProcessor(templatePath);
Console.WriteLine("Template loaded.");
for (int i = 0; i < UserImages.Length; i++)
{
string image = UserImages[i];
string imagePath = Path.Combine(testFolderPath, image);
Console.WriteLine("\n\rProcessing image: " + imagePath);
// timer for performance measure
Stopwatch sw = Stopwatch.StartNew();
// recognize image
RecognitionResult result = templateProcessor.RecognizeImage(imagePath);
sw.Stop();
Console.WriteLine("Recognition time: " + sw.Elapsed);
// get export csv string
string stringRes = result.GetCsv();
// save csv to output folder
File.WriteAllText(Path.Combine(outputPath, image + ".csv"), stringRes);
Console.WriteLine("Result Exported. Path: " + Path.Combine(outputPath, image + ".csv"));
sw.Restart();
// recalculate recognition results with custom threshold
Console.WriteLine("\n\rPerformaing recalculation\n\r");
templateProcessor.Recalculate(result, CustomThreshold);
sw.Stop();
Console.WriteLine("Recalculation time: " + sw.Elapsed);
// get export csv string
stringRes = result.GetCsv();
// save recalculated results
File.WriteAllText(Path.Combine(outputPath, image + "_Recalculated.csv"), stringRes);
Console.WriteLine("Recalculation result exported. Path: " + Path.Combine(outputPath, image + "_Recalculated.csv"));
}
Console.WriteLine("PerformOMRRecalculation executed successfully.\n\r");
// For complete examples and data files, please go to https://github.com/aspose-omr/Aspose.OMR-for-.NET
string TemplateName = @"Sheet.omr";
string[] UserImages = new string[] { "Sheet1.jpg", "Sheet2.jpg" };
int CustomThreshold = 40;
// input and output preparation
string testFolderPath = RunExamples.GetSourceDir();
string templatePath = Path.Combine(testFolderPath, TemplateName);
string outputPath = RunExamples.GetResultDir();
// actual OMR API calls
OmrEngine engine = new OmrEngine();
TemplateProcessor templateProcessor = engine.GetTemplateProcessor(templatePath);
Console.WriteLine("Template loaded.");
for (int i = 0; i < UserImages.Length; i++)
{
string imagePath = Path.Combine(testFolderPath, UserImages[i]);
string csvResult = templateProcessor.RecognizeImage(imagePath, CustomThreshold).GetCsv();
File.WriteAllText(Path.Combine(outputPath, UserImages[i] + "_Threshold.csv"), csvResult);
Console.WriteLine("Result exported. Path: " + Path.Combine(outputPath, UserImages[i] + "_Threashold.csv"));
}
Console.WriteLine("PerformOMRWithThreshold executed successfully.\n\r");
// For complete examples and data files, please go to https://github.com/aspose-omr/Aspose.OMR-for-.NET
if (control == null)
{
return;
}
string imageName = Path.GetFileNameWithoutExtension(this.UserImagePath);
string path = DialogHelper.ShowSaveDataDialog(imageName);
if (string.IsNullOrEmpty(path))
{
return;
}
control.ExportResults(path);
// For complete examples and data files, please go to https://github.com/aspose-omr/Aspose.OMR-for-.NET
this.dataFolderPath = Path.Combine(FindDataFolder(), TestDataFolderName);
string templatePath = Path.Combine(this.dataFolderPath, TemplateName);
OmrEngine engine = new OmrEngine();
TemplateProcessor processor = engine.GetTemplateProcessor(templatePath);
control = engine.GetCorrectionControl(processor);
CustomContentControl.Content = control;
control.Initialize();
// For complete examples and data files, please go to https://github.com/aspose-omr/Aspose.OMR-for-.NET
if (control == null)
{
return;
}
control.RecognizeImage();
// For complete examples and data files, please go to https://github.com/aspose-omr/Aspose.OMR-for-.NET
if (control == null)
{
return;
}
string imagePath = DialogHelper.ShowOpenImageDialog(this.dataFolderPath);
if (string.IsNullOrEmpty(imagePath))
{
return;
}
this.UserImagePath = imagePath;
control.LoadAndDisplayImage(imagePath);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment