Add progress monitoring C api

The C API is missing the ability to monitor the progress of the
recognition. This patch adds C wrappers to the progress monitor
that allow monitoring the progress and canceling the recognition
process early.
This commit is contained in:
Jaroslaw Kubik 2018-05-29 23:26:41 +02:00
parent 217e5e5881
commit 87d33b6c9e
2 changed files with 56 additions and 0 deletions

View File

@ -807,3 +807,43 @@ TESS_API float TESS_CALL TessChoiceIteratorConfidence(const TessChoiceIterator*
{
return handle->Confidence();
}
TESS_API ETEXT_DESC* TESS_CALL TessMonitorCreate()
{
return new ETEXT_DESC();
}
TESS_API void TESS_CALL TessMonitorcDelete( ETEXT_DESC* monitor )
{
delete monitor;
}
TESS_API void TESS_CALL TessMonitorSetCancelFunc( ETEXT_DESC* monitor, TessCancelFunc cancelFunc )
{
monitor->cancel = cancelFunc;
}
TESS_API void TESS_CALL TessMonitorSetCancelThis( ETEXT_DESC* monitor, void* cancelThis )
{
monitor->cancel_this = cancelThis;
}
TESS_API void* TESS_CALL TessMonitorGetCancelThis( ETEXT_DESC* monitor )
{
return monitor->cancel_this;
}
TESS_API void TESS_CALL TessMonitorSetProgressFunc( ETEXT_DESC* monitor, TessProgressFunc2 progressFunc )
{
monitor->progress_callback2 = progressFunc;
}
TESS_API int TESS_CALL TessMonitorGetProgress( ETEXT_DESC* monitor )
{
return monitor->progress;
}
TESS_API void TESS_CALL TessMonitorSetDeadlineMSecs( ETEXT_DESC* monitor, int deadline )
{
monitor->set_deadline_msecs( deadline );
}

View File

@ -24,6 +24,7 @@
#ifdef TESS_CAPI_INCLUDE_BASEAPI
# include "baseapi.h"
# include "ocrclass.h"
# include "pageiterator.h"
# include "resultiterator.h"
# include "renderer.h"
@ -104,6 +105,10 @@ typedef enum TessTextlineOrder { TEXTLINE_ORDER_LEFT_TO_RIGHT, TEXTLINE_ORDE
typedef struct ETEXT_DESC ETEXT_DESC;
#endif
typedef bool (*TessCancelFunc)(void* cancel_this, int words);
typedef bool (*TessProgressFunc)(ETEXT_DESC* ths, int left, int right, int top,
int bottom);
struct Pix;
struct Boxa;
struct Pixa;
@ -392,6 +397,17 @@ TESS_API BOOL TESS_CALL TessChoiceIteratorNext(TessChoiceIterator* handle);
TESS_API const char* TESS_CALL TessChoiceIteratorGetUTF8Text(const TessChoiceIterator* handle);
TESS_API float TESS_CALL TessChoiceIteratorConfidence(const TessChoiceIterator* handle);
/* Progress monitor */
TESS_API ETEXT_DESC* TESS_CALL TessMonitorCreate();
TESS_API void TESS_CALL TessMonitorcDelete( ETEXT_DESC* monitor );
TESS_API void TESS_CALL TessMonitorSetCancelFunc( ETEXT_DESC* monitor, TessCancelFunc cancelFunc );
TESS_API void TESS_CALL TessMonitorSetCancelThis( ETEXT_DESC* monitor, void* cancelThis );
TESS_API void* TESS_CALL TessMonitorGetCancelThis( ETEXT_DESC* monitor );
TESS_API void TESS_CALL TessMonitorSetProgressFunc( ETEXT_DESC* monitor, TessProgressFunc progressFunc );
TESS_API int TESS_CALL TessMonitorGetProgress( ETEXT_DESC* monitor );
TESS_API void TESS_CALL TessMonitorSetDeadlineMSecs( ETEXT_DESC* monitor, int deadline );
#ifdef __cplusplus
}
#endif