How to Extract Barcode Data from a Scanned OMR Form inside .NET Apps

This technical tip shows how to extract Barcode Data from a Scanned Image inside .NET applications. Aspose.OMR for .NET contains BarcodeElement which provides the functionality to extract barcode information from a scanned OMR form. Aspose.OMR API uses the Aspose.BarCode API for the extraction of barcode information from OMR forms. Therefore it is essential to add a reference to Aspose.BarCodeRecognition.dll in the project when barcode extraction is required. The BarcodeElement class is available in the Aspose.OMR.Elements namespace and can be used to recognize a barcode in a scanned image. The following steps are required to extract barcode data: <br/> <br/> • Create an instance of the OmrTemplate class and initialize it with the path to the template file. <br/> • Create an instance of the OmrImage class and initialize it with the path to the scanned OMR form image. <br/> • Create an instance of the BarcodeElement class and initialize it by specifying the expected barcode location on the scanned image and it's approximate size. <br/> • Add the BarcodeElement object to the OmrTemplate element collection. <br/> • Create an instance of OmrEngine and initialize it by passing the OmrTemplate object. <br/> • Initiate the OMR process by calling the OmrEngine class' ExtractData. <br/> • Get all pages of extracted data and iterate over it to display the extracted information. <br/>
//your code here...Sample Code for Extracting Barcode Data from a Scanned OMR Form //[C# Code Sample] string templateFile = "sample-template.amr"; string imageFile = "sample-image.jpg"; // do not forget to set the license for BarCodeRecognition in case BarCode elements are used Aspose.BarCodeRecognition.License licenseBarCode = new Aspose.BarCodeRecognition.License(); licenseBarCode.SetLicense("Aspose.Total.lic"); Aspose.OMR.License licenseOmr = new Aspose.OMR.License(); licenseOmr.SetLicense("Aspose.Total.lic"); // Loading the template OmrTemplate template = OmrTemplate.Load(templateFile); // 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 OmrImage and load the image using file path OmrImage image = OmrImage.Load(imageFile); // 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]); } } //[VB.NET Code Sample] Dim templateFile As String = "sample-template.amr" Dim imageFile As String = "sample-image.jpg" ' do not forget to set the license for BarCodeRecognition in case BarCode elements are used Dim licenseBarCode As New Aspose.BarCodeRecognition.License() licenseBarCode.SetLicense("Aspose.Total.lic") Dim licenseOmr As New Aspose.OMR.License() licenseOmr.SetLicense("Aspose.Total.lic") ' Loading the template Dim template As OmrTemplate = OmrTemplate.Load(templateFile) ' Adding BarCode element requires creation of BarcodeElement object ' While specifying the barcode display name, its position and size Dim barcodeElement As 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 OmrImage and load the image using file path Dim image As OmrImage = OmrImage.Load(imageFile) ' Create an instance of OmrEngine and load the template using file path Dim engine As New OmrEngine(template) ' Extract OMR data and store the results in an instance of OmrProcessingResults Dim result As OmrProcessingResult = engine.ExtractData(New OmrImage(){image}) ' Get all page data into an instance of Hashtable Dim pages() As Hashtable = result.PageData ' Loop over all the pages For Each page As Hashtable In pages ' Display key and value For Each key As String In page.Keys Console.WriteLine("key: " & key & ": " & "value: " & page(key)) Next key Next page

Url: http://www.aspose.com/categories/.net-components/aspose.ocr-for-.net/default.aspx

Language: C/C++ | User: Sheraz Khan | Created: Mar 27, 2015 | Tags: Extracting Barcode Data extract barcode information from image extract barcode info from OMR form recognize barcode in scanned image perform OCR on image .NET OCR Component, .NET OCR libraries