souleateryx / tesseract-android-tools

Automatically exported from code.google.com/p/tesseract-android-tools
0 stars 0 forks source link

Throw exception for unsupported Bitmap types #20

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Try to make an application that uses tesseract-android-tools as a library. 
2. In the main application, attach the code that I have written below. In the 
res/drawable-hdpi include a file that you want to test
3.

What is the expected output? What do you see instead?
I expect the letters of the image that I am trying to test. Instead I never get 
any output. I know that the nativeSetImagePix function is not called upon. 
Thats all I can understand.

However, please note that the tests for tesseract given in 
tesseract-android-tools-tests ran successfully. The problem here is sending 
Bitmaps to decode for text.

What version of the product are you using? On what operating system?
tesseract-3.00
Android 2.2
Ubuntu 11.04

Please provide any additional information below.

package iitgn.ocr;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import com.googlecode.tesseract.android.TessBaseAPI;

public class Trial1Activity extends Activity {

    private static final String TESSBASE_PATH = "/mnt/sdcard/tesseract/";
    private static final String DEFAULT_LANGUAGE = "eng";
    private static final String EXPECTED_FILE = TESSBASE_PATH + "tessdata/" + DEFAULT_LANGUAGE
            + ".traineddata";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final TessBaseAPI baseApi = new TessBaseAPI();
        baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);
        final Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.digits);
//digits is a .jpg image I found in one of the issues here.
        ImageView img = (ImageView) findViewById(R.id.imageView1);
        img.setImageBitmap(bmp);//I can see the ImageView. So we know that it should work if I sent it to the setImage()
        baseApi.setImage(bmp);
        Log.v("Kishore","Kishore:Working");//This statement is never reached. Futhermore, on putting some more Log.v commands in the setImage function, I found out that the native function nativeSetImagePix is never accessed. I have attached the Logcat output below to show that it is not accessed.

        String outputText = baseApi.getUTF8Text();
        Log.v("Kishore","Kishore:"+outputText);
        baseApi.end();
        bmp.recycle();
    }
}

Original issue reported on code.google.com by kish...@iitgn.ac.in on 6 Oct 2011 at 11:03

GoogleCodeExporter commented 8 years ago
Sorry. I forgot to include the logcat details. Here they are:

10-06 16:33:46.921: VERBOSE/Tesseract(native)(18050): 
Java_com_googlecode_tesseract_android_TessBaseAPI_nativeClassInit
10-06 16:33:46.921: VERBOSE/Tesseract(native)(18050): 
Java_com_googlecode_tesseract_android_TessBaseAPI_nativeConstruct
10-06 16:33:46.931: VERBOSE/Tesseract(native)(18050): 
Java_com_googlecode_tesseract_android_TessBaseAPI_nativeInit
10-06 16:33:46.931: INFO/Tesseract(native)(18050): Attempting Init() with 
dir=/mnt/sdcard/tesseract/, lang=eng
10-06 16:33:47.041: INFO/Tesseract(native)(18050): Initialized Tesseract API 
with language=eng
10-06 16:33:47.041: VERBOSE/Kishore(18050): Kishore:Accessed
10-06 16:33:47.041: DEBUG/dalvikvm(18050): Trying to load lib 
/data/data/iitgn.ocr/lib/liblept.so 0x4601cdb8
10-06 16:33:47.041: DEBUG/dalvikvm(18050): Shared lib 
'/data/data/iitgn.ocr/lib/liblept.so' already loaded in same CL 0x4601cdb8
10-06 16:33:47.041: DEBUG/AndroidRuntime(18050): Shutting down VM
10-06 16:33:47.041: WARN/dalvikvm(18050): threadid=1: thread exiting with 
uncaught exception (group=0x400259f8)
10-06 16:33:47.051: ERROR/AndroidRuntime(18050): FATAL EXCEPTION: main

Original comment by kish...@iitgn.ac.in on 6 Oct 2011 at 11:04

GoogleCodeExporter commented 8 years ago
Well, I figured this out. It is not the nativeSetImagePix that wasnt being 
accessed. There was a problem in reading the file in the readBitmap function 
because the bitmap wasnt in the ARGB_8888 format. 
This piece of code is required instead:
final TessBaseAPI baseApi = new TessBaseAPI();
        baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);
//        baseApi.setPageSegMode(TessBaseAPI.PSM_SINGLE_LINE);
        BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
        final Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.digits, opt);
        ImageView img = (ImageView) findViewById(R.id.imageView1);
        img.setImageBitmap(bmp);
        baseApi.setImage(bmp);

Original comment by kish...@iitgn.ac.in on 6 Oct 2011 at 11:45

GoogleCodeExporter commented 8 years ago

Original comment by alanv@google.com on 11 Sep 2012 at 8:36

GoogleCodeExporter commented 8 years ago
Check already exists in ReadFile.readBitmap().

Original comment by alanv@google.com on 14 Sep 2012 at 6:37