Skip to content

Commit 917e994

Browse files
committed
extend ETEXT_DESC by progress_callback
1 parent ed6ae9b commit 917e994

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

ccmain/control.cpp

+16-4
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,22 @@ bool Tesseract::RecogAllWordsPassN(int pass_n, ETEXT_DESC* monitor,
224224
if (w > 0) word->prev_word = &(*words)[w - 1];
225225
if (monitor != NULL) {
226226
monitor->ocr_alive = TRUE;
227-
if (pass_n == 1)
228-
monitor->progress = 30 + 50 * w / words->size();
229-
else
230-
monitor->progress = 80 + 10 * w / words->size();
227+
if (pass_n == 1) {
228+
// monitor->progress = 30 + 50 * w / words->size();
229+
monitor->progress = 70 * w / words->size();
230+
if (monitor->progress_callback != NULL) {
231+
TBOX box = pr_it->word()->word->bounding_box();
232+
(*monitor->progress_callback)(monitor->progress,
233+
box.left(), box.right(),
234+
box.top(), box.bottom());
235+
}
236+
} else {
237+
monitor->progress = 70 + 30 * w / words->size();
238+
if (monitor->progress_callback!=NULL) {
239+
(*monitor->progress_callback)(monitor->progress,
240+
0, 0, 0, 0);
241+
}
242+
}
231243
if (monitor->deadline_exceeded() ||
232244
(monitor->cancel != NULL && (*monitor->cancel)(monitor->cancel_this,
233245
words->size()))) {

ccutil/ocrclass.h

+5
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,17 @@ typedef struct { /*single character */
101101
* the OCR engine is storing its output to shared memory.
102102
* During progress, all the buffer info is -1.
103103
* Progress starts at 0 and increases to 100 during OCR. No other constraint.
104+
* Additionally the progress callback contains the bounding box of the word that
105+
* is currently being processed.
104106
* Every progress callback, the OCR engine must set ocr_alive to 1.
105107
* The HP side will set ocr_alive to 0. Repeated failure to reset
106108
* to 1 indicates that the OCR engine is dead.
107109
* If the cancel function is not null then it is called with the number of
108110
* user words found. If it returns true then operation is cancelled.
109111
**********************************************************************/
110112
typedef bool (*CANCEL_FUNC)(void* cancel_this, int words);
113+
typedef bool (*PROGRESS_FUNC)(int progress,
114+
int left, int right, int top, int bottom);
111115

112116
class ETEXT_DESC { // output header
113117
public:
@@ -117,6 +121,7 @@ class ETEXT_DESC { // output header
117121
volatile inT8 ocr_alive; // ocr sets to 1, HP 0
118122
inT8 err_code; // for errcode use
119123
CANCEL_FUNC cancel; // returns true to cancel
124+
PROGRESS_FUNC progress_callback; // called whenever progress increases
120125
void* cancel_this; // this or other data for cancel
121126
struct timeval end_time; // time to stop. expected to be set only by call
122127
// to set_deadline_msecs()

0 commit comments

Comments
 (0)