openCV 图像拼接-全景图像

图像拼接,就是将多张图片拼接成一个大图,类似手机里的全景照片。按照某大神的思路,可以自己按照如下步骤实现:

  1. 对每幅图进行特征点提取
  2. 对对特征点进行匹配
  3. 进行图像配准
  4. 把图像拷贝到另一幅图像的特定位置
  5. 对重叠边界进行特殊处理

不过openCV已经提供了现成的函数(stitch)类实现此功能,此函数的特点就是慢,有多慢呢,我用手机拍了四张图片,中午睡一觉后,还没有拼接完成。于是换成了两张较小的图片,效果还是可以的。

#include "stdafx.h"
#include 
#include   
#include   
#include  
#include 
#include 
#include 
#include < opencv2\stitching.hpp >

using namespace std;
using namespace cv;
bool try_use_gpu = true;


int main(int argc, char * argv[])
{
	vector srcImgs;
	Mat dstImage;
	srcImgs.push_back(cv::imread("images/1.png"));
	srcImgs.push_back(cv::imread("images/2.png"));
	//srcImgs.push_back(cv::imread("images/3.jpg"));
	//srcImgs.push_back(cv::imread("images/4.jpg"));


	Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
	// 使用stitch函数进行拼接
	Stitcher::Status status = stitcher.stitch(srcImgs, dstImage);
	if (status != Stitcher::OK)
	{
		cout << "Can't stitch images, error code = " << int(status) << endl;
		return -1;
	}
	
	imwrite("my.jpg", dstImage);
	imshow("全景图像", dstImage);
	if (waitKey() == 27)
		return 0;
}

原图:

openCV 图像拼接-全景图像_第1张图片openCV 图像拼接-全景图像_第2张图片

效果图:

openCV 图像拼接-全景图像_第3张图片

 

参考:https://www.cnblogs.com/skyfsm/p/7411961.html

你可能感兴趣的:(C++)