【问题标题】:Bytes Per Pixel value for byte representation of image in AndroidAndroid中图像字节表示的每像素字节值
【发布时间】:2011-05-01 23:55:42
【问题描述】:

我目前正在编写一个需要在其中使用 OCR 的 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 调用中使用了相同的图像数据源。

谢谢。

【问题讨论】:

    标签: android ocr tesseract


    【解决方案1】:

    我实际上做了同样的事情并让它工作。我想您会以某种方式使用相机和相机预览来捕获屏幕以进行 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.
    

    我希望它有所帮助。如果您还有其他问题,请现在告诉我。

    祝你好运, 沃尔克

    【讨论】:

    • 我不确定为什么 bpl 是一个额外的输入。 bpl=bpp*width 不是一直都在吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-26
    • 1970-01-01
    • 2012-03-25
    • 2017-05-05
    • 1970-01-01
    相关资源
    最近更新 更多