LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Determine if a document needs adjustment for OCR
Groups: Registered, Tech Support, Administrators
Posts: 54
Thanks: 2 times
Was thanked: 10 time(s) in 10 post(s)
While you can usually check how accurately a form is recognized by checking the confidence value, when simply creating a document with OCR, you may not be able to tell how accurate the recognition is until after the document is produced. Thankfully, the
StatisticsInformationCommand allows us to check the image for necessary preprocessing. This demo I have included checks to see how good the contrast is by calculating how much of the image's histogram is within a predefined midtone range. If the midtones are 50% or more of the total image, it executes the
StretchIntensityCommand and the
ChangeContrastCommand to effect a much greater contrast for recognition. A sample snippet from the project is as follows:
Code:
int threshold = 5;
StatisticsInformationCommand statsCommand = new StatisticsInformationCommand();
statsCommand.Run(image);
statsCommand.Start = statsCommand.Minimum + threshold;
statsCommand.End = statsCommand.Maximum - threshold;
statsCommand.Run(image);
Console.WriteLine("This image has {0:0.00}% of gray in it", statsCommand.Percent);
if (statsCommand.Percent > 50)
{
Console.WriteLine("Performing image cleanup...");
StretchIntensityCommand stretchIntensityCommand = new StretchIntensityCommand();
ChangeContrastCommand changeContrastCommand = new ChangeContrastCommand();
stretchIntensityCommand.Run(image);
changeContrastCommand.Contrast = 1000;
changeContrastCommand.Run(image);
Console.WriteLine("Done cleaup.");
}
else
{
Console.WriteLine("Cleanup is not needed for this document");
}
A sample document, created specifically for this project can be found
here. Note that this document will not properly recognize without adjustment.
The full source of this project can be downloaded here:
Edited by user 7 years ago
| Reason: typo
Josh Clark
Developer Support Engineer
LEAD Technologies, Inc.

LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Determine if a document needs adjustment for OCR
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.