获取数据目录路径(android) [英] Get path of data directory(android)

查看:133
本文介绍了获取数据目录路径(android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用tesseract ocr.为了使用tesseract,我需要使用多个语言文件,这些文件位于名为"tessdata"的目录中.

I am using tesseract ocr in my app. In order to use tesseract i need to use several language files that are located at a directory called - 'tessdata'.

这是我的方法代码:

    public String detectText(Bitmap bitmap) {
    TessBaseAPI tessBaseAPI = new TessBaseAPI();
    String DATA_PATH = Environment.getRootDirectory().getPath() + "/tessdata/";

    tessBaseAPI.setDebug(true);
    tessBaseAPI.init(DATA_PATH, "eng"); //Init the Tess with the trained data file, with english language

    tessBaseAPI.setImage(bitmap);

    String text = tessBaseAPI.getUTF8Text();

    tessBaseAPI.end();

    return text;
}

我使用了许多变体:

String DATA_PATH = Environment.getRootDirectory().getPath() + "/tessdata/";

,并且每次应用程序失败时均出现找不到路径"异常. 我需要一个好方法将这个目录放在android手机中,并获取它的路径,而不管它是哪部手机.现在,可以在应用程序根目录中找到"tessdata"目录.

and every time the app fails with "path not found" exception. I need a good way to put this directory in the android phone and get the path of it regardless of which phone it is. Right now the 'tessdata' directory can be found at the app root directory.

我该怎么做?

推荐答案

不要在DATA_PATH变量中包含"/tessdata/" -只需保留该部分,但请确保子文件夹位于<指定的目录中c1>.

Don't include "/tessdata/" in your DATA_PATH variable--just leave that part off, but be sure that subfolder exists within the directory specified by DATA_PATH.

这篇关于获取数据目录路径(android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