【问题标题】:Simple stitching code简单的拼接代码
【发布时间】:2015-10-20 08:22:54
【问题描述】:

我第一次使用OpenCV,那是为了做一个简单的图像拼接......我尝试了以下简单的代码:

    Mat resImage;
    Mat image1 = imread(_T("D:\\Tempx\\Image1.bmp"), CV_LOAD_IMAGE_COLOR);
    Mat image2 = imread(_T("D:\\Tempx\\Image2.bmp"), CV_LOAD_IMAGE_COLOR);
    std::vector<cv::Mat> vImg;

    vImg.push_back(image1);
    vImg.push_back(image2);

    Stitcher stitcher = Stitcher::createDefault(TRUE);
    Stitcher::Status stat = stitcher.stitch(vImg, resImage); // <-- crash the program !!!
    if(cv::Stitcher::OK != stat)
        sError.Format(_T("Error while stitching the images."));

    std::vector<int> compression_params;
    compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
    compression_params.push_back(9);

    imwrite(_T("D:\\Tempx\\Image3.bmp"), resImage, compression_params);

但在线:

stitcher.stitch(vImg, resImage);

程序崩溃了:

可能是一些简单的事情,可能不是......你能看看并告诉我一个提示/想法,什么?谢谢。

【问题讨论】:

  • 根据文档 createDefault(bool try_use_gpu = false);我建议您使用 False 而不是 true 作为参数。 (虽然我不确定)
  • 我已经尝试过了,完全一样的行为。 :(

标签: c++ opencv visual-c++ graphics mfc


【解决方案1】:

我猜你的图片有问题。确保它们被正确读取,例如,通过 imwrite 到新文件中。还要先用另一对图像进行测试。如果所有这些都通过,那么它可能由于某种原因无法估计相机参数。

更新: 特征提取器似乎有问题,仅凭您发布的追溯很难判断出了什么问题。在代码中设置特征提取器,看看效果如何:

Stitcher stitch = Stitcher::createDefault(FALSE);
stitch.setFeaturesFinder(new detail::OrbFeaturesFinder());

第一行和你的代码一样,第二行我们只是告诉拼接器使用什么特征提取器。

【讨论】:

  • 我检查了,加载的图像我保存在硬盘上,并且它们存储正确,所以,问题不存在......
  • 那我建议你分享你的图片,有人可以尝试在你的图片上运行相同的代码,然后可以看到什么问题......
  • 当然,这是个好主意!但为此,我应该创建另一个回复,希望本论坛的管理员能够理解。
【解决方案2】:

用于拼接的图像:

代码是:

#include <opencv2/opencv.hpp>
#include <opencv2/stitching.hpp>

    Mat image1 = imread(_T("D:/Tempx/Image1.bmp"), CV_LOAD_IMAGE_ANYCOLOR);
    Mat image2 = imread(_T("D:/Tempx/Image2.bmp"), CV_LOAD_IMAGE_ANYCOLOR);

    vImg.push_back(image1);
    vImg.push_back(image2);

    Mat resImage;
    Stitcher stitch = Stitcher::createDefault(FALSE);
    Stitcher::Status stat = stitch.stitch(vImg, resImage);
    if(Stitcher::OK != stat)
        MessageBox(_T("Error while stitching the images."));

    std::vector<int> compression_params;
    compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
    compression_params.push_back(9);

    imwrite(_T("D:/Tempx/Image3.bmp"), resImage, compression_params);

【讨论】:

    猜你喜欢
    • 2020-04-13
    • 2013-11-01
    • 2017-08-24
    • 1970-01-01
    • 1970-01-01
    • 2015-04-07
    • 1970-01-01
    • 2013-08-27
    • 2014-06-23
    相关资源
    最近更新 更多