Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Mask giving assertion error in Grabcut Algo

I want to implement Grabcut using Mask. But its is giving me the assertion error.

Here is my Image: image description

Here is my mask : image description

Please need urgent help.Thanks

click to hide/show revision 2
retagged

updated 2014-08-20 08:29:49 -0600

berak gravatar image

Mask giving assertion error in Grabcut Algo

I want to implement Grabcut using Mask. But its is giving me the assertion error.

Here is my Image: image description

Here is my mask : image description

Please need urgent help.Thanks

Mask giving assertion error in Grabcut Algo

I want to implement Grabcut using Mask. But its is giving me the assertion error.

Error:OpenCV Error: Bad argument (mask element value must be equelGC_BGD or GC_FGD or GC_PR_BGD or GC_PR_FGD)

Here is my Image: image description

Here is my mask : image description

Please need urgent help.Thanks

Mask giving assertion error in Grabcut Algo

I want to implement Grabcut using Mask. But its is giving me the assertion error.

Code:

Mat firstMask = new Mat();

    Mat bgModel = new Mat();
    Mat fgModel = new Mat();
    Mat mask;
    Mat source = new Mat(1, 1, CvType.CV_8U, new Scalar(3.0));
    dst = new Mat();
    Rect rect = new Rect(tl, br);

    firstMask=Highgui.imread("/storage/emulated/0/DCIM/Camera/pokimen.jpg", CvType.CV_8UC1);

    Imgproc.grabCut(img, firstMask, rect, bgModel, fgModel, 3, Imgproc.GC_INIT_WITH_MASK);
    Core.compare(firstMask, source/* GC_PR_FGD */, firstMask, Core.CMP_EQ);
    Log.d("hello", "asdas");
    Mat foreground = new Mat(img.size(), CvType.CV_8UC3, new Scalar(255,255, 255));
    img.copyTo(foreground, firstMask);

     Core.rectangle(img, tl, br, color);

       Mat tmp = new Mat();
       Imgproc.resize(background, tmp, img.size());
       background = tmp;
       mask = new Mat(foreground.size(), CvType.CV_8UC1, new Scalar(255, 255, 255));

    Imgproc.cvtColor(foreground, mask, 6/* COLOR_BGR2GRAY */);
    Imgproc.threshold(mask, mask, 254, 255, 1 /* THRESH_BINARY_INV */);

    Mat vals = new Mat(1, 1, CvType.CV_8UC3, new Scalar(0.0));
    background.copyTo(dst);

    background.setTo(vals, mask);

    Core.add(background, foreground, dst, mask);

    firstMask.release();
    source.release();
    bgModel.release();
    fgModel.release();
    vals.release();

Error:OpenCV Error: Bad argument (mask element value must be equelGC_BGD or GC_FGD or GC_PR_BGD or GC_PR_FGD)

Here is my Image: image description

Here is my mask : image description

Please need urgent help.Thanks

Mask giving assertion error in Grabcut Algo

I want to implement Grabcut using Mask. But its is giving me the assertion error.

Code:

Mat firstMask = new Mat();

    Mat bgModel = new Mat();
    Mat fgModel = new Mat();
    Mat mask;
    Mat source = new Mat(1, 1, CvType.CV_8U, new Scalar(3.0));
    dst = new Mat();
    Rect rect = new Rect(tl, br);

    firstMask=Highgui.imread("/storage/emulated/0/DCIM/Camera/pokimen.jpg", CvType.CV_8UC1);

    Imgproc.grabCut(img, firstMask, rect, bgModel, fgModel, 3, Imgproc.GC_INIT_WITH_MASK);
    Core.compare(firstMask, source/* GC_PR_FGD */, firstMask, Core.CMP_EQ);
    Log.d("hello", "asdas");
    Mat foreground = new Mat(img.size(), CvType.CV_8UC3, new Scalar(255,255, 255));
    img.copyTo(foreground, firstMask);

     Core.rectangle(img, tl, br, color);

       Mat tmp = new Mat();
       Imgproc.resize(background, tmp, img.size());
       background = tmp;
       mask = new Mat(foreground.size(), CvType.CV_8UC1, new Scalar(255, 255, 255));

    Imgproc.cvtColor(foreground, mask, 6/* COLOR_BGR2GRAY */);
    Imgproc.threshold(mask, mask, 254, 255, 1 /* THRESH_BINARY_INV */);

    Mat vals = new Mat(1, 1, CvType.CV_8UC3, new Scalar(0.0));
    background.copyTo(dst);

    background.setTo(vals, mask);

    Core.add(background, foreground, dst, mask);

    firstMask.release();
    source.release();
    bgModel.release();
    fgModel.release();
    vals.release();

Error:OpenCV Error: Bad argument (mask element value must be equelGC_BGD or GC_FGD or GC_PR_BGD or GC_PR_FGD)

Here is my Image: image description

Here is my mask : image description

Please need urgent help.Thanks