Skip to content

Commit

Permalink
Add progress monitoring C api
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jaroslaw Kubik committed May 29, 2018
1 parent 217e5e5 commit 87d33b6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/api/capi.cpp
Expand Up @@ -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 );
}
16 changes: 16 additions & 0 deletions src/api/capi.h
Expand Up @@ -24,6 +24,7 @@

#ifdef TESS_CAPI_INCLUDE_BASEAPI
# include "baseapi.h"
# include "ocrclass.h"
# include "pageiterator.h"
# include "resultiterator.h"
# include "renderer.h"
Expand Down Expand Up @@ -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,

This comment has been minimized.

Copy link
@stweil

stweil Jun 9, 2018

Contributor

These two lines currently break the compilation with C compilers (see issue #1652). We have to add #include <stdbool.h> to make it work again.

int bottom);

struct Pix;
struct Boxa;
struct Pixa;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 87d33b6

Please sign in to comment.