【问题标题】:Tessseract returns null in androidTesseract 在 android 中返回 null
【发布时间】:2014-02-23 08:49:35
【问题描述】:

上个月,我开始利用空闲时间使用 Tesseract 库获取一些有关 Android OCR 的知识。我下载了 tess-two 项目和 android ndk。然后我在 ubuntu 机器上构建了 tess-two 项目来创建(.so)文件并成功地得到了它。我只是使用带有 (.so) 库的 tess-two 项目作为我的 android 项目的库。 (我正在 Windows 8 中开发我的项目)。

现在我有一个 android 项目和 tess-two 项目,称为我的项目的库。然后我完成了编码以获取 Image 并将其传递给 TessBaseAPI 对象并在 getUTF8Text() 函数中获取转换结果但是转换需要太多时间但每次都返回 null。

这是我的AsyncTask。拍照后我会在这里传递图像路径

public class Task extends AsyncTask<String, String, String> 
{
    private Context mcontext;
    TessBaseAPI baseAPI=new TessBaseAPI();

    @Override
    protected String doInBackground(String... params) 
    {
        File externalStorageDirectory = Environment
                .getExternalStorageDirectory();
                baseAPI.init(externalStorageDirectory.getAbsolutePath()+
                "/ocrsample/tesseract/", "eng",TessBaseAPI.OEM_TESSERACT_ONLY);
        inspectFromImagePath(picturePath);
        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        Intent i = new Intent(mcontext, ReadActivity.class);
        i.putExtra("result", result);
        mcontext.startActivity(i);
        baseAPI.clear();
    }

    private void inspectFromImagePath(String picturePath) 
    {
        baseAPI.setPageSegMode(PageSegMode.PSM_SINGLE_BLOCK);
        baseAPI.setImage(new File(picturePath));
        String text = baseAPI.getUTF8Text();
        bitmap.recycle();
    }
}

【问题讨论】:

    标签: android android-ndk ocr tesseract


    【解决方案1】:

    您尝试将 resultonPostExecute() 发送到 ReadActivity 类它为空,因为您从 doInBackground 返回 null。所以将返回值更改为一个值或在onPostExecute()中初始化结果

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-25
      • 2021-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      相关资源
      最近更新 更多