基于Stitcher类的图像拼接(图像融合)

1 实现代码

#include 
#include 
#include 
//#include 
#include 


using namespace std;
using namespace cv;
bool try_use_gpu = false;
vector<Mat> imgs;
string result_name = "/Users/macbookpro/CLionProjects/PatternRecognition/img_test2/dst1.jpg";
int main(int argc, char * argv[])
{
    string iPath1 = "/Users/macbookpro/CLionProjects/PatternRecognition/img_test2/2.png";
    string iPath2 = "/Users/macbookpro/CLionProjects/PatternRecognition/img_test2/1.png";
    Mat img1 = imread(iPath1);
    Mat img2 = imread(iPath2);

    imshow("p1", img1);
    imshow("p2", img2);

    if (img1.empty() || img2.empty())
    {
        cout << "Can't read image" << endl;
        return -1;
    }
    imgs.push_back(img1);
    imgs.push_back(img2);

    //Stitcher::SCANS = 1,
    //Stitcher::PANORAMA = 0,
    Ptr<Stitcher >stitcher = Stitcher::create(Stitcher::PANORAMA);

    // 拼接方式-多通道融合
//    auto blender = detail::Blender::createDefault(detail::Blender::MULTI_BAND);
//    stitcher->setBlender(blender);

    // 使用stitch函数进行拼接
    Mat pano;
    Stitcher::Status status = stitcher->stitch(imgs, pano);

    if (status != Stitcher::OK)
    {
        cout << "Can't stitch images, error code = " << int(status) << endl;
        return -1;
    }
    imwrite(result_name, pano);
    Mat pano2 = pano.clone();
    // 显示源图像,和结果图像
    imshow("全景图像", pano);
    waitKey(-1);
}

你可能感兴趣的:(数字图像处理)