OpenCV for Android: Convert Camera preview from YUV to RGB with Imgproc.cvtColor

后端 未结 1 630
悲哀的现实
悲哀的现实 2020-12-18 16:36

I get a runtime error if I try to convert camera preview YUV byte array to a RGB(A) byte array with Imgproc.cvtColor( mYUV_Mat, mRgba_Mat, Imgproc.COLOR_YUV420sp2RGBA, 4 ) i

相关标签:
1条回答
  • 2020-12-18 17:10

    Maybe the Imgproc library isn't properly included in your project, but other OpenCV libraries are? The line that crashes is the first line where you use a method from Imgproc, which would explain why earlier parts of the code run correctly.

    Your code looks fine, except you can use the no-argument constructor for mRgba_Mat (since most OpenCV4Android functions, including cvtColor, can infer the required size of the destination matrix), and you're allocating a lot of wasted space for mYUV_Mat. You don't need a full 4 channels if you just allocate YUV matrices 50% more space than their RGB counterparts:

    mYUV_Mat = new Mat( newImageHeight + newImageHeight / 2, newImageWidth, CvType.CV_8UC1 );
    
    0 讨论(0)
提交回复
热议问题