1

here is my code to convert the picture taken from the camera into text using tesseract's java wrapper tess4j! i have included the jar files added them to my path! code does not show any syntax errors! i launch the default camera it starts i take picture and it is shown in the image view i declared however the editbox seems empty though it should show the result of OCR!

package your.apnakaam.namespace;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.graphics.Bitmap;
import android.widget.ImageView;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.util.Log;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.io.File;
import java.io.File;
import net.sourceforge.tess4j.*;
public class KaamsekhaActivity extends Activity 
{
    private static final int CAMERA_REQUEST = 1888; 
        private ImageView imageView;
//**************************************************************************************************
private Intent data;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.main);
    setContentView(R.layout.apna_layout);
    Button capt_but = (Button)findViewById(R.id.capture_btn);
    this.imageView = (ImageView)this.findViewById(R.id.picture);

    capt_but.setOnClickListener(new View.OnClickListener()
    {
        //@Override
    // TODO Auto-generated method stub          
             public void onClick(View v)
             {
                 Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
                 startActivityForResult(cameraIntent, CAMERA_REQUEST); 
             }
    }); 
}
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {  
       if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) 
       {  
            Bitmap photo = (Bitmap) data.getExtras().get("data"); 
            imageView.setImageBitmap(photo);
            void myfunction()
       }  
    }
    public void myfunction()
    {
        TextView disp = (TextView)findViewById(R.id.editText1);
        File new_pic = (File) data.getExtras().get("data");
        Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
        try 
        {   
            String result = instance.doOCR(new_pic);
            disp.setText(result);
        } 
        catch (TesseractException e)
        {
            System.err.println(e.getMessage());
        }
    }

}

I can't figure out whats wrong with the code!

2
  • I don't understand your code. Where are you calling myfunction? Commented Nov 4, 2012 at 11:53
  • 1
    Please post the actual code you are using. "void myfunction()" will not even compile so I know it's not the code you have in your project. Commented Nov 4, 2012 at 18:11

1 Answer 1

1

The function doOCR takes a buffered image that is not possible while working in android! Bufferedimage uses IIOimage that is used in java but not in android!

Sign up to request clarification or add additional context in comments.

1 Comment

Boy, you sure like to use lots of exclamation points! I believe Google Docs can convert a picture to OCR directly! Look here! The only restriction is you need Android 3 or higher! 'Hope that helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.