在OpenCV中将位图转换为mat,反之亦然

时间:2017-10-22 16:26:16

标签: android opencv3.0 opencv4android

我的代码中有一个Android Bitmap,我想运行 cvCanny方法就可以了。但是,它需要首先在Mat中。我如何能 将数据转换为Mat,以及如何将其转换回Bitmap 我做完了吗?

1 个答案:

答案 0 :(得分:1)

首先导入org.opencv.android.Utils

然后使用:

Mat src = new Mat();
Utils.bitmapToMat(bitmap, src);

执行边缘检测:

Mat dest = new Mat();
Imgproc.Canny(src, dest, min, max);
Bitmap edgeBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(dest, edgeBitmap);
//edgeBitmap is ready 
相关问题