图像拼接类stitcher
拼接类stitcher 的头文件为:#include "opencv2/stitching/stitcher.hpp"
1、Stitcher::createDefault
使用默认参数创建一个拼接器
C++: Stitcher Stitcher::createDefault(bool try_use_gpu=false)
2、Stitcher::estimateTransform
这些函数尝试匹配给定的图像和去估计每个摄像机的旋转
Note
Use the functions only if you’re aware of the stitching pipeline, otherwise use Stitcher::stitch().
(注意:只有你熟悉拼接的流程情况使用这个函数,否则使用Stitcher::stitch())
-
C++:
Status
Stitcher::
estimateTransform
(InputArray
images
)
C++: Status Stitcher::estimateTransform(InputArray images,const std::vector<std::vector<Rect>>& rois)
-
C++:
Status
Stitcher::
stitch
(InputArray
images, OutputArray
pano
)
¶
-
C++:
Status
Stitcher::
stitch
(InputArray
images, const std::vector<std::vector<Rect>>&
rois, OutputArray
pano
)
Parameters:images –Input images(输入图像)
rois – Region of interest rectangles(感兴趣矩形区域) pano – Final pano
Returns:Status code.
#include <iostream>
#include <fstream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/stitching/stitcher.hpp"
using namespace std;
using namespace cv;
bool try_use_gpu = false;
vector<Mat> imgs; //定义一个Mat类型的向量
string result_name = "result.jpg"; //输出图像的名字
int main(int argc, char* argv[])
{
Mat img1 = imread("E:\\图片\\图像拼接\\1.jpg");//E:\\图片\\图像拼接\\1.jpg
if (img1.empty())
{
cout << "img1 Can't read image '" << endl;
return -1;
}
imshow("图1",img1);
imgs.push_back(img1);
Mat img2=imread("E:\\图片\\图像拼接\\2.jpg");
if (img2.empty())
{
cout << "img2 Can't read image '" << endl;
return -1;
}
imshow("图2",img2);
imgs.push_back(img2);
Mat img3=imread("E:\\图片\\图像拼接\\3.jpg");
if (img3.empty())
{
cout << "img3 Can't read image '" << endl;
return -1;
}
imshow("图3",img3);
imgs.push_back(img3);
Mat pano;
Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
Stitcher::Status status = stitcher.stitch(imgs, pano);
if (status != Stitcher::OK)
{
cout << "Can't stitch images, error code = " << int(status) << endl;
return -1;
}
imshow("拼接图",pano);
imwrite(result_name, pano);
waitKey();
return 0;
}
运行结果