title: OpenCV android: App crashes when applying opencv filter
body: <p>I'm trying to simply load an image and then trying to apply a filter to it using OpenCV, but my app keeps crashing. My image is saved in Drawable as test.jpg.</p>
  <p>To apply the filter, I'm first loading the image to the app using <code>ImageView</code>. This part is working fine. Then, on click of a button, the filter should be applied to the image. As soon as I click the button, the app crashes.</p>
  <p>The code of mainactivity.java is below:</p>
  <pre><code>package com.xyz.hello;
  
  import androidx.appcompat.app.AppCompatActivity;
  
  import android.annotation.SuppressLint;
  import android.graphics.Bitmap;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Toast;
  import android.widget.ImageView;
  import org.opencv.android.OpenCVLoader;
  import org.opencv.android.Utils;
  import org.opencv.core.Mat;
  import org.opencv.core.Size;
  import org.opencv.imgcodecs.Imgcodecs;
  import org.opencv.imgproc.Imgproc;
  
  import java.io.IOException;
  
  public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          OpenCVLoader.initDebug();
      }
  
      public void displayToast(View v){
          Mat img = null;
  
          try {
              img = Utils.loadResource(getApplicationContext(), R.drawable.test);
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          Imgproc.cvtColor(img, img, Imgproc.COLOR_RGB2BGRA);
  
          Mat img_result = img.clone();
          Imgproc.Canny(img, img_result, 80, 90);
          Bitmap img_bitmap = Bitmap.createBitmap(img_result.cols(), img_result.rows(),Bitmap.Config.ARGB_8888);
          Utils.matToBitmap(img_result, img_bitmap);
          ImageView imageView = findViewById(R.id.img);
          imageView.setImageBitmap(img_bitmap);
      }
  
  } 
  </code></pre>
  <p>Also, my .xml file code is below:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
  xmlns:tools=&quot;http://schemas.android.com/tools&quot;
  android:layout_width=&quot;match_parent&quot;
  android:layout_height=&quot;match_parent&quot;
  tools:context=&quot;.MainActivity&quot;
  android:orientation=&quot;vertical&quot;&gt;
  
  
  &lt;Button
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:text=&quot;@string/display_message&quot;
      android:onClick=&quot;displayToast&quot;
      tools:ignore=&quot;HardcodedText&quot; /&gt;
  
  &lt;ImageView
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:src=&quot;@drawable/test&quot;
      android:id=&quot;@+id/img&quot;
      android:adjustViewBounds=&quot;true&quot;&gt;
  
  &lt;/ImageView&gt;
  </code></pre>
  
  <p>Logcat file is repeating this output:</p>
  <pre><code>2021-03-11 22:01:51.979 6551-6623/com.google.android.googlequicksearchbox I/HotwordLSAdapter: getAudioSourceOpeningStatus completed: 102
  2021-03-11 22:01:51.979 6551-6623/com.google.android.googlequicksearchbox W/ErrorReporter: reportError [type: 211, code: 393244, bug: 0]: errorCode: 393244, engine: 0
  2021-03-11 22:01:51.980 6551-6623/com.google.android.googlequicksearchbox I/MicroDetector: Keeping mic open: false
  2021-03-11 22:01:51.980 6551-6623/com.google.android.googlequicksearchbox I/MicroDetector: #shutdownAudioWithAudioLibrary
  2021-03-11 22:01:51.980 6551-13750/com.google.android.googlequicksearchbox E/DeviceStateChecker: DeviceStateChecker cancelled
  2021-03-11 22:01:51.981 6551-6623/com.google.android.googlequicksearchbox I/MicroDetectionWorker: #onError(false)
  2021-03-11 22:01:51.982 6551-6623/com.google.android.googlequicksearchbox I/HotwordLSAdapter: stopListeningStatus result: 109
  </code></pre>