Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Graphcut doesn't generate correct result

I have this code:

int main(int argc, char* argv[])
{

    Mat image0=imread("C:\\Working Dir\\Tests\\TestBlending\\shop0.jpg");
    Mat image1=imread("C:\\Working Dir\\Tests\\TestBlending\\shop1.jpg");

    image0.convertTo(image0,CV_32FC3,1/255.0);
    image1.convertTo(image1,CV_32FC3,1/255.0);

    // our corners are just at (0,0)
    cv::Point corner1;
    corner1.x = 0;
    corner1.y = 0;

    cv::Point corner2;
    corner2.x = 0;
    corner2.y = 0;

    std::vector<cv::Point> corners;

    corners.push_back(corner1);
    corners.push_back(corner2);

    std::vector<cv::Mat> masks;
    Mat mask0(image0.size(), CV_8U);
    mask0(Rect(0, 0, mask0.cols, mask0.rows)).setTo(255);

    Mat mask1(image1.size(), CV_8U);
    mask1(Rect(0, 0, mask1.cols, mask1.rows)).setTo(255);
    masks.push_back(mask0);
    masks.push_back(mask1);

    std::vector<cv::Mat> sources;

    sources.push_back(image0);
    sources.push_back(image1);

    cv::detail::GraphCutSeamFinder seam_finder;

    seam_finder.find(sources, corners, masks);

    printf("%lu\n", masks.size());
    for(int i = 0; i < masks.size(); i++)
    {
        std::cout << "MASK = "<< std::endl << " "  << masks.at(i) << std::endl << std::endl;
    }

    return 0;
}

and the images that I am using are:

enter image description here enter image description here

The masks that I am getting is all 255 for image 0 and all zero for image 1.

What is the problem and how can I fix it?