简体   繁体   English

通过OCR Tesseract从Image中提取文本 - 错误:无法在baseApi.ini上找到源文件

[英]Extract a text from Image by OCR Tesseract - Error: can't find source file on baseApi.ini

I try to run a simple OCR with tessera. 我尝试用tessera运行一个简单的OCR。 My image is very simple as shown below: 我的图像非常简单,如下所示:

在此输入图像描述

So if it works fine, the output is an extracted text as: SONY TV ... 因此,如果它工作正常,输出是一个提取文本: 索尼电视...

When I run the program on Android, I get the following problem with line: baseApi.init(myDir, "eng"); 当我在Android上运行程序时,我遇到以下问题: baseApi.init(myDir,“eng”);

as it says it couldn't find the source but as shown in the image it is in tssD/tessdata/eng.traineddata. 因为它说它无法找到源,但如图所示,它位于tssD / tessdata / eng.traineddata中。

在此输入图像描述

Here is my original code: 这是我的原始代码:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String myDir= "tssD/tessdata/eng.traineddata";
        String imagePath = "myImages/Remote1.bmp";

        ImageView image = (ImageView) findViewById(R.id.imageView1);
        Bitmap bMap = BitmapFactory.decodeFile(imagePath);

        TessBaseAPI baseApi = new TessBaseAPI();
        baseApi.init(myDir, "eng"); 
        baseApi.setImage(bMap);
        String recognizedText = baseApi.getUTF8Text(); 
        EditText text = (EditText) findViewById(R.id.editText1);
        text.setText(recognizedText);   
        image.setImageBitmap(bMap);
        baseApi.end();
    }

The tssD folder will not be built into your APK and will not be installed on your device. tssD文件夹不会内置到您的APK中,也不会安装在您的设备上。 If you want to include miscellaneous files with your APK, you'll need to put them into assets or res/raw. 如果您想在APK中加入杂项文件,则需要将它们放入资源或res / raw。

You can open a file in assets for reading with something like: 您可以在资源中打开文件以进行阅读,例如:

InputStream input = assetManager.open("sample.txt");

The reference page for the AssetManager is here . AssetManager的参考页面在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM