title: Error: Assertion failed (src.type() == CV_8UC1 || src.type() == CV_8UC3 || src.type() == CV_8UC4) in Android Kotlin
body: <p>I want to detect the corners in　a video.</p>
  <p>To do so,I first grayscaled the video frames and applied the corner detection method there.</p>
  <p>However, I got the following error:</p>
  <blockquote>
  <p>E/cv::error(): OpenCV(4.6.0) Error: Assertion failed (src.type() ==
  CV_8UC1 || src.type() == CV_8UC3 || src.type() == CV_8UC4) in
  Java_org_opencv_android_Utils_nMatToBitmap2</p>
  </blockquote>
  <p>The code I wrote is below.The language is Kotlin.
  Could anyone please explain the solution? Thank you.</p>
  <pre><code>class MainActivity : AppCompatActivity() {
  
      @RequiresApi(Build.VERSION_CODES.P)
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
          OpenCVLoader.initDebug()
  
          val videoView = findViewById&lt;VideoView&gt;(R.id.videoView)
          val imgView = findViewById&lt;ImageView&gt;(R.id.imageView)
  
          //set Video to videoView
          val uri = Uri.parse(&quot;android.resource://&quot; + getPackageName() + &quot;/&quot; + R.raw.video_name)
          videoView.setVideoURI(uri)
          videoView.start();
  
  
          val retriever = MediaMetadataRetriever()
          var bitmap = MediaMetadataRetriever.BitmapParams()
          val context = applicationContext
          retriever.setDataSource(context, uri)
  
          //get frame
          val frameNum =
              retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_FRAME_COUNT)
  
  
          
          thread(){
              try{
                  for (i in 1..frameNum!!.toInt()) {
  
                      //get frame
                      var bitframe = retriever.getFrameAtIndex(i)
                      val f_width = bitframe!!.width
                      val f_height = bitframe!!.height
  
                      //Mat
                      var srcMat: Mat = Mat.zeros(f_height, f_width, CV_8UC1)
                      var grayMat: Mat = Mat.zeros(f_height, f_width, CV_8UC1)
                      var bitMat: Mat = Mat.zeros(f_height, f_width, CV_8UC1)
                      var cornerMat:Mat = Mat.zeros(f_height, f_width, CV_8UC1)
  
                      //bitframe to srcMat
                      Utils.bitmapToMat(bitframe, srcMat)
  
                      //grayScale
                      Imgproc.cvtColor(srcMat, grayMat, Imgproc.COLOR_BGR2GRAY)
                      
                      Imgproc.cornerHarris(grayMat,cornerMat,3,5,0.5)
  
          Utils.matToBitmap(cornerMat, bitframe)
          Handler(Looper.getMainLooper()).post {
              imgView.setImageBitmap(bitframe)
          }
       }
  }
  
  
  </code></pre>
  <p>activity_main.xml is below.</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout 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;VideoView
          android:id=&quot;@+id/videoView&quot;
          android:layout_width=&quot;396dp&quot;
          android:layout_height=&quot;258dp&quot;
          android:layout_marginTop=&quot;16dp&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  
      &lt;ImageView
          android:id=&quot;@+id/imageView&quot;
          android:layout_width=&quot;382dp&quot;
          android:layout_height=&quot;244dp&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@+id/videoView&quot;
          tools:srcCompat=&quot;@tools:sample/avatars&quot; /&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>