public static void Run() { // ExStart:SetElementLevelThreshold // 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"); // Get the first page of the template OmrPage page = template.Pages[0]; // Create an element by passing the name, location and size GridElement element = new GridElement("grid1", new PointF(10, 20), new SizeF(60, 30)); // Add element to the page page.Elements.Add(element); // Create configuration for the element element.Configuration = new OmrConfig(); // Set the TrimWhitePixels to false element.Configuration.TrimWhitePixels = false; // Create an instance of OmrEngine and pass object of OmrTemplate as parameter OmrEngine engine = new OmrEngine(template); // Extract the data OmrProcessingResult result = engine.ExtractData(new OmrImage[] { image }); // ExEnd:SetElementLevelThreshold }
public static void Run() { // ExStart:SettingMarkThreshold // 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"); // Create an instance of OmrEngine and pass object of OmrTemplate as parameter OmrEngine engine = new OmrEngine(template); // Get the configurations of OmrEngine OmrConfig config = engine.Configuration; // Set fill threshold config.FillThreshold = 0.12; // Extract the data OmrProcessingResult result = engine.ExtractData(new OmrImage[] { image }); // ExEnd:SettingMarkThreshold }
public static void Run() { // ExStart:SkewImageCorrectionUsingAlgorithm // 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"); // Area of the image to be processed Rectangle area = new Rectangle(0, 0, image.Width, image.Height); // Grayscale conversion GrayscaleAlgorithm gs = new GrayscaleAlgorithm(); gs.Process(image, area); // Binarization AverageThresholdAlgorithm threshold = new AverageThresholdAlgorithm(); threshold.Process(image, area); // Skew correction SkewCorrectionAlgorithm skewCorrection = new SkewCorrectionAlgorithm(); skewCorrection.Process(ref image, area); // save image image.AsBitmap().Save(dataDir + "result_out.jpg"); // ExEnd:SkewImageCorrectionUsingAlgorithm }
public static void Run() { // ExStart:DetectImageResolutionAutomatically // 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 the auto image resolution detection property image.AutoDetectResolution = true; // Instantiate the recognition engine for the template OmrEngine engine = new OmrEngine(template); // Extract data. This template has only one page. OmrProcessingResult result = engine.ExtractData(new OmrImage[] { image }); // Load actual result from Hashtable OmrResult = result.PageData[0]; // Get Collection of Keys ICollection key = OmrResult.Keys; foreach (string k in key) { Console.WriteLine(k + ": " + OmrResult[k]); } // ExEnd:DetectImageResolutionAutomatically }
public static void Run() { try { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_OCR(); // Load template file OmrTemplate template = OmrTemplate.Load(dataDir + "sample_1.amr"); // Load the image to be analyzed OmrImage image = OmrImage.Load(dataDir + "sample1.jpg"); // do not forget to set the license for BarCode in case BarCode elements are used //Aspose.BarCode.License licenseBarCode = new Aspose.BarCode.License(); //licenseBarCode.SetLicense(dataDir + "Aspose.Total.lic"); //// do not forget to set the license for BarCode in case BarCode elements are used //var licenseOmr = new Aspose.OCR.License(); //licenseOmr.SetLicense(dataDir + "Aspose.Total.lic"); // Adding BarCode element requires creation of BarcodeElement object // While specifying the barcode display name, its position and size BarcodeElement barcodeElement = new BarcodeElement("Aztec BarCode", new PointF(0, 0), new SizeF(205, 205)); // Add the BarCode element to the page element collection template.Pages[0].Elements.Add(barcodeElement); // 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[] { 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]); } } } catch (Exception ex) { Console.WriteLine(ex.Message); // Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx."); } }
public static void Run() { // ExStart:SkewedImageSecondMethod // The path to the documents directory. string dataDir = RunExamples.GetDataDir_OCR(); // Load the image to be analyzed OmrImage image = OmrImage.Load(dataDir + "answers.jpg"); OmrEngine engine = new OmrEngine(new OmrTemplate()); // Get skew degree of the image double degree = engine.GetSkewDegree(image); // Rotate image to correct skew engine.RotateImage(ref image, degree); // Save image image.AsBitmap().Save(dataDir + "result_out.jpg"); // ExEnd:SkewedImageSecondMethod }
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 }