L_OcrAutoRecognizeManager_SetRunJobCallback

#include "ltocr.h"

L_LTOCR_API L_INT EXT_FUNCTION L_OcrAutoRecognizeManager_SetRunJobCallback(autoRecognizeManager, callback, userData)

Use this function to set a callback to get notified when a job is about to start or when a job is completed or aborted.

Parameters

L_OcrAutoRecognizeManager autoRecognizeManager

Handle to the OCR engine auto recognize manager.

L_OcrAutoRecognizeRunJobCallback callback

Pointer to L_OcrAutoRecognizeRunJobCallback function to get notified when a job is about to start or when a job is completed or aborted.

L_VOID* userData

Optional user data to pass to the callback function.

Returns

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

Comments

Use this function to set a callback to get notified when a job is about to start or when a job is completed or aborted.

This callback occurs when a job is about to start or when a job is completed or aborted. For more information about the kind of information you will get during this callback, refer to L_OcrAutoRecognizeRunJobCallbackData.

Required DLLs and Libraries

See Also

Functions

Topics

Example

const L_TCHAR* _ocrOperationNames[] = 
{ 
   L"LoadImage", 
   L"SaveImage", 
   L"PreprocessImage", 
   L"AutoZone", 
   L"Recognize", 
   L"SaveDocumentPrepare", 
   L"SaveDocument", 
   L"SaveDocumentConvertImage", 
   L"Formatting", 
   L"RecognizeOMR", 
}; 
 
L_VOID ShowJobErrors(L_OcrAutoRecognizeJob ocrJob) 
{ 
   // Show the errors 
   L_OcrAutoRecognizeManagerJobError* errors = NULL; 
   L_UINT errorCount = 0; 
   L_OcrAutoRecognizeJob_GetErrors(ocrJob, &errors, &errorCount); 
   std::wcout << L"Errors:" << std::endl; 
   for(L_UINT i = 0; i < errorCount; i++) 
   { 
      const L_OcrAutoRecognizeManagerJobError* error = &errors[i]; 
      std::wcout << L"  page: " << error->ImagePageNumber << L" Operation: " << _ocrOperationNames[error->Operation] << L" code: " << error->ErrorCode << std::endl; 
   } 
 
   L_OcrMemory_Free(errors); 
} 
 
L_INT EXT_CALLBACK MyRunJobCB(const L_OcrAutoRecognizeRunJobCallbackData* data, L_VOID* /*userData*/) 
{ 
   std::wcout << L"MyRunJobCallback fired...\nStatus: " << data->Status << std::endl; 
   if(data->IsCompleted) 
      std::wcout << L"Job completed" << std::endl; 
   else 
      std::wcout << L"Job still in progress" << std::endl; 
 
   if(data->Status != SUCCESS) 
      ShowJobErrors(data->Job); 
 
   return SUCCESS; 
} 
 
L_INT L_OcrAutoRecognizeManager_SetRunJobCallbackExample() 
{ 
   L_INT retCode = -1; 
   L_OcrEngine ocrEngine = NULL; 
   L_OcrAutoRecognizeManager autoRecognizeManager = NULL; 
   L_OcrAutoRecognizeManagerOptions autoRecognizeOptions = { 0 }; 
   L_OcrAutoRecognizeJob autoRecognizeJob = NULL; 
 
   // Create an instance of the engine 
   retCode = L_OcrEngineManager_CreateEngine(L_OcrEngineType_Advantage, &ocrEngine); 
   if(retCode != SUCCESS) 
      return retCode; 
 
   // Start the engine using default parameters 
   retCode =L_OcrEngine_Startup(ocrEngine, NULL, OCR_ADVANTAGE_RUNTIME_DIR); 
   if(retCode != SUCCESS) 
      return retCode; 
 
   // 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; 
 
   // Give the manager our updated settings 
   L_OcrAutoRecognizeManager_SetOptions(autoRecognizeManager, &autoRecognizeOptions); 
 
   L_OcrAutoRecognizeJobData jobData; 
   jobData.StructSize = sizeof(L_OcrAutoRecognizeJobData); 
   wcscpy_s(jobData.ImageFileName, MAKE_IMAGE_PATH(L_TEXT("OCR1.tif"))); 
   wcscpy_s(jobData.DocumentFileName, MAKE_IMAGE_PATH(L_TEXT("OCR1.pdf"))); 
   jobData.Format = DOCUMENTFORMAT_PDF; 
   wcscpy_s(jobData.JobName, L"MyJob"); 
   jobData.FirstPageNumber = 1; 
   jobData.LastPageNumber = -1; 
   jobData.UserData = NULL; 
   wcscpy_s(jobData.ZonesFileName, L_TEXT("")); 
   L_OcrAutoRecognizeManager_CreateJob(autoRecognizeManager, &autoRecognizeJob, &jobData); 
 
   L_OcrAutoRecognizeRunJobCallback runJobCallback; 
   L_OcrAutoRecognizeManager_GetRunJobCallback(autoRecognizeManager, &runJobCallback, NULL); 
   if(runJobCallback == NULL) 
   { 
      // Add our callback handler 
      L_OcrAutoRecognizeManager_SetRunJobCallback(autoRecognizeManager, &MyRunJobCB, NULL); 
   } 
 
   // Run the job 
   retCode = L_OcrAutoRecognizeManager_RunJob(autoRecognizeManager, autoRecognizeJob); 
 
   //CLEANUP 
   L_OcrAutoRecognizeJob_Destroy(autoRecognizeJob); 
   L_OcrEngine_Destroy(ocrEngine); 
 
   return retCode; 
} 
Help Version 21.0.2021.7.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

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