本文实例为大家分享了opencv2实现多张图像上下左右拼接融合的具体代码,供大家参考,具体内容如下
在前面的“opencv2两张图像拼接融合_基于SURF特征提取”博文中,实现了两张左右图像的拼接融合,后来我也实现了多张图像的拼接融合。但是opencv2自带一种函数,直接就实现了图像的上下左右拼接。具体程序如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#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; } |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/hanshuning/article/details/41149137