Click here to Skip to main content
Click here to Skip to main content

Tagged as

Improving Forms Recognition Results with Automated Alignment

, 1 Nov 2013
Improving Forms Recognition Results with Automated Alignment

Editorial Note

This article is in the Product Showcase section for our sponsors at CodeProject. These reviews are intended to provide you with information on products and services that we consider useful and of value to developers.

Introduction 

If you have been involved in the development of a document management application or process, you have probably run across a requirement to add, or interface with, forms recognition. It is also likely you have been frustrated with the accuracy of the results. Forms recognition and processing is a complicated procedure with an infinite number of variables and factors contributing to the accuracy of the extracted fields. Every document is different, but most share similar issues contributing to inaccuracies including scan quality, user input legibility, recognition engine quality, etc. However, few variables carry as much weight or significance as form alignment.

Alignment is critical to the accuracy of forms recognition because the form fields are confined to very specific locations on the master form. Therefore, seemingly minute differences of a few pixels or degrees can completely throw off what is presented to the optical text recognition (OCR) or optical mark recognition (OMR) engine, making it impossible to get correct results without scanning the document again or fixing the document in some way.

Figure 1 from left to right:
(1) Master form with field areas defined in green
(2) Filled and scanned form with alignment imperfections
(3) Combined overlay of first two images

Using LEADTOOLS to Automatically Correct Alignment Issues 

Forms alignment in and of itself is a multi-faceted issue consisting of three major obstacles: skew angle, offset margins, scan resolution and non-linear deformations. LEADTOOLS uses its decades of experience and research in the document imaging industry to make it easy for developers to correct alignment problems in their scanned documents. Best of all, the corrections are done automatically with only a few very simple lines of code. 

// Create an OCR Engine for each processor on the machine. This 
// allows for optimal use of thread during recognition and processing.
ocrEngines = new List<IOcrEngine>();
for (int i = 0; i < Environment.ProcessorCount; i++)
{
   ocrEngines.Add(OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false));
   ocrEngines[i].Startup(formsCodec, null, String.Empty, String.Empty);
}
// Point repository to directory with existing master forms 
formsRepository = new DiskMasterFormsRepository(formsCodec, _MasterFormFolder);
autoEngine = new AutoFormsEngine(formsRepository, ocrEngines, null,
    AutoFormsRecognitionManager.Default | AutoFormsRecognitionManager.Ocr, 30, 70, true);

// Run the forms recognition on this document
AutoFormsRunResult runResult = autoEngine.Run(document, null);
if (runResult != null)
{
   // Process the recognized form and extract desired info
   foreach (FormPage formPage in runResult.FormFields)
   {
      foreach (FormField field in formPage)
      {
         // ...
      }
   }
}

LEADTOOLS believes that form alignment is so crucial and integral to the success of forms recognition and processing that it is done automatically as a part of its classification (recognition) algorithm. This is a huge benefit to developers since more time can be devoted to other areas of their application, rather than researching and debugging problems with inaccurate results that disappear with properly aligned forms.

Don’t just take our word for it though. Let’s dive deeper into each of the four forms alignment stumbling blocks, how they adversely affect accuracy, and how using LEADTOOLS will have a huge impact on the overall quality of your forms recognition application.

Skew Angle

If you have spent any amount of time scanning documents, you know very well that the paper isn’t always laid down or fed in perfectly straight. Since the zones defining the form fields are rectangular, it will be very hard for the filled-in text to fit within the restrictive area. With a very modest skew angle of only one degree, a few fields might still land in their boxes, depending on their proximity to the origin of rotation. Most fields, however, will have tops and bottoms of characters cut off, or potentially even show up in a completely different field’s box for larger skew angles.

Figure 2: Example of image skewed by only 1 degree

Offset Margins

Offset margins are similar to the skew angle in that it is a problem with how the document is oriented when scanned. Extra margins are added or subtracted to the scanned image when the top-left corner is not in the correct location, shifting everything up or down and left or right in relation to the original document. Flatbed scanners are more prone to this than those with an automatic document feeder (ADF), but if the guides are poorly chosen or if the paper slips, the same imperfections can appear.

