Search code examples
androidopencvjavacv

Mat::convertto() not working in javacv, android camera


I am developing an Android OpenCV app based on Opencv4android SDK tutorial 2 - Mixed Processing.

in the frame processing function public Mat onCameraFrame(CvCameraViewFrame inputFrame) {}

The frame is RGBA and I want to make RGB by doing this:

 mRgba = inputFrame.rgba();
 mGray = inputFrame.gray();

 Mat    mRgb=new Mat(640,480,CvType.CV_8UC3);
 mRgba.convertTo(mRgb, CvType.CV_8UC3);
 //Imgproc.cvtColor(mRgba, mRgb, CvType.CV_8UC3);
 PinkImage(mRgb.dataAddr());

But when I debug and log the things I passed to the JNI part, I find it's not working at all. mRgb is CV_8UC4 even after calling converto()

What is the cause of this?


Solution

  • OK, the answer is here

    Imgproc.cvtColor(mRgba,mRgb,Imgproc.COLOR_RGBA2RGB);
    

    instead of

    mRgba.convertTo(mRgb, CvType.CV_8UC3);
    

    Thanks a lot!!