Here is my code to use grabcut on the android phone,But when finish the grabcut ,the background is black ,how to let it white,Thanks a lot!
org.opencv.core.Rect rect1=new org.opencv.core.Rect(p1,p2) ;
//Rect rect = new Rect(50,30, 100,200);
Log.d(TAG, "rect: " + rect);
Mat mask = new Mat();
mask.setTo(new Scalar(125));
Mat fgdModel = new Mat();
fgdModel.setTo(new Scalar(255, 255, 255));
Mat bgdModel = new Mat();
bgdModel.setTo(new Scalar(255, 255, 255));
Mat imgC3 = new Mat();
Imgproc.cvtColor(img, imgC3, Imgproc.COLOR_RGBA2RGB);
Log.d(TAG, "imgC3: " + imgC3);
Log.d(TAG, "Grabcut begins");
Imgproc.grabCut(imgC3, mask, rect1, bgdModel, fgdModel,5, Imgproc.GC_INIT_WITH_RECT);
Mat source = new Mat(1, 1, CvType.CV_8U, new Scalar(3.0));
Core.compare(mask, source, mask, Core.CMP_EQ);
// Core.compare(mask,cv::GC_PR_FGD,mask,Core.CMP_EQ);
Mat foreground = new Mat(img.size(), CvType.CV_8UC3, new Scalar(255, 255, 255));
img.copyTo(foreground, mask);//提取完成
//convert to Bitmap
Log.d(TAG, "Convert to Bitmap");
Utils.matToBitmap(foreground, bitmap);
img.release();
imgC3.release();
mask.release();
fgdModel.release();
bgdModel.release();
return bitmap;