For full page OCR, offset margins present few problems as long as the document has been de-skewed and the rows of text line up horizontally. When recognizing specific fields with a small rectangular region of interest, an offset margin of only five to ten pixels can cause characters to go missing from either side, or for the entire row of characters to be unrecognizable due to being cut off at the top or bottom.

Figure 3: Example of image offset by only (5,10) pixels

Scan Resolution

The scan resolution plays another major role in aligning forms. The DPI (Dots / Pixels Per Inch) of a scanned document sets the coordinate system and therefore can throw off where the fields are physically located in the bitmap. For example, the point located at (300,300) on a 300 DPI image will actually be at (200,200) on a 200 DPI image.

Figure 4: Example of how coordinate systems will differ with different scan resolutions

Most SDKs and forms recognition solutions don’t bother with this and leave it up to either the programmer to convert the coordinate spaces on the fly, or force the user into scanning the form at the same DPI as the original master form. LEADTOOLS sees the value in giving customers and programmers the flexibility and peace of mind in knowing that as long as the scan quality is high enough for OCR, OMR or barcode recognition to be accurate (typically 150-200 DPI is a good baseline), LEADTOOLS can recognize the form and process the fields. All of the coordinates are relative so that once a filled form is scanned and classified, it contains properties that help map the fields to the master form with impeccable accuracy.

Non-Linear Deformations

Finally, the most difficult alignment imperfection to overcome is non-linear deformation. Every scanner is different, and can cause stretching and shrinking in some areas of the document while others appear normal. This means that a document scanned at the same resolution on one scanner might not line up with the exact same paper document fed through a different scanner.

The most common cause of this is the differences in ADF speed. When a document is fed into the scanner, the feeder usually starts slow, speeds up to full speed, and some scanners even slow down again at the end of a document. This would cause the middle of the document to line up correctly, but causing the top and/or bottom to be stretched and in turn misalign the fields. Variations in lenses and even the age of the scanner can also cause non-linear deformations. This poses a huge problem for customers since their forms recognition will usually only work as expected when the filled forms are scanned with the exact same scanner as the master forms.

Figure 5: Example of non-linear deformation. Note how the top of the image aligns but the bottom starts to stretch

Very few forms recognition SDKs are capable of this advanced image processing, but LEADTOOLS is proud to be far ahead of the competition with its full-scale forms recognition document alignment correction. In the final figure below, you will see a form that has been fully corrected with LEADTOOLS forms alignment.

Figure 6: Properly Aligned Form. Note how the data to be extracted fits perfectly within the fields

Conclusion

As evidenced above, there are huge benefits when choosing LEADTOOLS as your forms recognition engine. Its automated forms alignment features can correct the skew angle, offset margins, calculate the relative coordinates for different scan resolutions, and account for non-linear transformations; allowing your filled forms to be in perfect unity with your master forms. When this happens, you will get better accuracy, faster processing speeds, more peace of mind and a faster time to market for your application.

Download the Full Forms Recognition Example

You can download the fully functional demo which includes the features discussed above. To run this example you will need the following:

  • LEADTOOLS free 60 day evaluation
  • Visual Studio 2008 or later
  • Browse to the LEADTOOLS Examples folder (e.g. C:\LEADTOOLS 18\Examples\) where you can find example projects for this and many more technologies in LEADTOOLS

Support

Need help getting this sample up and going? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team (sales@leadtools.com) or call us at 704-332-5532.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

LEADTOOLS Support
Help desk / Support LEAD Technologies, Inc.
United States United States
With a rich history of over twenty years, LEAD has established itself as the world's leading provider of software development toolkits for document, medical, multimedia, raster and vector imaging. LEAD's flagship product, LEADTOOLS, holds the top position in every major country throughout the world and boasts a healthy, diverse customer base and strong list of corporate partners including some of the largest and most influential organizations from around the globe. For more information, contact sales@leadtools.com or support@leadtools.com.
Group type: Organisation (No members)


Follow on   Twitter   Google+

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 1 Nov 2013
Article Copyright 2013 by LEADTOOLS Support
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid