Ask Your Question
0

android opencv 4.3.0 Assertion failed (buf.checkVector(1, CV_8U) > 0)

asked 2020-07-13 05:40:24 -0600

ch gravatar image

updated 2020-07-13 08:15:24 -0600

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_'
edit retag flag offensive close merge delete

Comments

why do you think, you need to imdecode() your Mat ?

                    pictureSize?.height?.toDouble() ?: 1080.toDouble()), CvType.CV_8U)

is above line duplicated by error ?

berak gravatar imageberak ( 2020-07-13 06:10:22 -0600 )edit
1

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)'

where 'scn' is 1.even thought i first converted it mat to 8 byte so i thought to use imdecode

ch gravatar imagech ( 2020-07-13 06:15:39 -0600 )edit

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

berak gravatar imageberak ( 2020-07-13 06:47:53 -0600 )edit

p0 is ByteArray

ch gravatar imagech ( 2020-07-13 07:12:32 -0600 )edit

we know that. what is inside it ? how long is it ?

do you understand the comment above ?

berak gravatar imageberak ( 2020-07-13 07:36:13 -0600 )edit

Sorry i am very new to opecv ,i dont understand.I am not reading file from memory

ch gravatar imagech ( 2020-07-13 08:14:30 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-07-13 11:45:58 -0600

ch gravatar image

i converted bytearray to bitmap,and then to mat .Thank you for your help

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-07-13 05:40:24 -0600

Seen: 3,861 times

Last updated: Jul 13 '20