opencv4.3 Stitcher图像拼接方法——学习笔记1

鉴于opencv2和3版本Sticher图像拼接方法在4版本不能用的情况,我们对其进行改进,但是Sticher拼接对重合比较明显的可以拼接,不明显的拼接红外图像会报错。

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include<opencv2/stitching.hpp>

#include <opencv.hpp>
using namespace std;
using namespace cv;
bool try_use_gpu = false;
vector<Mat> imgs;
Stitcher::Mode mode = Stitcher::PANORAMA;
string result_name = "dst1.jpg";
int main(int argc, char * argv[])
{
	Mat img1 = imread("7.jpg");
	Mat img2 = imread("8.jpg");
	Mat dst1;
	imshow("p1", img1);
	imshow("p2", img2);
	/*hconcat(img1, img2, dst1);//水平拼接
	imshow("dst1", dst1);*/
	if (img1.empty() || img2.empty())
	{
		cout << "Can't read image" << endl;
		return -1;
	}
	imgs.push_back(img1);
	imgs.push_back(img2);

	Mat pano;
	Ptr<Stitcher> stitcher = Stitcher::create(mode);
	Stitcher::Status status = stitcher->stitch(imgs, pano);
	// 使用stitch函数进行拼接
	if (status != Stitcher::OK)
	{
		cout << "Can't stitch images, error code = " << int(status) << endl;
		return -1;
	}
	imwrite(result_name, pano);
	Mat pano2 = pano.clone();
	// 显示源图像,和结果图像
	imshow("全景图像", pano);
	if (waitKey() == 27)
		return 0;
}

 

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页