1

我尝试使用 OpenCV 中的拼接器模块来拼接图像。下面是我的代码(核心部分)。

int main()
{
    Mat img1 = imread("5.jpg");
    Mat img2 = imread("6.jpg");
    //Mat img3 = imread("11.jpg");
    imgs.push_back(img1);
    imgs.push_back(img2);
    //imgs.push_back(img3);

    Mat pano; // Mat to store the output pano image
    Stitcher stitcher = Stitcher::createDefault(try_use_gpu); // create a Stitcher object
    Stitcher::Status status = stitcher.stitch(imgs, pano); // stitch the input images together
    cout << "hello" <<endl;
    if (status != Stitcher::OK)
    {
        cout << "Can't stitch images, error code = " << int(status) << endl;
        return -1;
    }
    imshow("pano",pano);
    imwrite(result_name, pano); // write the result to the output image
    waitKey(0);
    return 0;
}

上面代码中的“imgs”是一个 Mat 类型的向量。

我在网上看到很多类似的代码与此类似,但我不知道为什么我的代码对输入图像的大小有很大的限制。如果输入图像大小约为 800 * 600,则效果很好。但是当大小为 650 * 650 或 1280 * 640 或其他大小时,控制台提示将在程序结束后很快关闭。并且没有图像保存在“panoResult.jpg”中。也不显示图像。Visual Studio 2010 只是Image_stitching2.exe: Native' has exited with code -1 (0xffffffff). 在我调试时显示。

有人可以帮忙吗?我真的需要在这方面取得进展,因为我已经花了几个小时来修复它,但只是不正确。任何提示或帮助对我来说都很棒。

4

0 回答 0