利用 opencv stitch 进行图形拼接

#include <iostream>
#include <fstream>
#include <opencv2/core/core.hpp>
#include "opencv2/highgui/highgui.hpp"
#include<opencv2/stitching.hpp>
#include<Windows.h>

using namespace std;
using namespace cv;

bool try_use_gpu = false;
vector<Mat> imgs;
string result_name = "result.jpg";

int main()
{
	Mat img1 = imread("1.jpg");
	Mat img2 = imread("2.jpg");
	Mat img3 = imread("3.jpg");
	Mat img4 = imread("4.jpg");


	imgs.push_back(img1);
	imgs.push_back(img2);
	imgs.push_back(img3);
	imgs.push_back(img4);

	Mat pano;
	Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
	Stitcher::Status status = stitcher.stitch(imgs, pano);
	if (status != Stitcher::OK)
	{
		cout << "Can't stitch images, error code = " << status << endl;
		return -1;
	}
	namedWindow(result_name);
	imshow(result_name, pano);
	imwrite(result_name, pano);
	waitKey();
	return 0;
}

主要代码:

Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
Stitcher::Status status = stitcher.stitch(imgs, pano);

Stitcher是OpenCV的一个类,其中实现了图像拼接

可以看出这个过程很复杂,需要涉及到很多的算法,比如:特征点的提取、特征点匹配、图像融合等等。这些过程OpenCV都为我们封装在Stitcher类中,不在此细述。

缺点:实时性不高

本人使用自己拍摄的图像进行测试时,效果不佳

参考网址:https://www.cnblogs.com/wyuzl/p/7676691.html

猜你喜欢

转载自blog.csdn.net/SenPaul/article/details/83040316