ImageGear Professional DLL v17.1 for Windows Accusoft
Using Recognition Component
Send Feedback  
ImageGear Professional DLL v17.1 for Windows > User Guide > Getting Started > Using Recognition Component

Glossary Item Box

The following tutorial provides step-by-step instructions on how to create a simple application that loads and recognizes images and saves the recognized data into the file in the specified output format.

The Recognition Component is available for ImageGear Professional DLL 32-bit versions.

Preliminary Steps

Before completing the tutorial steps, complete the preliminary steps outlined in this section.

ImageGear Binary Files to be Accessible from the Application

The following necessary binaries must be located in the working directory of the application or in the directory being specified by the system path:

Recognition re-distributable package (see Distributing Recognition Engine Files with Your Application)

igcore17d.dll must be linked to the application using igcore17d.lib or any other appropriate way. Other dlls do not need to be linked.

ImageGear Header Files to be Included into the Application Code

The following header files must be included into the code:

C Copy Code
#include "gear.h" // Include for ImageGear Core
#include "i_rec.h" // Include for ImageGear Recognition component

Note that all other ImageGear header files that are referenced from these two must be accessible.

Creating the Application 

  1. Set the solution name and attach the components. Before working with any ImageGear functionality, you need to set the license solution name and attach all necessary components to the Core. These operations must be performed only once per session.
    C Copy Code
    AT_ERRCOUNT nErrCount;
    HIGEAR hIGear;
    HIG_REC_IMAGE hRecImg;
    AT_INT i;
    enumIGRecLangEnable lang[IG_REC_LANG_SIZE];
    HIG_REC_DOCUMENT hDocument;
    // Set license solution name
    nErrCount = IG_lic_solution_name_set( "AccuSoft 1-100-17" );
    if(nErrCount != 0)
        return;
    // Attach LZW component (if necessary)
    IG_comm_comp_attach( "LZW" );
    // Attach Recognition component
    nErrCount = IG_comm_comp_attach( "LZW" );
    if(nErrCount != 0)
    {
        return -1;
    }
    
     
  2. Initialize the Recognition component. Before using the Recognition component it must be initialized:
    C Copy Code
    nErrCount = IG_REC_initialize();
    if(nErrCount != 0)
    {
        return -1;
    }
    
     
  3. Load the image file and import its content into the Recognition image. ImageGear Core operates on HIGEAR image handles; Recognition component requires its own image representation, that is, HIG_REC_IMAGE. The following code loads the image file and imports HIGEAR into HIG_REC_IMAGE:
    C Copy Code
    nErrCount = IG_load_file("..\\RecognitionC\\Image.tif", &hIGear );
    if(nErrCount != 0)
    {
        IG_REC_close();
        return -1;
    }
    nErrCount = IG_REC_image_import(hIGear, &hRecImg);
    // HIGEAR can be deleted now
    IG_image_delete(hIGear);
    if(nErrCount != 0)
    {
        IG_REC_image_delete(hRecImg);
        IG_REC_close();
        return - 1;
    }
    
     
  4. Set recognition languages. Recognition languages must be set before processing and pre-processing. Note that spelling and correction are enabled by default. Use IG_REC_spelling_is_enabled_set and IG_REC_correction_is_enabled_set with the FALSE parameter to disable them.
    C Copy Code
    // Disable all languages
    for(i = 0; i < IG_REC_LANG_SIZE; i ++)
    {
        lang[i] = IG_REC_LANG_DISABLED;
    }
    // Enable English and French
    lang[IG_REC_LANG_ENG] = IG_REC_LANG_ENABLED;
    lang[IG_REC_LANG_FRE] = IG_REC_LANG_ENABLED;
    // Set English and French recognition languages
    nErrCount = IG_REC_languages_set(lang);
    if(nErrCount != 0)
    {
        IG_REC_image_delete(hRecImg);
        IG_REC_close();
        return - 1;
    }
    
     
  5. Preprocess the image. Preprocessing improves the recognition process. It performs such operations as fax correction, deskewing, and rotation. Preprocessing also creates an internal BW image with the secondary resolution conversion and performs inversion (if necessary) and despeckle operations on it.
    C Copy Code
    // Preprocess the image
    nErrCount = IG_REC_image_preprocess(hRecImg);
    if(nErrCount != 0)
    {
        IG_REC_image_delete(hRecImg);
        IG_REC_close();
        return - 1;
    }
    // Recognize the image
    nErrCount = IG_REC_image_recognize(hRecImg);
    if(nErrCount != 0)
    {
        IG_REC_image_delete(hRecImg);
        IG_REC_close();
        return - 1;
    }
    
     
  6. Set the output format, code page, and output level. Before saving the recognized data into the file, the output format, code page, and level must be set.
    C Copy Code
    // Set Word2000 output format
    nErrCount = IG_REC_output_format_set("Converters.Text.Word2000");
    if(nErrCount != 0)
    {
        IG_REC_image_delete(hRecImg);
        IG_REC_close();
        return - 1;
    }
    // Set Windows ANSI code page
    nErrCount = IG_REC_output_codepage_set("Windows ANSI");
    if(nErrCount != 0)
    {
        IG_REC_image_delete(hRecImg);
        IG_REC_close();
        return - 1;
    }
    // Set True Page output level
    nErrCount = IG_REC_output_level_set(IG_REC_OL_TRUEPAGE);
    if(nErrCount != 0)
    {
        IG_REC_image_delete(hRecImg);
        IG_REC_close();
        return;
    }
    
     
  7. Save the document. Formatted output in most formats is performed using the document architecture (except in cases that you need simple text or xml output. In this case you can use IG_REC_output_direct_text_write function. Please refer to Saving the Recognized Data Directly in the Text Format).
    C Copy Code
    // Create a document
    nErrCount = IG_REC_document_create(NULL, &hDocument);
    if(nErrCount != 0)
    {
        IG_REC_image_delete(hRecImg);
        IG_REC_close();
        return;
    }
    // Insert a page into the document.
    // Note that after inserting the page does not require to be deleted.
    nErrCount = IG_REC_document_page_insert(hDocument, hRecImg, -1);
    if(nErrCount != 0)
    {
        IG_REC_document_close(hDocument);
        IG_REC_image_delete(hRecImg);
        IG_REC_close();
        return;
    }
    // Save a document into the file in Word2000 format (being set above)
    IG_REC_document_write(hDocument, "Tutorial.DOC");
    // Close document
    IG_REC_document_close(hDocument);
    
     
  8. Close the Recognition component.
    C Copy Code
    IG_REC_close();
    

See Also

Optical Character Recognition

Recognition Component API Reference

©2012. Accusoft Corporation. All Rights Reserved.