static void ProcessScansAndExportData() { //fully qualified output path where the scanned images of the forms will be located. var scannedImagePath = AppDomain.CurrentDomain.BaseDirectory + @"Scans\"; ///fully qualified path to the form template var templatePath = AppDomain.CurrentDomain.BaseDirectory + "OmrOutput.omr"; //initialize an instance of the Aspose OMR engine var omrEngine = new OmrEngine(); //retrieve all images from the Scans folder var dirInfo = new DirectoryInfo(scannedImagePath); var files = dirInfo.GetFiles("*.jpg"); //use the omrEngine to create an instance of the template processor based on the generated template var templateProcessor2 = omrEngine.GetTemplateProcessor(templatePath); foreach (var file in files) { //use the template processor to extract form data from the form image string jsonResults = templateProcessor2.RecognizeImage(file.FullName, 28).GetJson(); //save the extracted data in a json file File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + Path.GetFileNameWithoutExtension(file.FullName) + "_scan_results.json", jsonResults); } }
public static void Run() { // ExStart:1 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, Path.GetFileNameWithoutExtension(UserImages[i]) + "_Threshold.csv"), csvResult); Console.WriteLine("Result exported. Path: " + Path.Combine(outputPath, Path.GetFileNameWithoutExtension(UserImages[i]) + "_Threashold.csv")); } Console.WriteLine("PerformOMRWithThreshold executed successfully.\n\r"); // ExEnd:1 }
/// <summary> /// Silent and short version of recognition workflow /// </summary> public static void RecognizeShort() { // --------------------------------------- // input and output preparation string testFolderPath = Path.Combine(FindDataFolder(), TestDataFolderName); Console.WriteLine("Test folder located. Path: " + testFolderPath); string templatePath = Path.Combine(testFolderPath, TemplateName); string outputPath = Path.Combine(testFolderPath, "Result"); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } // --------------------------------------- // actual OMR API calls OmrEngine engine = new OmrEngine(); TemplateProcessor templateProcessor = engine.GetTemplateProcessor(templatePath); 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); } }
public static void Run() { // ExStart:1 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"); // ExEnd:1 }
public static void Run() { // ExStart:1 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, Path.GetFileNameWithoutExtension(image) + ".csv"), stringRes); Console.WriteLine("Result Exported. Path: " + Path.Combine(outputPath, Path.GetFileNameWithoutExtension(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, Path.GetFileNameWithoutExtension(image) + "_Recalculated.csv"), stringRes); Console.WriteLine("Recalculation result exported. Path: " + Path.Combine(outputPath, Path.GetFileNameWithoutExtension(image) + "_Recalculated.csv")); } Console.WriteLine("PerformOMRRecalculation executed successfully.\n\r"); // ExEnd:1 }
/// <summary> /// Method demonstrated full OMR workflow. /// </summary> public static void Recognize() { // Set custom threshold to use in recalculation int CustomThreshold = 40; string testFolderPath = Path.Combine(FindDataFolder(), TestDataFolderName); Console.WriteLine("Test folder located. Path: " + testFolderPath); string templatePath = Path.Combine(testFolderPath, TemplateName); string outputPath = Path.Combine(testFolderPath, "Result"); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } // 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("Processing image: " + imagePath); // recognize image RecognitionResult result = templateProcessor.RecognizeImage(imagePath); // get export csv string string stringRes = result.GetCsv(); // save csv to output folder string outputName = Path.Combine(outputPath, Path.GetFileNameWithoutExtension(image) + ".csv"); File.WriteAllText(outputName, stringRes); Console.WriteLine("Export done. Path: " + outputName); // recalculate recognition results with custom threshold templateProcessor.Recalculate(result, CustomThreshold); // get export csv string stringRes = result.GetCsv(); // save recalculated results outputName = Path.Combine(outputPath, Path.GetFileNameWithoutExtension(image) + "_recalculated.csv"); File.WriteAllText(outputName, stringRes); Console.WriteLine("Recalculated result export done. Path: " + outputName); Console.WriteLine(); } }
/// <summary> /// Loads and displays CorrectionControl /// </summary> private void GetButtonClicked(object sender, RoutedEventArgs e) { 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(); }