Opencv stitcher图像无缝拼接生成全景图像(四)

转自:https://blog.csdn.net/hanshuning/article/details/41149137?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_title~default-0.no_search_link&spm=1001.2101.3001.4242.1

#include
#include
#include
#include “opencv2/highgui/highgui.hpp”
#include “opencv2/stitching/stitcher.hpp”

using namespace std;
using namespace cv;

bool try_use_gpu = false;
vector imgs;
string result_name = “result.jpg”;
int main()
{
Mat image11= imread(“1.jpg”);
Mat image22= imread(“2.jpg”);
Mat image33= imread(“3.jpg”);
Mat image44= imread(“4.jpg”);
Mat image55= imread(“5.jpg”);
Mat image66= imread(“6.jpg”);
Mat image77= imread(“7.jpg”);
Mat image88= imread(“8.jpg”);
Mat image99= imread(“9.jpg”);
Mat image1010= imread(“10.jpg”);
if (!image11.data || !image22.data|| !image33.data|| !image44.data|| !image55.data
|| !image66.data|| !image77.data|| !image88.data|| !image99.data|| !image1010.data
)
return 0;

Mat image1;
Mat image2;
Mat image3;
Mat image4;
Mat image5;
Mat image6;
Mat image7;
Mat image8;
Mat image9;
Mat image10;
resize(image11,image1,Size(400,300),0,0,CV_INTER_LINEAR); 
resize(image22,image2,Size(400,300),0,0,CV_INTER_LINEAR); 
resize(image33,image3,Size(400,300),0,0,CV_INTER_LINEAR); 
resize(image44,image4,Size(400,300),0,0,CV_INTER_LINEAR); 
resize(image55,image5,Size(400,300),0,0,CV_INTER_LINEAR); 
resize(image66,image6,Size(400,300),0,0,CV_INTER_LINEAR); 
resize(image77,image7,Size(400,300),0,0,CV_INTER_LINEAR); 
resize(image88,image8,Size(400,300),0,0,CV_INTER_LINEAR); 
resize(image99,image9,Size(400,300),0,0,CV_INTER_LINEAR); 
resize(image1010,image10,Size(400,300),0,0,CV_INTER_LINEAR); 

imgs.push_back(image1);
imgs.push_back(image2);
imgs.push_back(image3);
imgs.push_back(image4);
imgs.push_back(image5);
imgs.push_back(image6);
imgs.push_back(image7);
imgs.push_back(image8);
imgs.push_back(image9);
imgs.push_back(image10);

// 调用createDefault函数生成默认的参数
Stitcher stitcher = Stitcher::createDefault(try_use_gpu);

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

// 保存结果图像
imwrite(result_name, pano);

// 显示源图像,和结果图像

imshow(“全景图像”, pano);

waitKey(0);
return 0;
}

测试原图
Opencv stitcher图像无缝拼接生成全景图像(四)_第1张图片
Opencv stitcher图像无缝拼接生成全景图像(四)_第2张图片
Opencv stitcher图像无缝拼接生成全景图像(四)_第3张图片
Opencv stitcher图像无缝拼接生成全景图像(四)_第4张图片
Opencv stitcher图像无缝拼接生成全景图像(四)_第5张图片
全景拼接:

拼接要很久,还以为卡死了,几十秒才出来,这个只适合静态图片拼接,不适合实时视频拼接。

Opencv stitcher图像无缝拼接生成全景图像(四)_第6张图片

还可以。

你可能感兴趣的:(图像处理,opcv,opencv,计算机视觉,深度学习)