1

I am trying to run Demo App for OCR using tess-two but i am having problem with code:

I have follow these following steps:

Firstly i have downloaded and install the ndk from here https://developer.android.com/tools/sdk/ndk/index.html. And I configured it successfully Then I Download it "tess-two-master" from here https://github.com/rmtheis/tess-two and i extract it, in that location i run ndk-build command and it compiled successfully also. Then i Open a completely new Android Studio project and follow these instructions https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle from section "Configure tess-two with gradle" In the last step I go in "File -> Project Structure -> Select a module from the left subwindow -> Dependencies (last tab) ->Press the green "+" on your right -> Module Dependency -> OK"

After that i have downloaded this project https://github.com/GautamGupta/Simple-Android-OCR and I copy&paste in my new project the code in these files: "SimpleAndroidOCRActivity.java", "main.xml", "strings.xml". Of course my files had different names (in my case "MainActivity.java", "activity_main.xml", "strings.xml") so some renaming in the code was necessary. I also opened my "AndroidManifest.xml" and I add at the end (but before "/manifest") between "/application" and "/manifest" in the just downloaded "AndroidManifest.xml" (it means that I have add it "uses-permissions" and "uses-feature" tag).

Last step I have downloaded from here https://code.google.com/p/tesseract-ocr/downloads/list the file in the english language. and in the folder of my project excatly in "app-->src-->main". I have created here a new folder and name it "assets". Inside that folder i have created another folder named "tessdata". and i put it there my .traineddata file.

Then when i am trying to sync it, i am having following error: Warning:Dependency OCR3:app:unspecified on project tess-two resolves to an APK archive which is not supported as a compilation dependency. File: C:\Users\jana-PC\AndroidStudioProjects\OCR3\app\build\outputs\apk\app-release-unsigned.apk

When i am trying to compile it, it doesn't compile because it is showing me error that TessBaseAPI cannot resolve symbol:

My code in this part is:

import com.googlecode.tesseract.android.TessBaseAPI;



        TessBaseAPI baseApi = new TessBaseAPI();
        baseApi.setDebug(true);
        baseApi.init(DATA_PATH, lang);
        baseApi.setImage(bitmap);

        String recognizedText = baseApi.getUTF8Text();

        baseApi.end(); 

Anyone with some help, i would be very grateful !!

Jana
  • 68
  • 1
  • 7

3 Answers3

1

Have you tried this solution: https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle

LUMI888
  • 63
  • 4
  • Yes i have tried, but when import module(tess-two) and call it import com.googlecode.tesseract.android.TessBaseAPI; then it is showing error that Cannot resolve symbol. And when i click Alt+Enter, it is showing two suggestions 1. "Add dependency on module tess-two" and 2. move "com.googlecode.tesseract.android.TessBaseAPI" from module "tess-two" to app. What should I do !!!?? – Jana May 28 '15 at 22:33
1

To use the tess-two api, you must first add this line to your app:gradle file in you android project

compile 'com.rmtheis:tess-two:7.0.0'

Add this line and sync the project again and I'm sure your problems will be solved.

0

Gradle dependency management is what helped me out;

I was getting unresolved symbols when attempting to import tess-two;

I experienced unresolved symbols during import of tess-two to an android as well. Figured out that i had to import tess-two as a 'Gradle Project', not as an 'Android .aar' or as an 'Android library'; This meant i had to choose the top-level project-level directory of the tess-two project as the import directory, rather than individual sub-project 'tess-two' within the tess-two project;

Finally determined that gradle syncs the tess-two project by use of gradle build file at the project level of tess -two; But if you import the tess-two subprojects, the project-level gradle.build of tess-two never fully resolves the dependencies underneath the tess-two project; Hope this helps;