opencv中的图像拼接

        图像拼接可以实现任意多张平面图像的拼接,可以很好的完成全景图的构建,在opencv中有Stitcher类来实现,废话不多说直接上代码。

#include<opencv2/opencv.hpp>
#include <opencv2/stitching/stitcher.hpp>
#include<opencv2/stitching/warpers.hpp>
#include"1.h"
#include<boost/filesystem.hpp>


using namespace std;
using namespace cv;
using namespace boost::filesystem;


int main()
{
vector<Mat> images;
for (directory_iterator i(DATA_FOLDER_5), end_iter; i != end_iter; i++)
{
string im_name = i->path().filename().string();
string filename = string(DATA_FOLDER_5) + im_name;
Mat im = imread(filename);
if (!im.empty())
{
images.push_back(im);
}
}
cout << "Read" << images.size() << "images" << endl << "Now making panorama..." << endl;
Mat panorama;
Stitcher stitcher = Stitcher::createDefault();
stitcher.stitch(images, panorama);
namedWindow("panorama", CV_WINDOW_NORMAL);
imshow("panorama", panorama);
while (char(waitKey(1) != 'q'))
{


}
return 0;


}

猜你喜欢

转载自blog.csdn.net/qq_29462849/article/details/76638741