Question

I'm currently writing an Android application which needs to use OCR within it.

To achieve this I am using Tesseract in conjunction with the tesseract-android-tools project.

I have managed to get the Tesseract API to initialize and need to use the following setImage function:

void com.googlecode.tesseract.android.TessBaseAPI.setImage(byte[] imagedata, int width, int height, int bpp, int bpl)

What I am struggling with is how to get the correct values for bpp (bytes per pixel) and bpl (bytes per line). Does anyone know how I can get these values? I have put fairly random values in there at the moment and believe it is causing errors later on.

I should note that the application is also using JavaCV for image recognition which is recognising images fine and I'm using the same source of image data for this tesseract call.

Thanks.

Was it helpful?

Solution

I actually did the same and got it working. I guess you'll use somehow the camera and the camera preview to capture the screen for the OCR recognition. Therefore you can get the camera preview format, which allows you through the PixelFormat to retrieve the BytesPerPixel.

I'll give you a short example:

Camera.Parameters cameraParameters = camera.getParameters(); // retrieve the camera parameters
previewFormat = cameraParameters.getPreviewFormat(); // retrieve the Previewformat according to your camera

PixelFormat pf = new PixelFormat(); // create a PixelFormat object
PixelFormat.getPixelFormatInfo(previewFormat, pf); // get through the previewFormat-int the PixelFormat

int bpp = pf.bytesPerPixel; // save the BytesPerPixel for this Pixelformat
int bpl = bpp*width; // BytesPerLines is just the "BPP * width" of your PreviewFormat/Picture

tess.setImage(imagedata, width, height, bpp, bpl); // setImage with imagedata[], width and height of the previewFormat, etc.

I hope it helps. If you'll have further questions let me now.

Best wishes and good luck, Volker

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top