opencv2图像拼接融合 opencv2实现10张图像上下左右拼接融合
米姒翰 人气:0在前面的“opencv2两张图像拼接融合_基于SURF特征提取”博文中,实现了两张左右图像的拼接融合,后来我也实现了多张图像的拼接融合。但是opencv2自带一种函数,直接就实现了图像的上下左右拼接。具体程序如下:
#include <iostream> #include<vector> #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; string result_name = "result.jpg"; int main(int argc, char* argv[]) //int _tmain(int argc, _TCHAR* argv[]) { // 读取图像 /*Mat img1 = imread("img1.jpg"); Mat img2 = imread("img2.jpg"); Mat img3 = imread("img3.jpg");*/ 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; 因为老师给的图像太大,先处理下。处理后的图像存放在imagei中。 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; }
加载全部内容