Using and opencv IplImage returns a tilde '~'

152 views
Skip to first unread message

igm

unread,
Aug 10, 2010, 8:06:46 AM8/10/10
to tesseract-ocr
Hello,

I am trying to use an IplImage in the method BeginPageUpright but it
always returns the same tilde '~' caracter and just only one.

IplImage *plate = cvLoadImage(argv[1]);
TessDllAPI api(argc > 3 ? argv[3] : "eng");
api.BeginPageUpright(plate->width, plate->height, (unsigned
char*)plate->imageData);
ETEXT_DESC* output = api.Recognize_all_Words();

I searched in the other discussions but and some people said that if
you change the line 72 of the file docqual.cpp from "EXTERN BOOL_VAR
(unlv_tilde_crunching, TRUE," to "EXTERN BOOL_VAR
(unlv_tilde_crunching, FALSE," it should resolve the problem but not
in my case. I have rebuild the solution and it returns the same fu..ng
tilde. LOL.

The code i am using is the same as the dlltest. I don't know what to
say by this time. Can you help me?

Thanks in advance.

Regards.



Jimmy O'Regan

unread,
Aug 10, 2010, 1:40:12 PM8/10/10
to tesser...@googlegroups.com

You're making a poor assumption about image formats being equivalent
across libraries. They rarely are. You'll need to convert the IplImage
to the format used by SetImage (used internally by BeginPageUpright).
For example, if plate->align == 1, you'll need to convert it to the 0
format, you'll have to provide bpp, etc., and I don't think tess will
handle the 32-bit floating point bpp values.


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

Jimmy O'Regan

unread,
Aug 10, 2010, 1:40:54 PM8/10/10
to tesser...@googlegroups.com

Oh, and there are 7 letters in 'fucking'.

igm

unread,
Aug 11, 2010, 5:23:15 AM8/11/10
to tesseract-ocr
After some hours I can answer my own question...

The imageData of IplImage is aligned 4 or 8 bytes in order to enhance
the processing speed. For example, let’s say you have a color image of
size 98-by-98 (pixel depth 8 bits) and imageData is aligned 4 bytes.
The size of each row will not be 98×3=294 bytes but 296 bytes. The
widthStep of IplImage shows the actual size of aligned image row in
bytes. This can help us access imageData correctly. Here is a code
that copy imageData to a user-created buffer.

// create a temp buffer
unsigned char *buffer,*temp2;
buffer = new unsigned char[plate->width*plate->height*plate-
>nChannels];
temp2 = buffer;
// pointer to imageData
unsigned char *temp1 = (unsigned char*) plate->imageData;

// copy imagedata to buffer row by row
for(int i=0;i<plate->height;i++)
{
memcpy(temp2, temp1, plate->width*plate->nChannels);
// imageData jump to next line
temp1 = temp1 + plate->widthStep;
// buffer jump to next line
temp2 = temp2+ plate->width*plate->nChannels;
}

TessDllAPI api("eng");
api.BeginPageUpright(plate->width, plate->height, buffer, 8);
ETEXT_DESC* output = api.Recognize_all_Words();


I hope it helps you.

A good answer returns a good result.
Reply all
Reply to author
Forward
0 new messages