1

I am starting off simple with tess-two in Android Studio (after I managed to import the pre-compiled version of Tesseract into my project!) so I keep adding single lines and moving forward...

In strings.xml under values under res, I have defined the following data path:

<string name="data_path">/usr/local/Cellar/tesseract/3.05.01/share/tessdata/eng.traineddata</string>

However, the baseApi.init line crashes my Empty Activity app that would normally build to device and say Hello World.

What am I doing wrong?

public class MainActivity extends AppCompatActivity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Attempt to initialize the API.
        TessBaseAPI baseApi = new TessBaseAPI();

        // Initialize the language training file path.
        // See 'strings.xml' under 'values' under 'res'.
        String DATA_PATH = getString(R.string.data_path);

        baseApi.init(DATA_PATH, "eng"); // <-- TessAndroid has stopped!
    }
}
  • 1
    One thing to note is that `data_path` needs to be a path that exists on your Android device. – rmtheis Jul 28 '17 at 19:42
  • @rmtheis Thanks for the tip. I thought similar to a Unity3D project that copies this file to device via `StreamingAssets`, AndroidStudio would do the same when building to device... How do I do that? Do I need to do so manually using something like `SmartSwitch`? Or somehow in my AndroidStudio code? –  Aug 06 '17 at 10:51
  • 1
    You can use AssetManager to copy the files to the device storage. See my android-ocr project for an [example](https://github.com/rmtheis/android-ocr/blob/c7a8bfc7e0f38279f147aa68826c93cfac8fe579/OCRTest/src/main/java/edu/sfsu/cs/orange/ocr/OcrInitAsyncTask.java#L601) of this. – rmtheis Aug 06 '17 at 14:25
  • @rmtheis Thanks, but in your example, there is no mention of `AssetManager`... Also, there is no `asset` folder in my `AndroidStudio` app. Is this something I should create manually? –  Aug 13 '17 at 12:37
  • 1
    [`getAssets()`](https://github.com/rmtheis/android-ocr/blob/c7a8bfc7e0f38279f147aa68826c93cfac8fe579/OCRTest/src/main/java/edu/sfsu/cs/orange/ocr/OcrInitAsyncTask.java#L619) returns an `AssetManager`; Yes – rmtheis Aug 25 '17 at 23:16

0 Answers0