1
votes

I try to run a simple OCR with tessera. My image is very simple as shown below:

enter image description here

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");

as it says it couldn't find the source but as shown in the image it is in tssD/tessdata/eng.traineddata.

enter image description here

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();
    }
1
May be reading something wrong, or unaware of the process, but why are you calling toString on a string?zgc7009
That doesnt make any difference,as it is a stringfarzin parsa
I know, which is why I am wondering why you are doing it. Seems redundant. Not like it is a big deal just extra codezgc7009
Here is not the problem,it is already gonefarzin parsa
I didnt know if there was an explicit reason for using .toString(), was wondering for my own reference. Thought it might just be something weird. Glad you got it to workzgc7009

1 Answers

3
votes

The tssD folder will not be built into your APK and will not be installed on your device. If you want to include miscellaneous files with your APK, you'll need to put them into assets or 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.