Question

Last month I started working on my leisure time to get some knowledge about Android OCR using Tesseract Library. I downloaded tess-two project & android ndk. Then I built that tess-two project on an ubuntu machine to create (.so) files and successfully got that. I just use that tess-two project with (.so) libs as library for my android project. (I am developing my project in windows 8).

Now I have an android project and tess-two project refered as Library for my project. Then I had done coding to get Image and pass it to TessBaseAPI object and get converted result in getUTF8Text() function But it takes too much time to convert but return null every time.

This is my AsyncTask.After picture taken I will pass the image path here

public class Task extends AsyncTask<String, String, String> 
{
    private Context mcontext;
    TessBaseAPI baseAPI=new TessBaseAPI();

    @Override
    protected String doInBackground(String... params) 
    {
        File externalStorageDirectory = Environment
                .getExternalStorageDirectory();
                baseAPI.init(externalStorageDirectory.getAbsolutePath()+
                "/ocrsample/tesseract/", "eng",TessBaseAPI.OEM_TESSERACT_ONLY);
        inspectFromImagePath(picturePath);
        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        Intent i = new Intent(mcontext, ReadActivity.class);
        i.putExtra("result", result);
        mcontext.startActivity(i);
        baseAPI.clear();
    }

    private void inspectFromImagePath(String picturePath) 
    {
        baseAPI.setPageSegMode(PageSegMode.PSM_SINGLE_BLOCK);
        baseAPI.setImage(new File(picturePath));
        String text = baseAPI.getUTF8Text();
        bitmap.recycle();
    }
}
Was it helpful?

Solution

you try send result from onPostExecute() to ReadActivity class that it's null because you return null from doInBackground. so change return value to one value or initialize result in onPostExecute()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top