我正在使用 ResultIterator 从图像中获取每个单词,但我在调用 iterator.begin()
时出错。我不知道为什么。
这是我当前的代码,
//Global
ArrayList<String> words = new ArrayList<String>();
@Override
public void onPreviewFrame(final byte[] data, Camera camera) {
final SurfaceView surfaceView = (SurfaceView) getActivity().findViewById(R.id.cameraView);
//get camera params for ocr
Camera.Parameters cameraParams = _camera.getParameters();
int width = surfaceView.getWidth();
int height = surfaceView.getHeight();
PixelFormat pixFormat = new PixelFormat();
PixelFormat.getPixelFormatInfo(cameraParams.getPreviewFormat(), pixFormat);
int bpp = pixFormat.bytesPerPixel;
int bpl = bpp * width;
//ocr
ocr.setImage(data, width, height, bpp, bpl);
ocr.setRectangle(0, 50, width, height - 50);
// Iterate through the results.
final ResultIterator iterator = ocr.getResultIterator();
iterator.begin(); //crashes my app
do {
words.add(iterator.getUTF8Text(PageIteratorLevel.RIL_WORD));
} while (iterator.next(PageIteratorLevel.RIL_WORD));
}
最佳答案
根据 Tesseract 的 APIExample
,您需要调用 Recognize
方法才能获取迭代器。您可能需要为 tess-two
实现此方法。
另一个地方是通过hOCR
输出。参见 Export HOCR output for tesseract OCR in android .
关于android - 如何在tess-two android中获取识别文本的每个单词和边界框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22589660/