2011-05-01 38 views
1

我目前正在编写一个需要在其中使用OCR的Android应用程序。Android中图像字节表示的字节每像素值

为了达到这个目的,我使用了Tesseract和tesseract-android-tools project

我设法得到的Tesseract API来初始化,需要使用以下setImage功能:

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

我所用的是如何得到正确的值BPP(每像素字节)挣扎, bpl(每行字节数)。 有谁知道我如何获得这些值?我现在已经把相当随机的数值放在那里,并且认为它以后会导致错误。

我应该注意到,该应用程序还使用JavaCV进行图像识别,它正在识别图像,并且使用相同的图像数据来源进行此次tesseract调用。

谢谢。

回答

5

我实际上做了同样的工作。我想你会以某种方式使用相机和相机预览来捕捉屏幕上的OCR识别。 因此,您可以获取相机预览格式,该格式允许您通过PixelFormat检索BytesPerPixel。

我给你一个简单的例子:

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. 

我希望它能帮助。如果您还有其他问题,请立即告诉我。

最良好的祝愿,祝你好运, 沃尔克

+2

我不知道为什么BPL是一个额外的输入。总是不是'bpl = bpp * width'? – 2011-10-04 12:58:20