Wrappers for tessearct3.01?

380 views
Skip to first unread message

devTess

unread,
Feb 8, 2011, 3:20:53 AM2/8/11
to tesseract-ocr
Hi, I like to know if there is any on-going wrappers being developed.
I mean those applications that access the tessearct 3.01 api and not
the tesseract3.01.exe.

I am trying to figure out what are the basic sequential steps needed
to call the tessearct3.01 api.

I know the existence of tessearct-develop forum, I am hoping to cover
more ground.
I am also aware of some of the efforts of wrapper development for
tessearct 2.04, it seems that the significant changes in tesseract3.01
had made the upgrading a significant task. I therefore like to hear
from others of the potential issues.

Thanks

Dmitry Silaev

unread,
Feb 8, 2011, 4:02:32 AM2/8/11
to tesser...@googlegroups.com
My engine uses both methods. For automated training it employs "tesseract.exe" and other training tools. For automatic recognition it uses Tesseract as a statically linked module called via TessBaseAPI.

Using TessBaseAPI is relatively easy, for instance (pseudocode):

Init(datapath, language, OcrEngineMode);
[ SetPageSegMode(PageSegMode); ]
[ SetVariable(name, value); ... ]
SetImage(image_bits, image_width, image_height, bits_per_pixel, image_pitch);
[ SetRectangle(left, top, width, height); ]
( GetUTF8Text() | Recognize() | other_recognition_procedure() )
copy_result_into_your_application_structures();
End();

As for the tesseract-dev group, they state that "this group is intended for tesseract developers to share information on updates, improvements...". For such questions as yours the present group is suited better, I think. However it seems to me, the dev team posts in the "-dev" group more often.

The biggest changes (in my case) were changes in the training data file format (not much of a problem if you have source box/tiff pairs) and mostly incompatible API (baseapi.h). Yet I can witness version 3.0x has more elaborated API, is much more stabile and produces more expected results.

Warm regards,
Dmitry Silaev





--
You received this message because you are subscribed to the Google Groups "tesseract-ocr" group.
To post to this group, send email to tesser...@googlegroups.com.
To unsubscribe from this group, send email to tesseract-oc...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/tesseract-ocr?hl=en.


devTess

unread,
Feb 8, 2011, 10:44:13 AM2/8/11
to tesseract-ocr
Hi Dimitry, with the guidelines provided from you, I prepared a strong
cup of coffee and start reading the top part of baseapi.h

Q1
Init(datapath, language, OcrEngineMode);
What is the normal setting of OcrEngineMode?

I try to use the :Recognize(ETEXT_DESC* monitor) method.
>>> There are two PARTS to the Recognize method

Part ONE:
Q2: which of the following is USED In normal running mode of
tessearct.exe to recognize text

if (tesseract_->tessedit_resegment_from_line_boxes)
page_res_ = tesseract_->ApplyBoxes(*input_file_, true,
block_list_);
else if (tesseract_->tessedit_resegment_from_boxes)
page_res_ = tesseract_->ApplyBoxes(*input_file_, false,
block_list_);
else
page_res_ = new PAGE_RES(block_list_, &tesseract_-
>prev_word_best_choice_); <<My guess>
if (tesseract_->tessedit_make_boxes_from_boxes) {
tesseract_->CorrectClassifyWords(page_res_);
return 0;
}

Part TWO:
Q3: which of the following is USED In normal running mode of
tessearct.exe to recognize text
if (tesseract_->interactive_mode) {
tesseract_->pgeditor_main(rect_width_, rect_height_, page_res_);
// The page_res is invalid after an interactive session, so
cleanup
// in a way that lets us continue to the next page without
crashing.
delete page_res_;
page_res_ = NULL;
return -1;
} else if (tesseract_->tessedit_train_from_boxes) {
tesseract_->ApplyBoxTraining(*output_file_, page_res_);
} else if (tesseract_->tessedit_ambigs_training) {
FILE *training_output_file = tesseract_-
>init_recog_training(*input_file_);
// OCR the page segmented into words by tesseract.
tesseract_->recog_training_segmented(
*input_file_, page_res_, monitor, training_output_file);
fclose(training_output_file);
} else {
// Now run the main recognition.
tesseract_->recog_all_words(page_res_, monitor, NULL, NULL, 0);
<<My guess>
}

Dmitry Silaev

unread,
Feb 9, 2011, 1:43:43 AM2/9/11
to tesser...@googlegroups.com
devTess be careful with coffee, don't overdose ))

> Q1
> Init(datapath, language, OcrEngineMode);
> What is the normal setting of OcrEngineMode?

Currently OEM_OcrEngineMode = TESSERACT_ONLY would be sufficient for all cases.

> Q2: which of the following is USED In normal running mode of
> tessearct.exe to recognize text

The values of the variables you can see within the code of Recognize()
(e.g. tesseract_->tessedit_resegment_from_boxes) are often loaded from
config files. Usually recognition runs with no config files at all, so
you can assume all these variables to be "false". In that way you can
examine the control paths and figure out what procedures get called at
the recognition stage.

> Q3: which of the following is USED In normal running mode of
> tessearct.exe to recognize text

You meant "to train" - copy-paste. Training is a 2-stage process:

1) Making box files. Requires two config files: "batch.nochop" and "makebox"

2) Generation of .tr files. Needs "nobatch" and "box.train"

You can find the above configs inside the tessdata/configs and
tessdata/tessconfigs directories in Tess's distribution. Check these
files and you'll understand what usually happens while training. Plain
old step-by-step debugging is also of use ))

Warm regards,
Dmitry Silaev

devTess

unread,
Feb 15, 2011, 9:34:28 PM2/15/11
to tesseract-ocr
Question:
where can I find out more about (see below)

