最近在做视频拼接,了解到OPENCV自带图像拼接stitcher类,想看看效果。于是就在网上搜了搜stitcher类的用法,发现网上大家发的都来自一篇,或者说都是opencv自带的例子stitching.cpp。这个类当中我们可能用到的成员函数有createDefault、estimateTransform、composePanorama、stitch。但例子只用到createDefault和stitch,实现的例子为:
- Stitcher stitcher = Stitcher::createDefault(false); //不使用GPU加速
- Stitcher::Status status = stitcher.stitch(imgs, pano); //imgs为输入图像组成的vector,pano为拼接结果
因为我做的视频拼接,这样子每次做就太慢了,我想先计算矩阵,以后直接调用,就不知道estimateTransform、composePanorama怎么用,opencv里也没有详细说明。废话不多说了,给出我的使用示例,希望对来者有所帮助,不走弯路。
- #include <stdio.h>
- #include <iostream>
- #include <vector>
- #include "opencv2/highgui/highgui.hpp"
- #include "opencv2/stitching/stitcher.hpp" //stitching 影像拼接
- using namespace cv;
- using namespace std;
- int main()
- {
- IplImage* img_1 = cvLoadImage("3.jpg");
- IplImage* img_2 = cvLoadImage("4.jpg");
- vector<Mat> imgs;
- imgs.push_back(img_1);
- imgs.push_back(img_2);
- //拼接
- Mat pano;
- Stitcher stitcher = Stitcher::createDefault(false);
- stitcher.estimateTransform(imgs);
- //stitcher.composePanorama(pano); //使用之前的图片集imgs
- stitcher.composePanorama(imgs,pano);//可以加入新的图片集imgs(保证与之前的大小数量一致)
- imwrite("stitching image.jpg", pano);
- imshow("拼接",pano);
- waitKey(0);
- return 0;
- }
【世事如此】知道了就简单,不知道就蛋疼!