Bytes Per Pixel value for byte representation of image in Android

余生长醉 提交于 2019-12-08 07:35:48

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/5852300/bytes-per-pixel-value-for-byte-representation-of-image-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!