Correct way to convert between Bitmap and Mat in OpenCV on Android?

后端 未结 1 418
终归单人心
终归单人心 2021-01-03 03:47

I\'m currently trying to migrate a bit of legacy code from iPhone to Android. This code uses the OpenCV library to do some image processing. And I cannot understand how to d

相关标签:
1条回答
  • 2021-01-03 04:22

    Currently matToBitmap is a bit buggy, I've read they intend to fix it in a future release.

    I can show it how I worked around it for a color image:

    mMat = Utils.loadResource(this, resId, Highgui.CV_LOAD_IMAGE_COLOR);
    Imgproc.cvtColor(mMat, result, Imgproc.COLOR_RGB2BGRA);
    bmp = Bitmap.createBitmap(result.cols(), result.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(result, bmp);
    mImageView.setImageBitmap(bmp);
    

    Basically i perform that space color conversion first or like you said the result will be a weird blend of random colors.

    Answer if it works, I think it does.

    0 讨论(0)
提交回复
热议问题