2

現在、OCR を使用する必要がある Android アプリケーションを作成しています。

これを達成するために、 tesseract-android-tools プロジェクトと組み合わせて Tesseract を使用しています。

Tesseract API を初期化することができたので、次の setImage 関数を使用する必要があります。

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

私が苦労しているのは、bpp (ピクセルあたりのバイト数) と bpl (1 行あたりのバイト数) の正しい値を取得する方法です。これらの値を取得する方法を知っている人はいますか? 現時点ではかなりランダムな値を入力しており、後でエラーが発生すると考えています。

アプリケーションは画像認識に JavaCV も使用しており、画像を正常に認識しており、この tesseract 呼び出しに同じソースの画像データを使用していることに注意してください。

ありがとう。

4

1 に答える 1

7

私は実際に同じことをして、それを機能させました。どういうわけか、カメラとカメラプレビューを使用して、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.

お役に立てば幸いです。ご不明な点がございましたら、今すぐお問い合わせください。

幸運を祈ります、フォルカー

于 2011-05-13T12:41:43.660 に答える