Opencv 使用Stitcher类图像拼接生成全景图像

Opencv中自带的Stitcher类可以实现全景图像,效果不错。下边的例子是Opencv Samples中的stitching.cpp的简化,源文件可以在这个路径里找到:

\opencv\sources\samples\cpp\stitching.cpp


#include <fstream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/stitching/stitcher.hpp"
#include <iostream>

using namespace cv;
using namespace std;

vector<Mat> imgs; //保存拼接的原始图像向量

//导入所有原始拼接图像函数
void parseCmdArgs(int argc, char** argv);

int main(int argc, char* argv[])
{
	//导入拼接图像
	parseCmdArgs(argc, argv);	
	Mat pano;
	Stitcher stitcher = Stitcher::createDefault(false);
	Stitcher::Status status = stitcher.stitch(imgs, pano);//拼接
	if (status != Stitcher::OK) //判断拼接是否成功
	{
		cout << "Can't stitch images, error code = " << int(status) << endl;
		return -1;
	}
	namedWindow("全景拼接",0);
	imshow("全景拼接",pano);
	imwrite("D:\\全景拼接.jpg",pano);
	waitKey();   
	return 0;
}

//导入所有原始拼接图像函数
void parseCmdArgs(int argc, char** argv)
{
	for(int i=1;i<argc;i++)
	{
		Mat img = imread(argv[i]);
		if (img.empty())
		{
			cout << "Can't read image '" << argv[i] << "'\n";
		}
		imgs.push_back(img);
	}
}


图1:


图2:


图3:


图4:


图5:



5个图片的拍摄角度合起来在180°左右,没有经过压缩的,下载下来可以直接测试使用,传入顺序随意,Stitcher会自动排列。全景拼接效果很赞:



  • 13
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 13
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值