其他分享
首页 > 其他分享> > OpenCV Stitcher图像拼接

OpenCV Stitcher图像拼接

作者:互联网

OpenCV3中提供了一个用于图像拼接的模块——Stitcher,可以将连续拍摄的图像序列,拼接成一幅全景画面。

如下所示是56幅连续拍摄的图像:

0.png

1.png

2.png

3.png

4.png

处理代码如下:



 1 #include < stdio.h >  
 2 #include < opencv2\opencv.hpp >  
 3 #include < opencv2\stitching.hpp >
 4  
 5  
 6 int main()
 7 {
 8     std::vector< cv::Mat > vImg;
 9     cv::Mat rImg;
10  
11     vImg.push_back(cv::imread("images0/0.png"));
12     vImg.push_back(cv::imread("images0/1.png"));
13     vImg.push_back(cv::imread("images0/2.png"));
14     vImg.push_back(cv::imread("images0/3.png"));
15     vImg.push_back(cv::imread("images0/4.png"));
16  
17     cv::Stitcher stitcher = cv::Stitcher::createDefault();
18  
19     unsigned long AAtime = 0, BBtime = 0; //check processing time
20     AAtime = cv::getTickCount(); //check processing time
21  
22     cv::Stitcher::Status status = stitcher.stitch(vImg, rImg);
23  
24     BBtime = cv::getTickCount(); //check processing time 
25     printf("Time consuming: %.2lf sec \n", (BBtime - AAtime) / cv::getTickFrequency()); //check processing time
26  
27     if (cv::Stitcher::OK == status)
28         cv::imshow("Stitching Result", rImg);
29     else
30         printf("Stitching fail.");
31  
32     cv::waitKey(0);
33 }

结果如下:

经裁剪,即可得到一幅全新的全景画面:

标签:vImg,back,OpenCV,拼接,Stitcher,imread,cv,png
来源: https://www.cnblogs.com/ybqjymy/p/14179398.html