Having problem with using grabcut algorithm in pictureBox of Visual C++ CLR project

asked 2017-02-07 12:24:47 -0600

Allison gravatar image

updated 2017-02-08 04:45:13 -0600

I need to use the grabcut algorithm in a picturebox where the image is loaded.But i'm having trouble in using the grabcut on the image.It is not working.

Here is the grabcut function :

void grabCut( Mat image, Mat mask, Rect rect, Mat bgdModel, Mat fgdModel, int i,const int GC_INIT_WITH_RECT)
        {
            int border = 20;
            int border2 = border + border;
            Rect rectangle(border, border, image.cols - border2, image.rows - border2);
            cv::compare(mask, GC_PR_FGD, mask, CMP_EQ);
            // Generate output image
            cv::Mat foreground(image.size(), CV_8UC3, cv::Scalar(255, 255, 255));
            image.copyTo(foreground, mask); // bg pixels not copied

                                              // draw rectangle on original image
            cv::rectangle(image, rect, cv::Scalar(255, 255, 255), 1);

        }

I'm using the code found in github that is ,grabcut.cpp which is running successfully, but when applying it in the picture box ,it's not working. Any idea how i can i make it work out?Any piece of code would be of great help.. Thank you in advance..

After declaring the variable:

IplImage* frame;

//Displaying the image

pictureBox1->Image  = gcnew System::Drawing::Bitmap
(frame->width,frame->height,frame->widthStep,
System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr) frame->imageData);
pictureBox1->Refresh();
edit retag flag offensive close merge delete

Comments

",it's not working" -- .. if that's all you can say, you clearly have no idea, what you're doing

(and we cannot help you)

berak gravatar imageberak ( 2017-02-07 12:33:43 -0600 )edit

I mean to say that the rectangle is not being drawn on the image (i.e displayed in the picturebox) when applying the grabcut function in order to separate the foreground from background ..

Allison gravatar imageAllison ( 2017-02-07 12:48:34 -0600 )edit

how do we know, what you display in your picturebox ?

berak gravatar imageberak ( 2017-02-07 12:56:09 -0600 )edit

An image showing hand palm ..i want to extract it from the background ..

Allison gravatar imageAllison ( 2017-02-07 13:04:14 -0600 )edit

you misread me:

how do we know, you're actually displaying imge , (not "foreground", or anything else ?)

berak gravatar imageberak ( 2017-02-07 13:10:23 -0600 )edit