2011-05-01 39 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