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

Convert a bitmap to mat and vice versa in OpenCV

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

首先导入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