【OpenCV】3.4.0图像拼接Stitching模块介绍

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hongtao_6/article/details/82183403

Images stitching 是opencv3.4.0中的模块之一,使用此模块可以实现对图像的拼接。在此之前需要编译opencv3.4.0+contrib。具体编译方法可以点此链接。也可以直接下载我编译好的opencv340+contrib的文件直接配置,配置方法与opencv一样。
具体内容可以参考sitiching的官方帮助文档

Image Stitching 模块下共包含七个子模块,分别为:

  • Features Finding and Images Matching 功能查找和图像匹配
  • Rotation Estimation 轮换估计
  • Autocalibration 自动校准
  • Images Warping 图像变形
  • Seam Estimation 接缝估计
  • Exposure Compensation 曝光补偿
  • Image Blenders 图像搅拌机
    这里写图片描述

我们先来看一下cv::stitcher这个类,该类包含在头文件opencv2/stitching.hpp中,其所有的成员函数如下:
这里写图片描述
这里写图片描述

先来看一个简单的实例:

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/stitching.hpp>
#include "windows.h"

using namespace std;
using namespace cv;

bool try_use_gpu = false;
vector<Mat> imgs;
string result_name = "dst1.jpg";
int main(int argc, char * argv[])
{
    Mat img1 = imread("33.jpg");
    Mat img2 = imread("34.jpg");
    imshow("p1", img1);
    imshow("p2", img2);

    long t0 = GetTickCount();

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

    Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
    // 使用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;
    }
    long t1 = GetTickCount();
    imwrite(result_name, pano);
    Mat pano2 = pano.clone();
    // 显示源图像,和结果图像
    imshow("全景图像", pano);

    cout << "Time: "<<t1 - t0 << endl;

    if (waitKey() == 27)
        return 0;
}

这里写图片描述
通过结果可以看出直接使用stitching函数进行拼接是比较耗时的。这个简单的例子主要使用了两个函数,分别为:
这里写图片描述
这里写图片描述
stitch函数的返回值是一个状态,并将拼接完成的图片存在 pano中
这里写图片描述

猜你喜欢

转载自blog.csdn.net/hongtao_6/article/details/82183403