title: OpenCV app - Android camera keeps showing black screen
body: <p><strong>Background</strong></p>
  <p>I had started out this project on Android Studio with the intent of creating a OpenCV application that could process frames using the camera on my OnePlus android device. After running the application, I was gratified to see it finally launch on my device. However, the application shows up with a black screen where the camera preview should be. Here is my code for my MainActivity, activity_main, and AndroidManifest files:</p>
  <p>EDIT: While the application launched on my device, I did give the application permission to use camera</p>
  <p><strong>MainActivity.java</strong></p>
  <pre><code>package com.example.cv;
  
  import androidx.appcompat.app.AppCompatActivity;
  
  import android.os.Bundle;
  import android.util.Log;
  import android.view.SurfaceView;
  
  import org.opencv.android.BaseLoaderCallback;
  import org.opencv.android.CameraBridgeViewBase;
  import org.opencv.android.JavaCameraView;
  import org.opencv.android.OpenCVLoader;
  import org.opencv.core.Core;
  import org.opencv.core.CvType;
  import org.opencv.core.Mat;
  import org.opencv.imgproc.Imgproc;
  
  public class MainActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2
  {
      private static String TAG = &quot;MainActivity&quot;;
      JavaCameraView javaCameraView;
      Mat mRGBA, mRGBAT;
  
  
      BaseLoaderCallback baseLoaderCallback = new BaseLoaderCallback(MainActivity.this) {
          @Override
          public void onManagerConnected(int status)
          {
              if (status == BaseLoaderCallback.SUCCESS) {
                  javaCameraView.enableView();
              } else {
                  super.onManagerConnected(status);
              }
          }
      };
  
      static
      {
          if (OpenCVLoader.initDebug())
          {
              Log.d(TAG, &quot;OpenCV is Configured or Connected successfully.&quot;);
          }
          else
          {
              Log.d(TAG, &quot;OpenCV not Working or Loaded.&quot;);
          }
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          javaCameraView = (JavaCameraView) findViewById(R.id.my_camera_view);
          javaCameraView.setVisibility(SurfaceView.VISIBLE);
          javaCameraView.setCvCameraViewListener(MainActivity.this);
  
      }
  
      @Override
      public void onCameraViewStarted(int width, int height)
      {
          mRGBA = new Mat(height, width, CvType.CV_8UC4);
      }
  
      @Override
      public void onCameraViewStopped()
      {
          mRGBA.release();
      }
  
      @Override
      public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame)
      {
          mRGBA = inputFrame.rgba();
          mRGBAT = mRGBA.t();
          Core.flip(mRGBA.t(), mRGBAT, 1);
          Imgproc.resize(mRGBAT, mRGBAT, mRGBA.size());
          return mRGBAT;
      }
  
      @Override
      public void onPointerCaptureChanged(boolean hasCapture) {
  
      }
  
  
      @Override
      protected void onDestroy() {
          super.onDestroy();
  
          if (javaCameraView != null)
          {
              javaCameraView.disableView();
          }
      }
  
      @Override
      protected void onPause() {
          super.onPause();
  
          if (javaCameraView != null)
          {
              javaCameraView.disableView();
          }
      }
  
  
      @Override
      protected void onResume() {
          super.onResume();
  
          if (OpenCVLoader.initDebug())
          {
              Log.d(TAG, &quot;OpenCV is Configured or Connected successfully.&quot;);
              baseLoaderCallback.onManagerConnected(BaseLoaderCallback.SUCCESS);
          }
          else
          {
              Log.d(TAG, &quot;OpenCV not Working or Loaded.&quot;);
              OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION, this, baseLoaderCallback);
          }
      }
  }
  </code></pre>
  <p><strong>activity_main.xml</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;RelativeLayout
      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;&gt;
  
  
      &lt;org.opencv.android.JavaCameraView
          android:id=&quot;@+id/my_camera_view&quot;
          android:layout_width=&quot;fill_parent&quot;
          android:layout_height=&quot;fill_parent&quot;
          /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  <p><strong>AndroidManifest.xml</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      package=&quot;com.example.cv&quot;&gt;
  
  
      &lt;uses-permission android:name=&quot;android.permission.CAMERA&quot;/&gt;
      &lt;uses-feature android:name=&quot;android.hardware.camera&quot;/&gt;
      &lt;uses-feature android:name=&quot;android.hardware.camera.autofocus&quot;/&gt;
      &lt;uses-feature android:name=&quot;android.hardware.camera.front&quot;/&gt;
      &lt;uses-feature android:name=&quot;android.hardware.camera.front.autofocus&quot;/&gt;
  
      &lt;application
          android:allowBackup=&quot;true&quot;
          android:icon=&quot;@mipmap/ic_launcher&quot;
          android:label=&quot;@string/app_name&quot;
          android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;
          android:supportsRtl=&quot;true&quot;
          android:theme=&quot;@style/AppTheme&quot;&gt;
          &lt;activity android:name=&quot;.MainActivity&quot;&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  
                  &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>