Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in loading eng.traineddata (3.01) using com.android.content.res.AssetManager() #40

Open
GoogleCodeExporter opened this issue Dec 25, 2015 · 6 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. I put the latest eng.traineddata file in the android "asset" folder
2. This is the code for copying the traineddata file from the "asset" folder to 
the sd-card.

        File tessdata=new File(DEFAULT_DATA_PATH+"tessdata/"+DEFAULT_LANG+".traineddata");
        if(!tessdata.exists()){
            try {
                tessdata.createNewFile();
                InputStream in=packageResource.getAssets().open(DEFAULT_LANG+".traineddata");

                OutputStream out=new FileOutputStream(tessdata);
                byte[] buffer = new byte[1024];
                int read;
                while((read = in.read(buffer)) != -1){
                  out.write(buffer, 0, read);
                }

                in.close();
                in = null;
                out.flush();
                out.close();
                out = null;
            } catch (Exception e) {
                e.printStackTrace();
                Log.e("tag", e.getMessage());
            }

        }
3.

What is the expected output? What do you see instead?
   I expect to copy bytes from the eng.traineddata file using inputstream.read(byte[]) but an IOException come out from the native level.I tried to do the same thing copying bytes from the file using java.io.FileInputStream() and everything is OK.I think the error concerns with Android.

What version of the product are you using? On what operating system?
  tesseract-android-tools....1.0
  tesseract..................3.01
  leptonica-.................1.69

    Windows 7 32 bits

Please provide any additional information below.
     The following are the Log-cat output on the IOException:
(My project package name is"com.balancecharger")

10-24 12:18:27.108: W/System.err(8898): java.io.IOException
10-24 12:18:27.118: W/System.err(8898):     at 
android.content.res.AssetManager.readAsset(Native Method)
10-24 12:18:27.118: W/System.err(8898):     at 
android.content.res.AssetManager.access$700(AssetManager.java:36)
10-24 12:18:27.118: W/System.err(8898):     at 
android.content.res.AssetManager$AssetInputStream.read(AssetManager.java:571)
10-24 12:18:27.148: W/System.err(8898):     at 
com.balancecharger.Converter.convertBitmapToString(Converter.java:41)
10-24 12:18:27.179: W/System.err(8898):     at 
com.balancecharger.MainActivity$2.onClick(MainActivity.java:144)
10-24 12:18:27.188: W/System.err(8898):     at 
android.view.View.performClick(View.java:2408)
10-24 12:18:27.188: W/System.err(8898):     at 
android.view.View$PerformClick.run(View.java:8816)
10-24 12:18:27.208: W/System.err(8898):     at 
android.os.Handler.handleCallback(Handler.java:587)
10-24 12:18:27.208: W/System.err(8898):     at 
android.os.Handler.dispatchMessage(Handler.java:92)
10-24 12:18:27.228: W/System.err(8898):     at 
android.os.Looper.loop(Looper.java:123)
10-24 12:18:27.248: W/System.err(8898):     at 
android.app.ActivityThread.main(ActivityThread.java:4627)
10-24 12:18:27.268: W/System.err(8898):     at 
java.lang.reflect.Method.invokeNative(Native Method)
10-24 12:18:27.268: W/System.err(8898):     at 
java.lang.reflect.Method.invoke(Method.java:521)
10-24 12:18:27.278: W/System.err(8898):     at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-24 12:18:27.298: W/System.err(8898):     at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-24 12:18:27.308: W/System.err(8898):     at 
dalvik.system.NativeStart.main(Native Method)


Original issue reported on code.google.com by [email protected] on 24 Oct 2012 at 8:04

@GoogleCodeExporter
Copy link
Author

One thing I left to mention is that the IOException comes out where 
in.read(bytes);..And the Exception will not occur when I use an image file in 
the place of eng.traineddata file and everything runs OK.

Original comment by [email protected] on 24 Oct 2012 at 8:08

@GoogleCodeExporter
Copy link
Author

what's the packageResource in sentence:
InputStream in=packageResource.getAssets().open(DEFAULT_LANG+".traineddata");

I tried with
 InputStream in=getAssets().open(DEFAULT_LANG+".traineddata");
and it turns out alright.

Original comment by [email protected] on 24 Oct 2012 at 9:27

@GoogleCodeExporter
Copy link
Author

  I put all the above codes into only one function in a separate class so that I have to pass Resources() object (here packageResource) from main Activity() class into the function.... I've tried both with getResources().getAssets().open(DEFAULT_LANG+".traineddata"); and getResources().openRawResource(R.id.eng);. ...Both of them gave the same IOException() on calling the in.read(bytes) function.

Original comment by [email protected] on 25 Oct 2012 at 9:24

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

I've decided to put the "eng.trainedata" file bytes into an array of C++ file 
and embed into the compiled library file.But the file size is more than 3MB.I 
haven't tested but I'm worried about the performance issue.Any ideas please 
help!

Original comment by [email protected] on 30 Oct 2012 at 9:39

@GoogleCodeExporter
Copy link
Author

You need to put your traineddata file in "asset/tessdata". Looks like thats 
where you are trying to copy from.

1. I put the latest eng.traineddata file in the android "asset" folder
2. This is the code for copying the traineddata file from the "asset" folder to 
the sd-card. 

        File tessdata=new File(DEFAULT_DATA_PATH+"tessdata/"+DEFAULT_LANG+".traineddata");

Original comment by [email protected] on 19 Nov 2012 at 6:39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant