/** Starts new Activity to display Homography transformation */
  @Override
  public void onClick(View v) {
    if (v.getId() == transformButton.getId()) {
      transformButton.setEnabled(false);

      // Remove all but the two base imagess
      Pair<Bitmap, Bitmap> imagesToAdd = tranBuilder.getWarpedImages();
      if (imagesToAdd == null) {
        // Notify User
        mExpandedImageText.setText("Tranformation is not ready just Yet");
        return;
      } else mExpandedImageText.setText(R.string.show_exp_image);

      mImageAdapter.setWarpedImage(imagesToAdd.first);
      mImageAdapter.setInvertedWarpedImage(imagesToAdd.second);

      // Start transformation process
      transformButton.setEnabled(true);
      // Allow user to look for OCR conversion
      ocrButton.setEnabled(true);
    } else if (v.getId() == ocrButton.getId()) {
      // No support for filePath
      if (ocrIntent == null) return;

      // TODO
      Bitmap warp = tranBuilder.getWarpedImages().first;
      Uri uri = Utility.saveBitmapToFile(warp, WARPED_PATH);
      ocrIntent.putExtra(WARPED_SOURCE_EXTRA, uri);
      startActivity(ocrIntent);
    }
  }
 @Override
 public void OnKeypointsFoundForOther(Mat image) {
   Bitmap disp =
       Bitmap.createBitmap(
           image.cols(), image.rows(), Bitmap.Config.ARGB_8888); // Android uses ARGB_8888
   Utils.matToBitmap(image, disp);
   mImageAdapter.setOtherKeyPointImage(disp);
 }
  @Override
  public void OnHomographyStored(TransformInfo storage) {
    // Draw the key point matches and put in gallery
    Mat matches = storage.getMatchImage();
    // Must convert to Bitmap from Mat
    Bitmap disp =
        Bitmap.createBitmap(
            matches.cols(), matches.rows(), Bitmap.Config.ARGB_8888); // Android uses ARGB_8888
    Utils.matToBitmap(matches, disp);
    mImageAdapter.setPutativeImageWithLinesImage(disp);

    // Ready to show display reset text
    mExpandedImageText.setText(R.string.show_exp_image);
    boolean ready = mCVLibraryInitialized;
    transformButton.setEnabled(ready);
  }
  // Called when a started intent returns
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    String message = null;
    if (resultCode != RESULT_OK) {
      Toast t = Toast.makeText(this, "Failed to load image", Toast.LENGTH_SHORT);
      t.show();
      return;
    }

    // Assign the view to change based on who sent the request
    // There are two positions possibles
    int position = requestCode;

    // Check if file path or uri image source
    String filePath = data.getExtras().getString(BaseImageTaker.INTENT_RESULT_IMAGE_PATH);

    // Depending on how image was obtained,
    // obtain a Bitmap image of object
    // Getting source of the image

    Bitmap image = null;
    // Decode File path f
    if (filePath == null) {
      // query the data
      Uri pickedUri = data.getExtras().getParcelable(BaseImageTaker.INTENT_RESULT_IMAGE_URI);
      image = getBitmapFromURIviaInputStream(getContentResolver(), pickedUri);

      if (ocrIntent == null) {
        // TODO Add class for this intent
        ocrIntent = new Intent(this, DisplayReaderActivity.class);
      }
      // Set the data for
      if (position == 0) {
        // For reference image
        ocrIntent.putExtra(BASE_SOURCE_TYPE_EXTRA, URI_TYPE_EXTRA);
        ocrIntent.putExtra(BASE_SOURCE_EXTRA, pickedUri);
      } else if (position == 1) {
        // For other image
        ocrIntent.putExtra(QUERY_SOURCE_TYPE_EXTRA, URI_TYPE_EXTRA);
        ocrIntent.putExtra(QUERY_SOURCE_EXTRA, pickedUri);
      }

    } else {
      // Assign target dimension to read in images
      int targetWidth = TARGET_HEIGHT;
      int targetHeight = TARGET_WIDTH;

      BitmapFactory.Options bmpOptions = new BitmapFactory.Options();
      bmpOptions.inJustDecodeBounds = true;
      BitmapFactory.decodeFile(filePath, bmpOptions);
      int currHeight = bmpOptions.outHeight;
      int currWidth = bmpOptions.outWidth;

      int sampleSize = 1;
      {
        // use either width or height
        if ((currWidth > currHeight))
          sampleSize = Math.round((float) currHeight / (float) targetHeight);
        else sampleSize = Math.round((float) currWidth / (float) targetWidth);
      }

      bmpOptions.inSampleSize = sampleSize;
      bmpOptions.inJustDecodeBounds = false;
      // decode the file with restricted sizee
      image = BitmapFactory.decodeFile(filePath, bmpOptions);
    }

    // Update the adapter and transform builder
    if (image == null) {
      message = "Null image cannot display";
      Log.e(TAG, message);
      return;
    } else {
      // Display the image in the gallery
      mImageAdapter.setImage(image, position);

      // Update the transformation process
      if (position == 0) tranBuilder.setReferenceImage(image);
      else if (position == 1) tranBuilder.setOtherImage(image);
    }
  }