图像拼接Stitcher中estimateTransform、composePanorama函数用法

最近在做视频拼接,了解到OPENCV自带图像拼接stitcher类,想看看效果。于是就在网上搜了搜stitcher类的用法,发现网上大家发的都来自一篇,或者说都是opencv自带的例子stitching.cpp。这个类当中我们可能用到的成员函数有createDefault、estimateTransform、composePanorama、stitch。但例子只用到createDefaultstitch,实现的例子为:

  1.   Stitcher stitcher = Stitcher::createDefault(false);  //不使用GPU加速
  2.   Stitcher::Status status = stitcher.stitch(imgs, pano);  //imgs为输入图像组成的vector,pano为拼接结果

因为我做的视频拼接,这样子每次做就太慢了,我想先计算矩阵,以后直接调用,就不知道estimateTransform、composePanorama怎么用,opencv里也没有详细说明。废话不多说了,给出我的使用示例,希望对来者有所帮助,不走弯路。

  1. #include   
  2. #include   
  3. #include   
  4.   
  5. #include "opencv2/highgui/highgui.hpp"  
  6. #include "opencv2/stitching/stitcher.hpp"  //stitching 影像拼接  
  7. using namespace cv;  
  8. using namespace std;  
  9.   
  10. int main()  
  11.   
  12. {  
  13.   
  14.    IplImage* img_1 = cvLoadImage("3.jpg");  
  15.    IplImage* img_2 = cvLoadImage("4.jpg");  
  16.     
  17.    vector imgs;  
  18.      
  19.    imgs.push_back(img_1);  
  20.    imgs.push_back(img_2);  
  21.     //拼接  
  22.   
  23.   Mat pano;  
  24.   Stitcher stitcher = Stitcher::createDefault(false);  
  25.   stitcher.estimateTransform(imgs);
  26.    //stitcher.composePanorama(pano); //使用之前的图片集imgs
  27.    stitcher.composePanorama(imgs,pano);//可以加入新的图片集imgs(保证与之前的大小数量一致)
  28.   imwrite("stitching image.jpg", pano);  
  29.   imshow("拼接",pano);  
  30.   waitKey(0);  
  31.   return 0;  
  32. }


图像拼接Stitcher中estimateTransform、composePanorama函数用法_第1张图片图像拼接Stitcher中estimateTransform、composePanorama函数用法_第2张图片图像拼接Stitcher中estimateTransform、composePanorama函数用法_第3张图片


【世事如此】知道了就简单,不知道就蛋疼!

你可能感兴趣的:(图像拼接,opencv,图像拼接,stitching)