#include "ltocr.h"
L_LTOCR_API L_INT EXT_FUNCTION L_OcrAutoRecognizeManager_RunJobAsync(autoRecognizeManager, autoRecognizeJob)
L_OcrAutoRecognizeManager autoRecognizeManager; | handle to the OCR auto recognize manager |
L_OcrAutoRecognizeJob autoRecognizeJob; | handle to the OCR auto recognize job |
Runs a job asynchronously.
Parameter | Description |
---|---|
autoRecognizeManager | Handle to the OCR engine auto recognize manager. |
autoRecognizeJob | Handle to the OCR engine auto recognize job. |
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
This method will create an internal worker thread and return control immediately to the caller. When the job is completed, you can call L_OcrAutoRecognizeJob_GetErrors to get any errors that might occurred during the recognition process. To get notification when the job is completed (whether successfully or with aborted due to errors or through user action), use the L_OcrAutoRecognizeManager_SetRunJobCallback method.
To run a job synchronously, use L_OcrAutoRecognizeManager_RunJob.
To use this method, initialize a new L_OcrAutoRecognizeJobData structure with the job's parameters (input image file name, pages, output document format, output document name, optional zones file name, etc.), then use L_OcrAutoRecognizeManager_CreateJob to create the L_OcrAutoRecognizeJob handle passed as job handle to this method. Finally, call L_OcrAutoRecognizeManager_RunJob passing the L_OcrAutoRecognizeJob handle.
This method will perform the following operations:
The L_OcrAutoRecognizeManager also has some options that you can control, For more information about these options, refer to L_OcrAutoRecognizeManager_GetOptions and L_OcrAutoRecognizeManager_SetOptions.
Required DLLs and Libraries
LTOCR For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application. |
#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName
#define OCR_ADVANTAGE_RUNTIME_DIR TEXT("C:\\LEADTOOLS 19\\Bin\\Common\\OcrAdvantageRuntime")
/* Structure used for the callback function's user data */
typedef struct tagJOBCBPARM
{
L_OcrAutoRecognizeManager AutoRecognizeManager;
L_BOOL jobCompleted;
} JOBCBPARM, * LPJOBCBPARM;
static L_INT EXT_CALLBACK runJobCB(const L_OcrAutoRecognizeRunJobCallbackData* data, L_VOID* userData)
{
JOBCBPARM* param = (JOBCBPARM*)userData;
param->jobCompleted = data->IsCompleted;
if(data->Status == ERROR_USER_ABORT)
{
L_OcrAutoRecognizeManager_AbortAllJobs(param->AutoRecognizeManager);
param->jobCompleted = L_TRUE;
}
return SUCCESS;
}
L_INT L_OcrAutoRecognizeManager_RunJobAsyncExample()
{
L_INT retCode = -1;
L_OcrEngine ocrEngine = NULL;
L_OcrAutoRecognizeManager autoRecognizeManager = 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
std::cout << "Starting up the engine...\n";
retCode =L_OcrEngine_Startup(ocrEngine, NULL, OCR_ADVANTAGE_RUNTIME_DIR);
if(retCode != SUCCESS)
return retCode;
// Get the AutoRecognizeManager
L_OcrEngine_GetAutoRecognizeManager(ocrEngine, &autoRecognizeManager);
L_OcrAutoRecognizeJob autoRecognizeJob = NULL;
L_OcrAutoRecognizeJobData jobData;
jobData.StructSize = sizeof(L_OcrAutoRecognizeJob);
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");
// Create the job
L_OcrAutoRecognizeManager_CreateJob(autoRecognizeManager, &autoRecognizeJob, &jobData);
// Create the callback user data to be updated
JOBCBPARM userData;
userData.jobCompleted = L_FALSE;
userData.AutoRecognizeManager = autoRecognizeManager;
// Run the job in a thread and wait for it to be done
// We will use the callback to get notified when the job is finished
L_OcrAutoRecognizeManager_SetRunJobCallback(autoRecognizeManager, &runJobCB, &userData);
std::cout << "Running the job...\n";
L_OcrAutoRecognizeManager_RunJobAsync(autoRecognizeManager, autoRecognizeJob);
std::cout << "Waiting for the job to complete...\n";
while(userData.jobCompleted != L_TRUE)
{
Sleep(100);
}
std::cout << "Done...\n";
//CLEANUP
L_OcrAutoRecognizeJob_Destroy(autoRecognizeJob);
L_OcrEngine_Destroy(ocrEngine);
return retCode;
}