输出图像中的Grabcut OpenCV Android错误

时间:2016-03-25 14:25:31

标签: android opencv image-processing

我在Android上使用OpenCV并在图像上执行Grabcut以进行前景提取,我按预期获得输出但输出图像有蓝色调而不是提供的原始图像?这个问题的解决方案是什么?

我正在附加我目前正在使用的代码。

private Mat performGrabCut(Mat image)
{
      Mat firstMask = new Mat();
      Mat foregroundModel = new Mat();
      Mat backgroundModel = new Mat();

      Mat mask;

      Mat source = new Mat(1, 1, CvType.CV_8U, new Scalar(3.0));
      Mat destination = new Mat();

      Rect rect = new Rect(topLeft, bottomRight);

      Imgproc.grabCut(image, firstMask, rect, backgroundModel, foregroundModel, 1, 0);

      Core.compare(firstMask, source, firstMask, Core.CMP_EQ);

      Mat foreground = new Mat(image.size(), CvType.CV_8UC3, new Scalar(255,255,255));
      image.copyTo(foreground, firstMask);
      return foreground;
}

0 个答案:

没有答案