Ask Your Question

Joystna's profile - activity

2013-12-09 07:38:24 -0600 asked a question Hello Friends, How can i create a mask image in opencv and create trimap segments. Please guide its urgent.

Hello Friends,

I want to create a mask image and i want to segment it with trimap. and put that mask image on the original image and segment it F & B image. actually i am trying Gracut where i need to create a mask image and segment it and apply it on the original image. Below is my source code and have got result but it is not according to the exact result. Please guide me with the source code to create mask image and put that on original image. YOur kind help will be highly appreciated.

Thank you in advance. Joystna

include <opencv2 core="" core.hpp="">

include <opencv2 highgui="" highgui.hpp="">

include <opencv2 imgproc="" imgproc.hpp="">

include <iostream>

using namespace cv; using namespace std;

int main( ) { // Open another image Mat image; image = cv::imread("2.png");

if(! image.data ) // Check for invalid input
{
    cout <<  "Could not open or find the image" << std::endl ;
    return -1;
}

// define bounding rectangle

  cv::Rect rectangle(20,35,image.cols-40,image.rows-70);

cv::Mat result; // segmentation result (4 possible values)
cv::Mat bgModel,fgModel; // the models (internally used)

// GrabCut segmentation
cv::grabCut(image,    // input image
    result,   // segmentation result
    rectangle,// rectangle containing foreground 
    bgModel,fgModel, // models
  1,        // number of iterations
    cv::GC_INIT_WITH_RECT); // use rectangle
// Get the pixels marked as likely foreground
cv::compare(result,cv::GC_PR_FGD,result,cv::CMP_EQ);
// Generate output image
cv::Mat foreground(image.size(),CV_8UC3,cv::Scalar(255,255,255));
image.copyTo(foreground,result); // bg pixels not copied


// draw rectangle on original image
cv::rectangle(image, rectangle, cv::Scalar(255,0,0),5);
cv::namedWindow("Image");
cv::imshow("Image",image);

// display result
cv::namedWindow("Segmented Image");
cv::imshow("Segmented Image",foreground);


waitKey();
return 0;

} C:\fakepath\Untitled.png

2013-12-09 07:25:51 -0600 commented answer Hello Friends, How can i create a mask image in opencv and create trimap segments. Please guide its urgent.

hello below is my source code but it is not according to exact result because I am not using the mask image . Can anyone help me mask image source it will be highly appreciated.

include <opencv2/core/core.hpp>

include <opencv2/highgui/highgui.hpp>

include <opencv2/imgproc/imgproc.hpp>

include <iostream>

using namespace cv; using namespace std;

int main( ) { // Open another image Mat image; image = cv::imread("2.png");

if(! image.data ) // Check for invalid input
{
    cout &lt;&lt;  "Could not open or find the image" &lt;&lt; std::endl ;
    return -1;
}

// define bounding rectangle

// int border = 50; // int border2 = border + border; //cv::Rect rectangle(border,border,image.cols-border2,image.rows-border2); cv::Rect rectangle(20,35,imag

2013-12-09 00:20:22 -0600 answered a question How to remove black background from grabcut output image in OpenCV android ?

Hello Mr Haris,

can i get your help for my grabcut project.

please email me on [email protected]

Thank you

2013-12-08 20:04:12 -0600 received badge  Editor (source)
2013-12-08 20:03:23 -0600 asked a question Hello Friends, How can i create a mask image in opencv and create trimap segments. Please guide its urgent.

Hello Friends,

I want to create a mask image and i want to segment it with trimap. and put that mask image on the original image and segment it F & B image. actually i am trying Gracut where i need to create a mask image and segment it and apply it on the original image.

Please guide me with the source code to create mask image and put that on original image. YOur kind help will be highly appriciated.

Thank you in advance.

Joystna