title: I am building a OCR based application in android using tess-two library
body: <p>I am building a OCR based application in android, where the user takes the picture and crops it. The image gets converted into bitmap and then to text but I'm not able to convert the image into text. I think there is an error in getResults().The code for TessOCR class is from stack overflow only. Please help me with this.
  Thank You.</p>
  
  <pre><code>`private void processing1() {
      try {
          Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
          startActivityForResult(captureIntent, CAMERA_CAPTURE);
      } catch (ActivityNotFoundException anfe) {
          String errorMessage = "Whoops - your device doesn't support capturing images!";
          Toast toast = Toast.makeText(Main2Activity.this, errorMessage, Toast.LENGTH_SHORT);
          toast.show();
          btn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  new TessOCR(assetManager);
                  new TessOCR(assetManager).getResults(thePic);
                  intent = getIntent();
                  Bundle bd = intent.getExtras();
                  if(bd != null)
                  {
                      String getName = (String) bd.get("key");
                      tv.setText(getName);
                  }
                  Toast toast = Toast.makeText(Main2Activity.this, "SCANNED", Toast.LENGTH_SHORT);
                  toast.show();
                  new TessOCR(assetManager).onDestroy();
                              }
          });
      }
  }
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (resultCode == RESULT_OK) {
          if (requestCode == CAMERA_CAPTURE) {
              picUri = data.getData();
              performCrop();
          } else if (requestCode == PIC_CROP) {
              Bundle extras = data.getExtras();
               thePic = extras.getParcelable("data");
              picView.setImageBitmap(thePic);
                           }
      }
  }
          private void performCrop() {
      try {
          Intent cropIntent = new Intent("com.android.camera.action.CROP");
           cropIntent.setDataAndType(picUri, "image/*");
           cropIntent.putExtra("crop", "true");
           cropIntent.putExtra("aspectX", 1);
          cropIntent.putExtra("aspectY", 1);
          cropIntent.putExtra("outputX", 256);
          cropIntent.putExtra("outputY", 256);
          cropIntent.putExtra("return-data", true);
          startActivityForResult(cropIntent, PIC_CROP);
      } catch (ActivityNotFoundException anfe) {
          String errorMessage = "Whoops - your device doesn't support the crop action!";
          Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
          toast.show();
      }
  }`
  </code></pre>
  
  <p>My TessOCR class is below </p>
  
  <pre><code> `public static final String DATA_PATH = Environment
                  .getExternalStorageDirectory().toString() + "/AndroidOCR/";
          public static final String lang = "eng";
          private static final String TAG = "TESSERACT";
          private AssetManager assetManager;
          private TessBaseAPI mTess;
      Context context;
          public TessOCR(AssetManager assetManager) {
              Log.i(TAG, DATA_PATH);
              this.assetManager = assetManager;
              String[] paths = new String[]{DATA_PATH, DATA_PATH + "tessdata/"};
              for (String path : paths) {
                  File dir = new File(path);
                  if (!dir.exists()) {
                      if (!dir.mkdirs()) {
                          Log.v(TAG, "ERROR: Creation of directory " + path + " on sdcard failed");
                          return;
                      } else {
                          Log.v(TAG, "Created directory " + path + " on sdcard");
                      }
                  }
              }
              if (!(new File(DATA_PATH + "tessdata/" + lang + ".traineddata")).exists()) {
                  try {
                      InputStream in = assetManager.open("tessdata/" + lang + ".traineddata");
                      OutputStream out = new FileOutputStream(new File(DATA_PATH + "tessdata/", lang + ".traineddata"));
                      byte[] buf = new byte[1024];
                      int len;
                      while ((len = in.read(buf)) != -1) {
                          out.write(buf, 0, len);
                      }
                      in.close();
                      out.close();
                      Log.v(TAG, "Copied " + lang + " traineddata");
                  } catch (IOException e) {
                      Log.e(TAG, "Was unable to copy " + lang + " traineddata " + e.toString());
                  }
              }
              mTess = new TessBaseAPI();
              mTess.setDebug(true);
              mTess.init(DATA_PATH, lang);
          }
      public String getResults(Bitmap bitmap) {
          mTess.setImage(bitmap);
          String result = mTess.getUTF8Text();
          Intent intent = new Intent(context, Main2Activity.class);
          intent.putExtra(result,"key");
          return result;
      }
      public void onDestroy() {
          if (mTess != null)
              mTess.end();
      }
  }`
  </code></pre>