How to use tesseract in a C++ program?

1,299 views
Skip to first unread message

caro

unread,
Aug 2, 2010, 6:25:55 AM8/2/10
to tesseract-ocr
I already use tesseract OCR with command line directly. It works weel.
And I would like now to integrate it in a C++ program, first under
Linux.
Can anyone help me using it?

And finally, I would like to use it under Windows. I read I have to
use the dll, but I do not know how.

Thank you for your help.

Caroline

Andres

unread,
Aug 2, 2010, 12:55:48 PM8/2/10
to tesser...@googlegroups.com
Hello Caroline,

Look for dlltest.cpp and see what is being done there.
Perhaps others in the list might give you better options.

In Windows:
link with tessdll.lib and be sure to have tessdll.dll in your path

Regards.



2010/8/2 caro <carolin...@gmail.com>

--
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.


caro

unread,
Aug 3, 2010, 7:44:44 AM8/3/10
to tesseract-ocr
Hi Andres,

I tried including the tessdll.lib.
My code is:
/
******************************************************************************/
IplImage* img = cvLoadImage("number36.tif", 0) ; /// load
image into grayscale
if ( img==NULL )
return -1;

TessDllAPI api("eng");
api.BeginPageUpright(img ->width , img ->height , (unsigned
char *)img ->imageData, img ->depth);

ETEXT_DESC *output = api.Recognize_all_Words();
char *buffer = NULL ;
buffer = new char [output->count] ;
if ( buffer == NULL )
return -1;
int i;
for (i = 0; i < output->count; ++i)
{
const EANYCODE_CHAR *ch = &output->text[i];
buffer[i] = ch->char_code ;
}
buffer[i] = '\0';
printf(" OCR: %s\n", buffer);

/
******************************************************************************/

I tried it on an image where we have "36" written, in big caracters,
well segmented, not blured.

When I tried the same image using directly dlltest.exe, it works well,
it recognizes: 36
But with my code (using the lib), it does not work: it recognizes:
'1'ix

Do you have an idea?

Thank you.



On 2 août, 18:55, Andres <andrej...@gmail.com> wrote:
> Hello Caroline,
>
> Look for dlltest.cpp and see what is being done there.
> Perhaps others in the list might give you better options.
>
> In Windows:
> link with tessdll.lib and be sure to have tessdll.dll in your path
>
> Regards.
>
> 2010/8/2 caro <caroline.ma...@gmail.com>
>
> > I already use tesseract OCR with command line directly. It works weel.
> > And I would like now to integrate it in a C++ program, first under
> > Linux.
> > Can anyone help me using it?
>
> > And finally, I would like to use it under Windows. I read I have to
> > use the dll, but I do not know how.
>
> > Thank you for your help.
>
> > Caroline
>
> > --
> > 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<tesseract-ocr%2Bunsu...@googlegroups.com>
> > .

caro

unread,
Aug 3, 2010, 11:07:57 AM8/3/10
to tesseract-ocr
I did some reseach to find out my problem of results difference
between using dlltest.exe and using tessdll.dll in another code
(windows, visual c++).

After some investigations, it seems to be a problem of conversion of
image using openCV.
When I open the image using IMAGE (in dlltest), it works, and OCR is
good.
When I open the image using opencv and IplImage, it does not work.

If someone already encountered this problem and could help me...

Thanking you in advance,
Caroline


On 2 août, 18:55, Andres <andrej...@gmail.com> wrote:
> Hello Caroline,
>
> Look for dlltest.cpp and see what is being done there.
> Perhaps others in the list might give you better options.
>
> In Windows:
> link with tessdll.lib and be sure to have tessdll.dll in your path
>
> Regards.
>
> 2010/8/2 caro <caroline.ma...@gmail.com>
>
> > I already use tesseract OCR with command line directly. It works weel.
> > And I would like now to integrate it in a C++ program, first under
> > Linux.
> > Can anyone help me using it?
>
> > And finally, I would like to use it under Windows. I read I have to
> > use the dll, but I do not know how.
>
> > Thank you for your help.
>
> > Caroline
>
> > --
> > 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<tesseract-ocr%2Bunsu...@googlegroups.com>
> > .

Andres

unread,
Aug 6, 2010, 11:44:50 AM8/6/10
to tesser...@googlegroups.com
Hi Caroline,

Are you passing a IplImage pointer to tesseract ?

Regards,

Andres


2010/8/3 caro <carolin...@gmail.com>
To unsubscribe from this group, send email to tesseract-oc...@googlegroups.com.

Jimmy O'Regan

unread,
Aug 6, 2010, 11:47:58 AM8/6/10
to tesser...@googlegroups.com
On 6 August 2010 16:44, Andres <andr...@gmail.com> wrote:
> Hi Caroline,
>
> Are you passing a IplImage pointer to tesseract ?

That seems like it would be a common enough operation that it might be
worth having (optional, off by default) support for. I don't propose
to do it myself, but as this year's Summer of Code comes to a close,
it might be worth thinking about making an application for next
year's.

--
<Leftmost> jimregan, that's because deep inside you, you are evil.
<Leftmost> Also not-so-deep inside you.

Andres

unread,
Aug 6, 2010, 11:01:28 PM8/6/10
to tesser...@googlegroups.com
Seems a good idea. I was thinking in making it as I need it, but I never found time for that so far...

2010/8/6 Jimmy O'Regan <jor...@gmail.com>

--

Shivshankar Sabat

unread,
Sep 6, 2013, 6:48:45 AM9/6/13
to tesser...@googlegroups.com


HI,
 i m shiba and m using tesseract OCR engine and i want to code it java so how can i code it, please give me any  idea and m very poor in java so please anyone try to help me.

Thnks

shiba
Reply all
Reply to author
Forward
0 new messages