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.