L_OcrEngine_GetAutoRecognizeManager

Summary

Returns a handle to the OCR auto recognize manager.

Syntax

#include "ltocr.h"

L_LTOCR_API L_INT EXT_FUNCTION L_OcrEngine_GetAutoRecognizeManager(engine, autoRecognizeManager)

Parameters

L_OcrEngine engine

Handle to the OCR engine.

L_OcrAutoRecognizeManager* autoRecognizeManager

Pointer to L_OcrAutoRecognizeManager handle to be updated.

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

This function returns a handle to the OCR engine auto recognize manager that allow you to do one shot "fire and forget" OCR operations.

The L_OcrAutoRecognizeManager provides methods to convert a single or multipage image file to an OCR'ed document using one call. This could be desired when the default setting of the engine provides the required final document and no fine tuning is required.

The L_OcrAutoRecognizeManager also provide support for callbacks to monitor the various OCR operations, logging and tracing as well as allowing the user to abort at any time.

Required DLLs and Libraries

See Also

Functions

Topics

Example

static void LogMessage(const wchar_t* message, ...) 
{ 
   const unsigned int bufferSize = 1024 * 4; 
   wchar_t buffer[bufferSize]; 
 
   if(message != NULL) 
   { 
      va_list ap; 
      va_start(ap, message); 
      vswprintf_s(buffer, message, ap); 
      va_end(ap); 
   } 
   else 
   { 
      wcscpy_s(buffer, L""); 
   } 
 
   _tprintf(buffer); 
} 
 
static L_VOID EXT_CALLBACK MyAutoRecognizeTraceWriteLineCallback(L_OcrAutoRecognizeJob job, L_OcrTraceCategory category, const L_TCHAR* message, L_VOID* /*userData*/) 
{ 
   static const L_TCHAR* categoryNames[] = 
   { 
      L_TEXT("Info"), 
      L_TEXT("Warning"), 
      L_TEXT("Error") 
   }; 
 
   L_OcrAutoRecognizeJobData jobData = {0}; 
   jobData.StructSize = sizeof(L_OcrAutoRecognizeJobData); 
   L_OcrAutoRecognizeJob_GetJobData(job, &jobData); 
   LogMessage(L"Job:%s %s Thread:0x%08X - %s\n", jobData.JobName, categoryNames[category], GetCurrentThreadId(), message); 
} 
 
L_INT L_OcrEngine_GetAutoRecognizeManagerExample() 
{ 
   //Files to process 
   L_TCHAR *imageFiles[]    = {MAKE_IMAGE_PATH(L_TEXT("OCR1.tif")),  
      MAKE_IMAGE_PATH(L_TEXT("OCR2.tif")),  
      MAKE_IMAGE_PATH(L_TEXT("OCR3.tif")),  
      MAKE_IMAGE_PATH(L_TEXT("OCR4.tif"))}; 
   // Output files 
   L_TCHAR *documentFiles[] = {MAKE_IMAGE_PATH(L_TEXT("OCR1.pdf")),  
      MAKE_IMAGE_PATH(L_TEXT("OCR2.pdf")),  
      MAKE_IMAGE_PATH(L_TEXT("OCR3.pdf")),  
      MAKE_IMAGE_PATH(L_TEXT("OCR4.pdf"))}; 
 
   L_INT retCode = -1; 
   L_OcrEngine ocrEngine = NULL; 
   L_OcrAutoRecognizeManager autoRecognizeManager = NULL; 
   L_OcrAutoRecognizeManagerOptions autoRecognizeOptions = { 0 }; 
   L_OcrDocumentManager ocrDocumentManager = NULL; 
 
   std::cout << "Creating an instance of the engine...\n"; 
 
   // Create an instance of the engine 
   retCode = L_OcrEngineManager_CreateEngine(L_OcrEngineType_LEAD, &ocrEngine); 
   if(retCode != SUCCESS) 
      return retCode; 
 
   // Start the engine using default parameters 
   std::cout << "Starting up the engine...\n"; 
   L_OcrEngine_Startup(ocrEngine, NULL, OCR_LEAD_RUNTIME_DIR); 
 
   // Get the AutoRecognizeManager 
   L_OcrEngine_GetAutoRecognizeManager(ocrEngine, &autoRecognizeManager); 
 
   // Set the options we want 
   autoRecognizeOptions.StructSize = sizeof(L_OcrAutoRecognizeManagerOptions); 
   L_OcrAutoRecognizeManager_GetOptions(autoRecognizeManager, &autoRecognizeOptions); 
 
   // Use maximum CPUs/cores of current machine to speed up recognition 
   autoRecognizeOptions.UseThreads = true; 
 
   // Deskew and auto-orient all pages before recognition 
   autoRecognizeOptions.PreprocessPageCommands = L_OcrAutoPreprocessPageCommands_Deskew | L_OcrAutoPreprocessPageCommands_Rotate; 
 
   // Enable the Trace Callback 
   autoRecognizeOptions.TraceCallback = MyAutoRecognizeTraceWriteLineCallback; 
 
   // Give the manager our updated settings 
   L_OcrAutoRecognizeManager_SetOptions(autoRecognizeManager, &autoRecognizeOptions); 
 
   // Create PDFs with Image/Text option 
   L_OcrEngine_GetDocumentManager(ocrEngine, &ocrDocumentManager); 
   DOCWRTPDFOPTIONS pdfOptions; 
   pdfOptions.Options.uStructSize = sizeof(DOCWRTPDFOPTIONS); 
   L_OcrDocumentManager_GetFormatOptions(ocrDocumentManager, DOCUMENTFORMAT_PDF, &pdfOptions.Options); 
 
   // Set the specific PDF options we want 
   pdfOptions.bImageOverText = true; 
   pdfOptions.PdfProfile = DOCWRTPDFPROFILE_PDF; 
 
   // Give the engine our updated PDF options 
   L_OcrDocumentManager_SetFormatOptions(ocrDocumentManager, DOCUMENTFORMAT_PDF, &pdfOptions.Options); 
 
   // Loop through all the TIF files & convert to PDF 
   for(int index=0; index < _countof(imageFiles); index++) 
   { 
      // OCR each file 
      std::wcout << L"Processing " << imageFiles[index] << std::endl; 
      L_OcrAutoRecognizeManager_Run(autoRecognizeManager, imageFiles[index], documentFiles[index], DOCUMENTFORMAT_PDF, NULL); 
      std::wcout << "Saved: " << documentFiles[index] << std::endl; 
   } 
 
   //CLEANUP 
   L_OcrEngine_Destroy(ocrEngine); 
 
   return SUCCESS; 
} 
Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS OCR Module - LEAD Engine C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.