Ask Your Question

swag's profile - activity

2020-05-20 07:48:50 -0600 received badge  Popular Question (source)
2014-08-21 09:26:36 -0600 asked a question How to iterate through pixels in Android

I have code for pixel iteration which is in c++.

Here it is:

for(int i=0; i<maskImg.cols; i++)    
    for(int j=0; j<maskImg.rows; j++)    
    {               
        //if it's red, make it black
        if ((int)maskImg.at<cv::Vec3b>(j,i)[0]==0 && (int)maskImg.at<cv::Vec3b>(j,i)[1] == 0 && (int)maskImg.at<cv::Vec3b>(j,i)[2] == 255) {

            //the whole mask is black so this is redundant
            mask.at<uchar>(j,i)= GC_BGD;  //GC_BGD := 0 := black 

        }           

        //if it's green, make it white
        if ((int)maskImg.at<cv::Vec3b>(j,i)[0]==0 && (int)maskImg.at<cv::Vec3b>(j,i)[1] == 255 && (int)maskImg.at<cv::Vec3b>(j,i)[2] == 0) {    

                mask.at<uchar>(j,i) = GC_FGD; //GC_FGD:= 1 := white 

        }
    }

Now someone can help me that how to implement this in Android.Thanks

2014-08-21 08:02:09 -0600 commented answer How to specify mask for grabCut in C++

how to solve this problem in JavaCV? need urgent guys :|

2014-08-21 06:05:03 -0600 commented question Mask giving assertion error in Grabcut Algo

need urgent help dude :(

2014-08-21 05:27:09 -0600 commented question Mask giving assertion error in Grabcut Algo

no no .. i mean that i want to tell grabcut Algo that white area of the mask is foreground and back is background which should be subtract!

2014-08-21 05:14:59 -0600 commented question Mask giving assertion error in Grabcut Algo

okay fine i got ..Now problem is that i want to set the white region of mask as FGD and black as BGD ? how to do so?

2014-08-20 08:52:20 -0600 commented question Mask giving assertion error in Grabcut Algo

lol..Sorry buddy,,I m new to this forum so thats why .Updated again have a look and help :( totally struck there

2014-08-20 08:45:27 -0600 commented question Mask giving assertion error in Grabcut Algo

ops my bad. Now updated :)

2014-08-20 08:44:49 -0600 received badge  Editor (source)
2014-08-20 08:22:05 -0600 asked a question 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