title: Android application to convert Image to Text
body: <p>I am trying to develop android application that converts Image to Text using tess-two library, following this tutorial:</p>
  
  <p><a href="http://gaut.am/making-an-ocr-android-app-using-tesseract/" rel="nofollow">http://gaut.am/making-an-ocr-android-app-using-tesseract/</a></p>
  
  <p>but the application gets closed after the picture is taken.</p>
  
  <p>My code is:</p>
  
  <pre><code>protected Button _button;
  protected ImageView _image;
  protected TextView _field;
  protected String _path;
  protected boolean _taken;
  
  protected static final String PHOTO_TAKEN = "photo_taken";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      _image = ( ImageView ) findViewById( R.id.imageView1 );
      _field = ( TextView ) findViewById( R.id.textView1 );
      _button = ( Button ) findViewById( R.id.button1 );
  
  
      _path = Environment.getExternalStorageDirectory() + "/ImageOCR/make_machine_example.jpg";
  
      _button.setOnClickListener( new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              startCameraActivity();
          }
      } );
  }
  
  protected void startCameraActivity()
  {
      File file = new File( _path );
      Uri outputFileUri = Uri.fromFile( file );
  
      Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
      intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );
  
      startActivityForResult( intent, 0 );
  }
  
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) 
  {   
      Log.i( "MakeMachine", "resultCode: " + resultCode );
      switch( resultCode )
      {
          case 0:
              Log.i( "MakeMachine", "User cancelled" );
              break;
  
          case -1:
              onPhotoTaken();
              break;
      }
  }
  
  protected void onPhotoTaken() 
  {
      _taken = true;
  
      BitmapFactory.Options options = new BitmapFactory.Options();
      options.inSampleSize = 2;
  
      Bitmap bitmap = BitmapFactory.decodeFile( _path, options );
      _image.setImageBitmap(bitmap);
  
      _field.setVisibility( View.GONE );
  
      //--------------------------------------------------------
  
      ExifInterface exif;
      try {
          exif = new ExifInterface(_path);
  
          int exifOrientation = exif.getAttributeInt(
                  ExifInterface.TAG_ORIENTATION,
                  ExifInterface.ORIENTATION_NORMAL);
          int rotate = 0;
  
          switch (exifOrientation) {
          case ExifInterface.ORIENTATION_ROTATE_90:
              rotate = 90;
              break;
          case ExifInterface.ORIENTATION_ROTATE_180:
              rotate = 180;
              break;
          case ExifInterface.ORIENTATION_ROTATE_270:
              rotate = 270;
              break;
          }
  
          if (rotate != 0) {
              int w = bitmap.getWidth();
              int h = bitmap.getHeight();
  
              // Setting pre rotate
              Matrix mtx = new Matrix();
              mtx.preRotate(rotate);
           // Rotating Bitmap &amp; convert to ARGB_8888, required by tess
              bitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, false);
  
          }
  
          bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
  
          String DATA_PATH = Environment.getExternalStorageDirectory() + "/tesseract/";
          String lang = "eng";
          TessBaseAPI baseApi = new TessBaseAPI();
          baseApi.init(DATA_PATH, lang);
  
          baseApi.setImage(bitmap);
          String recognizedText = baseApi.getUTF8Text();
          Toast.makeText(this, recognizedText, 4000).show();
          baseApi.end();
  
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
  
      //---------------------------------------------------
  }
  
  @Override
  protected void onSaveInstanceState( Bundle outState ) {
      outState.putBoolean( MainActivity.PHOTO_TAKEN , _taken );
  }
  
  @Override 
  protected void onRestoreInstanceState( Bundle savedInstanceState)
  {
      Log.i( "MakeMachine", "onRestoreInstanceState()");
      if( savedInstanceState.getBoolean( MainActivity.PHOTO_TAKEN ) ) {
          onPhotoTaken();
      }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  </code></pre>
  
  <p>the path for the English language data is shown here:</p>
  
  <pre><code>    /storage/sdcard0/tesseract/tessdata
  </code></pre>
  
  <p>and the logCat window is displaying the following logs:</p>
  
  <pre><code>    03-20 02:24:25.094: D/libEGL(32009): loaded /system/lib/egl/libEGL_mali.so
      03-20 02:24:25.104: D/libEGL(32009): loaded /system/lib/egl/libGLESv1_CM_mali.so
      03-20 02:24:25.104: D/libEGL(32009): loaded /system/lib/egl/libGLESv2_mali.so
      03-20 02:24:25.109: D/(32009): Device driver API match
      03-20 02:24:25.109: D/(32009): Device driver API version: 10
      03-20 02:24:25.109: D/(32009): User space API version: 10 
      03-20 02:24:25.109: D/(32009): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct     16 15:37:13 KST 2012 
      03-20 02:24:25.144: D/OpenGLRenderer(32009): Enabling debug mode 0
      03-20 02:24:33.689: W/IInputConnectionWrapper(32009): showStatusIcon on inactive   InputConnection
      03-20 02:24:41.469: I/MakeMachine(32009): resultCode: -1
      03-20 02:24:41.469: I/System.out(32009): Not a DRM File, opening notmally
      03-20 02:24:41.469: I/System.out(32009): buffer returned 
      03-20 02:24:41.499: D/dalvikvm(32009): GC_FOR_ALLOC freed 60K, 8% free 12302K/13319K, paused 25ms, total 26ms
      03-20 02:24:41.514: I/dalvikvm-heap(32009): Grow heap (frag case) to 20.515MB for   7990288-byte allocation
      03-20 02:24:41.534: D/dalvikvm(32009): GC_CONCURRENT freed 3K, 5% free 20101K/21127K, paused 12ms+2ms, total 22ms
      03-20 02:24:41.534: D/dalvikvm(32009): WAIT_FOR_CONCURRENT_GC blocked 6ms
      03-20 02:24:41.959: D/dalvikvm(32009): GC_FOR_ALLOC freed 37K, 5% free 20077K/21127K, paused 10ms, total 10ms
      03-20 02:24:41.989: I/dalvikvm-heap(32009): Grow heap (frag case) to 28.108MB for  7990288-byte allocation
      03-20 02:24:42.019: D/dalvikvm(32009): GC_CONCURRENT freed &lt;1K, 4% free 27880K/28935K, paused 13ms+2ms, total 27ms
      03-20 02:24:42.019: D/dalvikvm(32009): WAIT_FOR_CONCURRENT_GC blocked 14ms
      03-20 02:24:42.134: D/dalvikvm(32009): GC_FOR_ALLOC freed &lt;1K, 4% free 27880K/28935K, paused 12ms, total 12ms
      03-20 02:24:42.144: I/dalvikvm-heap(32009): Grow heap (frag case) to 35.728MB for 7990288-byte allocation
      03-20 02:24:42.174: D/dalvikvm(32009): GC_CONCURRENT freed &lt;1K, 3% free 35683K/36743K, paused 12ms+2ms, total 28ms
      03-20 02:24:42.174: D/dalvikvm(32009): WAIT_FOR_CONCURRENT_GC blocked 1ms
      03-20 02:24:42.189: D/dalvikvm(32009): Trying to load lib /data/data/com.example.imageocr/lib/liblept.so 0x42664f40
      03-20 02:24:42.199: D/dalvikvm(32009): Added shared lib /data/data/com.example.imageocr/lib/liblept.so 0x42664f40
      03-20 02:24:42.204: D/dalvikvm(32009): Trying to load lib /data/data/com.example.imageocr/lib/libtess.so 0x42664f40
      03-20 02:24:42.259: D/dalvikvm(32009): Added shared lib /data/data/com.example.imageocr/lib/libtess.so 0x42664f40
      03-20 02:24:42.259: I/Tesseract(native)(32009): Attempting Init() with dir=/storage/sdcard0/tesseract/, lang=eng
      03-20 02:24:42.269: A/libc(32009): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread        32009 (xample.imageocr)
  </code></pre>