I am taking the image from android phone's camera and want to do some processing on it .
override fun onPictureTaken(p0: ByteArray?, p1: Camera?) { Log.i(TAG, "on picture taken") Observable.just(p0) .subscribeOn(proxySchedule) .subscribe { val pictureSize = p1?.parameters?.pictureSize Log.i(TAG, "picture size: " + pictureSize.toString()) Log.i(TAG, "on picture taken") Log.i(TAG, "picture size: w" + pictureSize?.width.toString()) Log.i(TAG, "picture size:h " + pictureSize?.height.toString()) val mat = Mat(Size(pictureSize?.width?.toDouble() ?: 1920.toDouble(), pictureSize?.height?.toDouble() ?: 1080.toDouble()), CvType.CV_8U)
pictureSize?.height?.toDouble() ?: 1080.toDouble()), CvType.CV_8U)
Log.i(TAG, "on picture taken mat 1"+mat.toString())
Log.i(TAG, "on picture taken p0"+p0?.size.toString())//not null
mat.put(0, 0, p0)
Log.i(TAG, "on picture taken mat 2"+mat.toString())//not null
val pic = Imgcodecs.imdecode(mat, Imgcodecs.IMREAD_UNCHANGED)//error here
Core.rotate(pic, pic, Core.ROTATE_90_CLOCKWISE)
mat.release()
SourceManager.corners = processPicture(pic)
Imgproc.cvtColor(pic, pic, Imgproc.COLOR_RGB2GRAY)
SourceManager.pic = pic
context.startActivity(Intent(context, CropActivity::class.java))
busy = false
}
}
Below is the error E/cv::error(): OpenCV(4.3.0) Error: Assertion failed (buf.checkVector(1, CV_8U) > 0) in imdecode_, file /build/master_pack-android/opencv/modules/imgcodecs/src/loadsave.cpp, line 755
E/org.opencv.imgcodecs: imgcodecs::imdecode_10() caught cv::Exception: OpenCV(4.3.0) /build/master_pack-android/opencv/modules/imgcodecs/src/loadsave.cpp:755: error: (-215:Assertion failed) buf.checkVector(1, CV_8U) > 0 in function 'imdecode_'