gpt4 book ai didi

安卓 OCR : Cannot resolve error for getBoundingBox

转载 作者:太空宇宙 更新时间:2023-11-03 10:40:54 27 4
gpt4 key购买 nike

我是一名学生,也是 android 开发的初学者,需要为我的学校项目的联系人管理应用程序执行 android OCR 功能。这是为了将名片中的图像转换为文本。

我在许多论坛上搜索了有关这方面的信息,并找到了几个很好的例子。

目前我在网上找到了一个开源代码,不需要设置ndk和环境变量等来设置。然而,当我将它实现到 eclipse(juno) 中时,出现了一个小错误,我不确定如何解决。

我在谷歌上搜索了很长时间,没有任何结果。因此,决定在这里问问。以下是有错误的代码。

    final class OcrRecognizeAsyncTask extends AsyncTask<Void, Void, Boolean> {

// private static final boolean PERFORM_FISHER_THRESHOLDING = false;
// private static final boolean PERFORM_OTSU_THRESHOLDING = false;
// private static final boolean PERFORM_SOBEL_THRESHOLDING = false;

private CaptureActivity activity;
private TessBaseAPI baseApi;
private byte[] data;
private int width;
private int height;
private OcrResult ocrResult;
private long timeRequired;

OcrRecognizeAsyncTask(CaptureActivity activity, TessBaseAPI baseApi, byte[] data, int width, int height) {
this.activity = activity;
this.baseApi = baseApi;
this.data = data;
this.width = width;
this.height = height;
}

@Override
protected Boolean doInBackground(Void... arg0) {
long start = System.currentTimeMillis();
Bitmap bitmap = activity.getCameraManager().buildLuminanceSource(data, width, height).renderCroppedGreyscaleBitmap();
String textResult;

// if (PERFORM_FISHER_THRESHOLDING) {
// Pix thresholdedImage = Thresholder.fisherAdaptiveThreshold(ReadFile.readBitmap(bitmap), 48, 48, 0.1F, 2.5F);
// Log.e("OcrRecognizeAsyncTask", "thresholding completed. converting to bmp. size:" + bitmap.getWidth() + "x" + bitmap.getHeight());
// bitmap = WriteFile.writeBitmap(thresholdedImage);
// }
// if (PERFORM_OTSU_THRESHOLDING) {
// Pix thresholdedImage = Binarize.otsuAdaptiveThreshold(ReadFile.readBitmap(bitmap), 48, 48, 9, 9, 0.1F);
// Log.e("OcrRecognizeAsyncTask", "thresholding completed. converting to bmp. size:" + bitmap.getWidth() + "x" + bitmap.getHeight());
// bitmap = WriteFile.writeBitmap(thresholdedImage);
// }
// if (PERFORM_SOBEL_THRESHOLDING) {
// Pix thresholdedImage = Thresholder.sobelEdgeThreshold(ReadFile.readBitmap(bitmap), 64);
// Log.e("OcrRecognizeAsyncTask", "thresholding completed. converting to bmp. size:" + bitmap.getWidth() + "x" + bitmap.getHeight());
// bitmap = WriteFile.writeBitmap(thresholdedImage);
// }

try {
baseApi.setImage(ReadFile.readBitmap(bitmap));
textResult = baseApi.getUTF8Text();
timeRequired = System.currentTimeMillis() - start;

// Check for failure to recognize text
if (textResult == null || textResult.equals("")) {
return false;
}
ocrResult = new OcrResult();
ocrResult.setWordConfidences(baseApi.wordConfidences());
ocrResult.setMeanConfidence( baseApi.meanConfidence());
ocrResult.setRegionBoundingBoxes(baseApi.getRegions().getBoxRects());
ocrResult.setTextlineBoundingBoxes(baseApi.getTextlines().getBoxRects());
ocrResult.setWordBoundingBoxes(baseApi.getWords().getBoxRects());
ocrResult.setStripBoundingBoxes(baseApi.getStrips().getBoxRects());

// Iterate through the results.
final ResultIterator iterator = baseApi.getResultIterator();
int[] lastBoundingBox;
ArrayList<Rect> charBoxes = new ArrayList<Rect>();
iterator.begin();
do {
lastBoundingBox =iterator.getBoundingBox(PageIteratorLevel.RIL_SYMBOL);
Rect lastRectBox = new Rect(lastBoundingBox[0], lastBoundingBox[1],
lastBoundingBox[2], lastBoundingBox[3]);
charBoxes.add(lastRectBox);
} while (iterator.next(PageIteratorLevel.RIL_SYMBOL));
iterator.delete();
ocrResult.setCharacterBoundingBoxes(charBoxes);

} catch (RuntimeException e) {
Log.e("OcrRecognizeAsyncTask", "Caught RuntimeException in request to Tesseract. Setting state to CONTINUOUS_STOPPED.");
e.printStackTrace();
try {
baseApi.clear();
activity.stopHandler();
} catch (NullPointerException e1) {
// Continue
}
return false;
}
timeRequired = System.currentTimeMillis() - start;
ocrResult.setBitmap(bitmap);
ocrResult.setText(textResult);
ocrResult.setRecognitionTimeRequired(timeRequired);
return true;
}

@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);

Handler handler = activity.getHandler();
if (handler != null) {
// Send results for single-shot mode recognition.
if (result) {
Message message = Message.obtain(handler, R.id.ocr_decode_succeeded, ocrResult);
message.sendToTarget();
} else {
Message message = Message.obtain(handler, R.id.ocr_decode_failed, ocrResult);
message.sendToTarget();
}
activity.getProgressDialog().dismiss();
}
if (baseApi != null) {
baseApi.clear();
}
}
}

错误在于 do 和 while 循环:

do {
lastBoundingBox = iterator.***getBoundingBox***(PageIteratorLevel.RIL_SYMBOL);
Rect lastRectBox = new Rect(lastBoundingBox[0], lastBoundingBox[1],
lastBoundingBox[2], lastBoundingBox[3]);
charBoxes.add(lastRectBox);
} while (iterator.next(PageIteratorLevel.RIL_SYMBOL));
iterator.***delete***();
ocrResult.setCharacterBoundingBoxes(charBoxes);

在上面加粗的代码中,getBoundingBox 和 delete 有如下错误:

“未为 ResultIterator 类型定义方法 getBoundingBox(int)”

“未为 ResultIterator 类型定义方法 getBoundingBox(int)”

我尝试了几种方法,但就是无法解决问题。如果有任何解决方案,请帮助我,非常感谢。

最佳答案

@SebastianRoth 是对的:您使用的预编译库已过时。我建议安装 NDK 并遵循 build instructions对于 OCR 引擎。这将重新编译库,包括它的 getBoundingBox 方法。

关于安卓 OCR : Cannot resolve error for getBoundingBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34125391/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com