我有4个Mat需要灰度,否则方法Core.add()不起作用。 它只接受带通道的数组。 一旦完成,我就无法带回彩色垫子。 有人能帮我吗? 核心.add()只需要1个频道吗? 背景,前景,面具和dst是Mat。
Imgproc.cvtColor(background , background , Imgproc.COLOR_BGR2GRAY);
Imgproc.cvtColor(foreground , foreground , Imgproc.COLOR_BGR2GRAY);
Imgproc.cvtColor(dst , dst , Imgproc.COLOR_BGR2GRAY);
Core.add(background, foreground, dst, mask); // new image output
Imgproc.cvtColor(background , background , Imgproc.COLOR_GRAY2BGRA);
Imgproc.cvtColor(foreground , foreground , Imgproc.COLOR_GRAY2BGRA);
Imgproc.cvtColor(dst , dst , Imgproc.COLOR_GRAY2RGBA);
Imgproc.cvtColor(mask , mask , Imgproc.COLOR_GRAY2RGBA);
Bitmap maschera = Bitmap.createBitmap(mask.width(), mask.height(), Config.ARGB_8888);
Bitmap gc_result = Bitmap.createBitmap(mask.width(), mask.height(), Config.ARGB_8888);
Utils.matToBitmap(mask, maschera);
Utils.matToBitmap(dst, gc_result);
String maskpath = Environment.getExternalStorageDirectory().getAbsolutePath()
+ "grubcut_dst.png";
Highgui.imwrite(maskpath, dst);
感谢所有人!!!