opencv graphcut不会返回正确的掩码

时间:2014-03-01 19:29:48

标签: c++ opencv image-processing

我有这段代码:

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;
}

我正在使用的图片是:

enter image description here enter image description here

我得到的面具对于图像0都是255,对于图像1都是零。

问题是什么,我该如何解决?

EDIT1

我注意到输入图像应该是tif格式,因此应用程序可以看到每个图像中的透明像素,所以这里是tif格式的图像文件:

enter image description here enter image description here

我使用smartblend(http://wiki.panotools.org/SmartBlend)来混合这两个图像,我可以得到这个图像:

enter image description here

0 个答案:

没有答案