Aspose.OCR.Examples.CSharp.FormattingAndManipulatingOMR.ExtractText.Run C# (CSharp) Method

Run() public static method

public static Run ( ) : void
return void
        public static void Run()
        {
            // ExStart:ExtractText
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OCR();

            // Load template file
            OmrTemplate template = OmrTemplate.Load(dataDir + "questions.amr");

            // Load the image to be analyzed
            OmrImage image = OmrImage.Load(dataDir + "answers.jpg");

            // Set resource for TextOcrElement
            TextOcrElement.Resource = dataDir + "Aspose.OCR.Spanish.Resources.zip";
            // Create an instance of TextOcrElement and initialize it by specifying the location of text and its size in mm
            TextOcrElement textElement = new TextOcrElement("OCR Text", new PointF(23.6f, 15.5f), new SizeF(14.6f, 4.7f));
            // Add the TextOcrElement to the page element collection
            template.Pages[0].Elements.Add(textElement);

            // Create an instance of OmrEngine and load the template using file path
            OmrEngine engine = new OmrEngine(template);
            // Extract OMR data and store the results in an instance of OmrProcessingResults
            OmrProcessingResult result = engine.ExtractData(new OmrImage[] { image });
            // Get all page data into an instance of Hashtable
            Hashtable[] pages = result.PageData;
            // Loop over all the pages
            foreach (Hashtable page in pages)
            {
                // Display key and value
                foreach (string key in page.Keys)
                {
                    Console.WriteLine("key: " + key + ": " + "value: " + page[key]);
                }
            }
            // ExEnd:ExtractText
        }
    }
ExtractText