这篇文章给大家介绍怎么在Opencv使用Stitcher类拼接图像,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
Opencv中自带的Stitcher类可以实现全景图像,效果不错。下边的例子是Opencv Samples中的stitching.cpp的简化,源文件可以在这个路径里找到:
\opencv\sources\samples\cpp\stitching.cpp
#include <fstream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/stitching/stitcher.hpp"
#include <iostream>
using namespace cv;
using namespace std;
vector<Mat> imgs; //保存拼接的原始图像向量
//导入所有原始拼接图像函数
void parseCmdArgs(int argc, char** argv);
int main(int argc, char* argv[])
{
//导入拼接图像
parseCmdArgs(argc, argv);
Mat pano;
Stitcher stitcher = Stitcher::createDefault(false);
Stitcher::Status status = stitcher.stitch(imgs, pano);//拼接
if (status != Stitcher::OK) //判断拼接是否成功
{
cout << "Can't stitch images, error code = " << int(status) << endl;
return -1;
}
namedWindow("全景拼接",0);
imshow("全景拼接",pano);
imwrite("D:\\全景拼接.jpg",pano);
waitKey();
return 0;
}
//导入所有原始拼接图像函数
void parseCmdArgs(int argc, char** argv)
{
for(int i=1;i<argc;i++)
{
Mat img = imread(argv[i]);
if (img.empty())
{
cout << "Can't read image '" << argv[i] << "'\n";
}
imgs.push_back(img);
}
}
关于怎么在Opencv使用Stitcher类拼接图像就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。