1. 程式人生 > 實用技巧 >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 }

結果如下:

經裁剪,即可得到一幅全新的全景畫面: