Ask Your Question

nena's profile - activity

2020-11-28 03:37:55 -0600 received badge  Good Question (source)
2017-02-06 04:55:17 -0600 received badge  Famous Question (source)
2016-01-08 06:21:30 -0600 received badge  Notable Question (source)
2015-09-22 10:05:07 -0600 received badge  Popular Question (source)
2015-03-23 05:45:24 -0600 received badge  Nice Question (source)
2014-08-06 09:14:21 -0600 received badge  Scholar (source)
2014-07-25 04:37:25 -0600 commented answer How to set transparent background to grabcut output image in OpenCV (C++)?

Great idea, thank you!

2014-07-25 01:32:27 -0600 received badge  Student (source)
2014-07-24 06:30:45 -0600 commented answer How to set transparent background to grabcut output image in OpenCV (C++)?

Exactly. I am working on a user friendly app for removing the background and I want it to work very fast even for large resolution images, which is not the case now.

2014-07-24 05:18:55 -0600 commented answer How to set transparent background to grabcut output image in OpenCV (C++)?

Can you maybe suggest a way of improving the performance?

2014-07-24 05:17:19 -0600 commented answer How to set transparent background to grabcut output image in OpenCV (C++)?

I reused the same mask which I found using grabcut instead of looking for the contours, and then split the image. That worked perfectly well. Thank you so much!

2014-07-18 03:18:45 -0600 commented answer How to remove black background from grabcut output image in OpenCV android ?
2014-07-18 02:08:06 -0600 received badge  Editor (source)
2014-07-17 10:11:02 -0600 asked a question How to set transparent background to grabcut output image in OpenCV (C++)?

Hi I'm using the grabcut algorithm to remove the background of an image, and currently I get these results: image description

What I want is that the background to be transparent instead of black. I tried the suggestions I found here: http://answers.opencv.org/question/24463/how-to-remove-black-background-from-grabcut-output/#24508

which led me to this result: image description

What I want is that my program doesn't depend on the colors of the image, since any color can be part of the foreground. As far as I understood, thresholding performs the image segmentation based on colors, so I can't use it.

I've read something about blob and edge detection but I didn't manage to implement it. So I need help. Thanks

2014-07-10 02:14:16 -0600 received badge  Supporter (source)
2014-07-09 07:23:15 -0600 commented answer How to remove black background from grabcut output image in OpenCV android ?

But what if the foreground contains black pixels?

2014-07-08 06:40:05 -0600 commented question Using a PNG image as mask for GrabCut

Here: http://prntscr.com/40kt4e. I guess it's like there's no rectangle, it only sees the GC_FGD pixels, everything else is considered BG. And it looks somehow scaled, but I have no idea how to fix it.

2014-07-08 06:28:16 -0600 asked a question Using a PNG image as mask for GrabCut

I have a png image with green and red lines and transparent background, which I need to use is as a mask for executing GrabCut. But I get unexpected results. Here's my code:

Mat image;
image= cv::imread(file);

cv::Rect rectangle(startX, startY, width, height);  
cv::Mat bgModel,fgModel;

//find the mask
Mat mask;
mask.create( image.size(), CV_8UC1);
mask.setTo(Scalar::all(GC_BGD));
Mat maskImg = imread("messi5.png");

for(int i=0; i<maskImg.cols; i++)    
    for(int j=0; j<maskImg.rows; j++)    
    {               
        //if it's red, make it white
        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) {

            mask.at<cv::Vec3b>(j,i)[0]= GC_BGD;
            mask.at<cv::Vec3b>(j,i)[1] = GC_BGD;
            mask.at<cv::Vec3b>(j,i)[2] = GC_BGD;
        }           

        //if it's green, make it black
        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<cv::Vec3b>(j,i)[0] = GC_FGD;
            mask.at<cv::Vec3b>(j,i)[1] = GC_FGD;
            mask.at<cv::Vec3b>(j,i)[2] = GC_FGD;
        }
    }

    // GrabCut segmentation
    cv::grabCut(image,    // input image
        mask,   // segmentation result
        rectangle,// rectangle containing foreground
        bgModel,fgModel, // models
        1,        // number of iterations
        cv::GC_INIT_WITH_MASK); // use rectangle

    Mat binMask;
    binMask.create( mask.size(), CV_8UC1 );
    binMask = mask & GC_FGD;
    Mat res;
    image.copyTo( res, binMask );
    imshow("result", res);
    waitKey(0);