This topic provides information about how to get started using ImageGear OCR:
The ImageGear Recognition Component must be attached to the Core component and initialized before using it.
Use the following call to attach the Recognition component:
C and C++ |
Copy Code
|
---|---|
AT_ERRCODE errorCode;
errorCode = IG_comm_comp_attach("REC");
|
If the component has been attached, the function returns IGE_SUCCESS.
To check whether the Recognition component has been already attached, call IG_comm_comp_check("REC"); if the function returns TRUE then the Recognition component has been attached.
After the Recognition component has been attached, the recognition session must be initialized with the function IG_REC_initialize(). The function returns 0 if the session has been initialized successfully. Otherwise, the return value is a number of errors encountered during the initialization.
Recognition component requires additional resource files to be available. See description of IG_REC_initialize() for information on where these files should be located such that the component can access them.
Function IG_REC_close() closes the recognition session if it is no longer necessary. After closing the session, any calls to the recognition functions are not allowed (except IG_REC_initialize()). To start a new recognition session call IG_REC_initialize() again.
The code example below demonstrates loading and recognizing the TEST1.TIF image file. The image contains English, machine-printed text. The result will be saved in the TEST1.TXT text file.
C and C++ |
Copy Code
|
---|---|
// Windows includes. #include <windows.h> // Include for Accusoft ImageGear. #include "gear.h" // Include for ImageGear Recognition component. #include "i_rec.h" // Load and recognize the Image.tif image file. // The result will be saved in the Image.txt text file. VOID OCRImagetoTextFile() { AT_ERRCOUNT errorCount; HIGEAR image; HIG_REC_IMAGE recognitionImage; errorCount = IG_comm_comp_attach("REC"); errorCount = IG_REC_initialize(); errorCount = IG_load_file("Image.tif", &image); errorCount = IG_REC_image_import(image, &recognitionImage); errorCount = IG_image_delete(image); errorCount = IG_REC_output_codepage_set("Windows ANSI"); errorCount = IG_REC_output_text_format_set(IG_REC_DTXT_TXTS); errorCount = IG_REC_image_recognize(recognitionImage); errorCount = IG_REC_output_direct_text_write(&recognitionImage, 1, "Image.txt"); errorCount = IG_REC_image_delete(recognitionImage); errorCount = IG_REC_close(); } |
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.
Before completing the tutorial steps, complete the preliminary steps outlined in this section:
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)
igcore19 d.dll must be linked to the application using igcore19 d.lib or any other appropriate way. Other dlls do not need to be linked.
The following header files must be included into the code:
C and C++ |
Copy Code
|
---|---|
// Include for ImageGear Core. #include "gear.h" // Include for ImageGear Recognition component. #include "i_rec.h" |
Note that all other ImageGear header files that are referenced from these two must be accessible.
C and C++ |
Copy Code
|
---|---|
AT_ERRCOUNT errorCount; AT_ERRCODE errorCode; HIGEAR image; HIG_REC_IMAGE recognitionImage; AT_INT i; enumIGRecLangEnable languages[IG_REC_LANG_SIZE]; HIG_REC_DOCUMENT document; // To unlock the toolkit for deployment you must call the // IG_lic_solution_name_set, IG_lic_solution_key_set() and possibly the // IG_lic_OEM_license_key_set() functions. // See Licensing section in ImageGear User Manual for more details. // Attach LZW component (if necessary). errorCode = IG_comm_comp_attach("LZW"); // Attach Recognition component. errorCode = IG_comm_comp_attach("REC"); |
C and C++ |
Copy Code
|
---|---|
errorCount = IG_REC_initialize(); |
C and C++ |
Copy Code
|
---|---|
errorCount = IG_load_file("..\\RecognitionC\\Image.tif", &image); errorCount = IG_REC_image_import(image, &recognitionImage); // HIGEAR can be deleted now. IG_image_delete(image); |
C and C++ |
Copy Code
|
---|---|
// Disable all languages. for(i = 0; i < IG_REC_LANG_SIZE; i ++) { languages[i] = IG_REC_LANG_DISABLED; } // Enable English and French. languages[IG_REC_LANG_ENG] = IG_REC_LANG_ENABLED; languages[IG_REC_LANG_FRE] = IG_REC_LANG_ENABLED; // Set English and French recognition languages. nErrCount = IG_REC_languages_set(languages); |
C and C++ |
Copy Code
|
---|---|
// Preprocess the image. nErrCount = IG_REC_image_preprocess(recognitionImage); // Recognize the image. nErrCount = IG_REC_image_recognize(recognitionImage); |
C and C++ |
Copy Code
|
---|---|
// Set Word2000 output format. errorCount = IG_REC_output_format_set("Converters.Text.Word2000"); // Set Windows ANSI code page. errorCount = IG_REC_output_codepage_set("Windows ANSI"); // Set True Page output level. errorCount = IG_REC_output_level_set(IG_REC_OL_TRUEPAGE); |
C and C++ |
Copy Code
|
---|---|
// Create a document. errorCount = IG_REC_document_create(NULL, &document); // Insert a page into the document. // Note that after inserting the page does not need to be deleted. errorCount = IG_REC_document_page_insert(document, recognitionImage, -1); // Save a document into the file in Word2000 format (being set above). errorCount = IG_REC_document_write(document, "Tutorial.DOC"); // Close document. IG_REC_document_close(document); |
C and C++ |
Copy Code
|
---|---|
IG_REC_close(); |
Recognition Component API Reference