我使用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));
}发布于 2014-03-23 20:16:05
根据Tesseract的APIExample,在获得迭代器之前,您需要调用Recognize方法。您可能需要为tess-two实现此方法。
另一个地点是通过hOCR输出。参见Export HOCR output for tesseract OCR in android。
https://stackoverflow.com/questions/22589660
复制相似问题