Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Tuesday, April 11, 2017 4:25:32 PM(UTC)

Hadi  
Hadi

Groups: Manager, Tech Support, Administrators
Posts: 218

Was thanked: 12 time(s) in 12 post(s)

The attached VS 2017 C# .NET Project uses the LEADTOOLS Forms SDK to processed filled out Bubble sheet or OMR (optical mark recognition) forms against a master form.

The class doing all of the hard work is the AutoFormsEngine.

Here is the relevant code:
Code:
 //Create a new instance of RasterCodecs
         using (RasterCodecs codecs = new RasterCodecs())
         {
            //We want to load all pages since it could be a multipage masterform / filled form
            codecs.Options.Load.AllPages = true;
            //Make sure to load any documents as 300x300 DPI for best accuracy
            codecs.Options.RasterizeDocument.Load.XResolution = 300;
            codecs.Options.RasterizeDocument.Load.YResolution = 300;

            //Set the directory of the Master Form Repository
            string masterFormRepository = @"C:\Users\Public\Documents\LEADTOOLS Images\Forms\MasterForm Sets\OMR";
            //set the directory of the filled forms
            string filledFormDirectory = @"C:\Users\Public\Documents\LEADTOOLS Images\Forms\Forms to be Recognized\OMR";
            //Startup the OCR Engine
            using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false))
            {
               ocrEngine.Startup(codecs, null, null, null);

               //Create the repository initialize the AutoFormsEngine and load each form
               IMasterFormsRepository repository = new DiskMasterFormsRepository(codecs, masterFormRepository);
               using (AutoFormsEngine engine = new AutoFormsEngine(repository, ocrEngine, null, AutoFormsRecognitionManager.Default | AutoFormsRecognitionManager.Ocr, 30, 80, false))
               {
                  //loop through all of the files in the directory of filled forms
                  foreach (var file in Directory.EnumerateFiles(filledFormDirectory))
                  {
                     Console.WriteLine("Processing file " + Path.GetFileName(file));
                     using (RasterImage image = codecs.Load(file))
                     {
                        //Run the recognition
                        AutoFormsRunResult runResult = engine.Run(image, null, null, null);

                        Console.WriteLine("Form Processed using " + runResult.RecognitionResult.MasterForm.Name);
                        //Process the results - this will jsut display all OMR fields found and output True or False to the console
                        if (runResult != null)
                           foreach (FormPage formPage in runResult.FormFields)
                              foreach (FormField field in formPage)
                                 if ((field as OmrFormField) != null)
                                    Console.WriteLine(field.Name + ": " + ((field.Result as OmrFormFieldResult)?.Text == "1").ToString());
                     }
                     Console.WriteLine("*****************************");
                  }
               }
            }

            Console.WriteLine("Done processing");
            Console.ReadLine();
         }

File Attachment(s):
SimpleOMRDemo.zip (5kb) downloaded 159 time(s).
Hadi Chami
Developer Support Manager
LEAD Technologies, Inc.

LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.037 seconds.