Click here to Skip to main content
15,867,488 members
Articles / Desktop Programming / Windows Forms
Article

The Atalasoft OCR engine

3 Oct 2005CPOL2 min read 69.7K   24   7
Convert images to plain text with the Atalasoft suite of OCR objects.

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

Image 1

Introduction

At Atalasoft, we’re excited to unveil the newest addition to our product line, Atalasoft OCR. This suite of objects, now available, provides interfacing to OCR engines in a way that makes integration into your .NET application a snap.

In the classes provided, we offer the best of all possible worlds: a multilayered approach to exposing engine capabilities that gets up and running quickly, yet also allows you to get down to the nitty gritty details that are most important to you.

When using Atalasoft OCR engine in its most basic way, most of the work is in managing the user interface and not the OCR engine.

The following snippet of C# code demonstrates how to convert a set of image files into a single plain text file.

C#
static void Main(string[] args)
{
    // create and initialize the engine
    ExperVisionEngine engine = new ExperVisionEngine(null, null);
    engine.Initialize();
     
    // select a file or set of files
    OpenImageFileDialog openDialog = new OpenImageFileDialog();
    openDialog.Multiselect = true;
    if (openDialog.ShowDialog() == DialogResult.OK) 
    {
        SaveFileDialog saveFileDialog = new SaveFileDialog();
        saveFileDialog.Filter = "Text (*.txt)|*.txt";
        if (saveFileDialog.ShowDialog() != DialogResult.OK)
            return;
        try 
        {
            // translate into a plain text file
            engine.Translate(
                new FileSystemImageSource(openDialog.FileNames, true),
                "text/plain", saveFileDialog.FileName);
        }
        catch (OcrException err) 
        {
            System.Console.WriteLine("Error in OCR: " + err.Message);
        }
    }
    engine.ShutDown();
}

As you can see, the interfacing is simple. You may also notice that the main use of the engine is the Translate method, which will takes a set of images and writes them to a file (or stream) using the given MIME type as the output format. By using the MIME standard to describe output file types, it is easy to ask the engine what output types it can support as well as to augment or replace them!

The OcrEngine maintains a collection of objects that implement an interface called ITranslator. When you request that a set of images are to be translated to an output file format, the engine will select a translator that matches the mime type.

Image 2

If your task requires you to generate output in a particular format, it is short work to create your own object to translate the recognized text and images into the format that you need. You can add your new translator or take away from the engine’s translator collection as you see fit. You can even bypass the translator selection process entirely and simply supply the translator that you want to use.

OCR Engine Events

Through the familiar .NET event mechanism, you can get hooked into every step of document processing, allowing you to finely control how your images are handled. For example, you can request notification during the stage when an image is preprocessed to make it more palatable for the OCR engine, letting you alter what the engine will use for recognition.

In the following C# code snippet, you can see how to hook in your own code to do image preprocessing:

C#
static void Main(string[] args)
{
    // create and initialize the engine
    ExperVisionEngine engine = new ExperVisionEngine(null, null);
    engine.Initialize();
 
    engine.PagePreprocessing +=
        new OcrPagePreprocessingEventHandler(engine_PagePreprocessing);
}
 
private static void engine_PagePreprocessing(
    object sender, OcrPagePreprocessingEventArgs e)
{
    // override all options
    e.OptionsOut = 0;
 
    AtalaImage imageBW;
    // convert to black and white, if needed
    if (e.ImageIn.PixelFormat != PixelFormat.Pixel1bppIndexed)
        imageBW = e.ImageIn.GetChangedPixelFormat(
                                 PixelFormat.Pixel1bppIndexed);
    else
        imageBW = e.ImageIn;
 
    // Deskew the image
    AutoDeskewCommand deskew = new AutoDeskewCommand();
    AtalaImage imageDeskewed = deskew.ApplyToImage(imageBW);
    if (imageBW != imageDeskewed && imageBW != e.ImageIn)
        imageBW.Dispose();
 
    // Hand back to the engine
    e.ImageOut = imageDeskewed;
}

As you can see, the amount of work to get hooked in is small, letting you concentrate on the task: processing the image in the way that you want.

The Atalasoft OCR objects let you hook into image processing, image segmentation, and output page construction. There are also events to let you track progress of the engine on a page as well as throughout an entire document. This lets you show your users what they need to know.

Contact Atalasoft directly for more details, or download a 30 day trial of our OCR engine today.

License

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


Written By
Architect Atalasoft, a Kofax Company
United States United States
Steve Hawley is a software engineer/architect at Atalasoft, Inc., responsible for current and future component designs.

Comments and Discussions

 
QuestionDoes the OCR engine support Indic Scripts? Pin
Yogi Yang24-Oct-08 4:43
Yogi Yang24-Oct-08 4:43 
RantDisappointed in Atalasoft Software Pin
T0mYtI12-Jul-08 22:22
T0mYtI12-Jul-08 22:22 
GeneralRe: Disappointed in Atalasoft Software Pin
Lou Franco14-Aug-08 5:51
Lou Franco14-Aug-08 5:51 
QuestionEngine Accuracy Pin
MrTouya9-Mar-07 10:13
MrTouya9-Mar-07 10:13 
Generalthe first impression was very negative [modified] Pin
Ryzhiy26-Jan-07 0:47
Ryzhiy26-Jan-07 0:47 
AnswerRe: the first impression was very negative Pin
Steve Hawley26-Jan-07 2:52
Steve Hawley26-Jan-07 2:52 
GeneralRe: the first impression was very negative Pin
Richard Minerich4-Jun-09 10:04
Richard Minerich4-Jun-09 10:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.