&tesseract_->prev_word_best_choice_


What is the purpose of doing that?
Why is it that it is not sufficient just to

page_res_ = new PAGE_RES(block_list_);

Thank you.
=================================================

int TessBaseAPI::RecognizeText(ETEXT_DESC* monitor) {

if (tesseract_ == NULL)
return -1;
if (page_res_ != NULL)
delete page_res_;

block_list_ =FindLinesCreateBlockList();

tesseract_->SetBlackAndWhitelist();
recognition_done_ = true;

page_res_ = new PAGE_RES(block_list_, &tesseract_-
>prev_word_best_choice_);

// Now run the main recognition.
tesseract_->recog_all_words(page_res_, monitor, NULL, NULL, 1);

return 0;
}

Dmitry Silaev

unread,
Feb 16, 2011, 12:52:48 AM2/16/11
to tesser...@googlegroups.com
devTess,

I'd not ask questions like this as Tess is undergoing transition from the old code base and is under hard development of new features. I've no enough time to investigate but the "prev_word_best_choice_" data member seems to be related to best segmentation search based on the language model.

Instead of rummaging in Tess's guts I'd better use a pretty convenient and high-level interface provided by "ResultIterator" (see GetIterator() in "baseapi.h" and then read all comments in "resultiterator.h" and "pageiterator.h")

Warm regards,
Dmitry Silaev





--

devTess

unread,
Feb 18, 2011, 11:53:46 AM2/18/11
to tesseract-ocr
Hi, I am getting many questions for help on how to make a simple
wrapper, where to find information of many parameter terms used in the
api. I have asked them to address the questions here. The developers
need feedbacks to refine the software.

For clarification, I am struggling to understand myself.

I hope someone who is able to make it work just post the simplest
example on how to use the api beside following the tesseractMain.cpp

I am sure the community would appreciate.

I am trying to understand how to do the core part of the tessnet to
work with version 3.

The codes provided by Remi have shown how to pass the bitmap to native
tessearct image struct Pix.

the challenge now is after many trials, I still could not get pass

the various ways to get the

recog_all_words(page_res_, monitor, NULL, NULL, 1);

works.


Thank you.
Message has been deleted

Cong Nguyen

unread,
Feb 21, 2011, 4:44:59 AM2/21/11
to tesseract-ocr
Dear devTess,

I have just implemented a simple .net wrapper:

http://code.google.com/p/tesseractdotnet/w/list

Hope it's helpful!
Cong.
Message has been deleted

SpeedyChair

unread,
Feb 22, 2011, 11:18:59 AM2/22/11
to tesser...@googlegroups.com
All three messages were received by the list. All Googlegroups mailing list
prevent the sender from receiving his own post back. They figure they never
fail and your own posts returning to you are not necessary. It confuses
many people.

Don Marang
Vinux Software Development Coordinator (vinux.org.uk)

There is just so much stuff in the world that, to me, is devoid of any real
substance, value, and content that I just try to make sure that I am working
on things that matter.
Dean Kamen


--------------------------------------------------
From: "Cong Nguyen" <congng...@gmail.com>
Sent: Monday, February 21, 2011 5:04 AM
To: "tesseract-ocr" <tesser...@googlegroups.com>
Subject: Re: Wrappers for tessearct3.01?

> Sorry, but it's not spam!
>
> I try to send message 3 times, but I cannot see my post! :)
>
> So, I try to post once more....
>
> I have just implemented a simple wrapper here
> http://code.google.com/p/tesseractdotnet/w/list.
> Hope it is helpful.
>
> Cong.

Ray Smith

unread,
Feb 24, 2011, 1:25:56 AM2/24/11
to tesser...@googlegroups.com, Dmitry Silaev
+1 to sticking with the TessBaseAPI + PageIterator + ResultIterator.
Delving too far into the guts is likely to get you into all kinds of trouble, especially as we are making rapid improvements, some of which are quite radical. The idea is that the above 3 APIs give you everything you need.

If recog_all_words isn;t working for you, perhaps you  aren't getting your image into a Pix correctly. Try pixWrite("filename.png", pix, IFF_PNG);
If a common display tool displays the file correctly, then you have created the pix correctly, otherwise you need to learn how to write your image data into a pix.

Ray.

devTess

unread,
Feb 24, 2011, 9:02:38 AM2/24/11
to tesseract-ocr
HI Cong Nguyen,
Exactly what I need.
Would you be implementing delegate event for the monitor class similar
to tessnet2.

Finally, someone did it. Thanks
J.

devTess

unread,
Feb 24, 2011, 9:16:15 AM2/24/11
to tesseract-ocr
Thanks Ray,
After getting helps from different people (Dmitry Silaev and Steve
Pohorsky (his implementation of tessnet for 3.0), yes, your diagnosis
is correct.

With a few examples now available, I can see where were my mistakes.

Thanks to all.
J.


Cong Nguyen

unread,
Feb 24, 2011, 8:23:04 PM2/24/11
to tesser...@googlegroups.com
Dear devTess,

I does not plan to implement delegate event at engine-level, so you should
manage your implementations at high-level.

Example:
....
string result = _ocrProcessor.Apply(bitmap);
List<Word> detectedWords = _ocrProcessor.RetriveResultDetail();
.... // you can raise event/do some things here if you want...

Thanks,
Cong.

-----Original Message-----
From: tesser...@googlegroups.com [mailto:tesser...@googlegroups.com]
On Behalf Of devTess
Sent: Thursday, February 24, 2011 9:03 PM
To: tesseract-ocr
Subject: Re: Wrappers for tessearct3.01?

--

Reply all
Reply to author
Forward
0 new messages