android opencv 4.3.0 Assertion failed (buf.checkVector(1, CV_8U) > 0)
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)
Log.i(TAG, "on picture taken mat 1"+mat.toString())
Log.i(TAG, "on picture taken p0"+p0?.size.toString())//not null//3049977
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_'
why do you think, you need to imdecode() your Mat ?
is above line duplicated by error ?
yes this line is duplicated by error ,edited it.As i want to use the bytearray image i get from camera so i use imdecode.I already have mat object ready but i cant use it as is as it says invalid number of channels in input Image 'VScn::contains(scn)'
please clarify, what is inside
p0
. if that is decoded pixels, you don't need imdecode.if on the other hand it is e.g. an encoded jpg "in memory", file header, compressed pixels, like it would be on disk, you need an 1d Mat, with the length of the buffer, not the image dimensions
p0 is ByteArray
we know that. what is inside it ? how long is it ?
do you understand the comment above ?
Sorry i am very new to opecv ,i dont understand.I am not reading file from memory