欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

opencv,c++图像拼接

程序员文章站 2022-05-16 10:38:14
...

使用opencv里的stitcher进行拼接

#include <stdio.h>
#include <iostream>
#include <sstream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/legacy/legacy.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include <opencv2/stitching/stitcher.hpp>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
	Mat pano;
	vector<Mat>imgs;
	string tem;
	string Input = "D:\\image\\";//读取图片
	for (int Num = 0; Num < 10; Num++)//文件夹里前10张图
	{
		//直接使用to_string()函数
		string output = Input + to_string(Num) + ".bmp";
		Mat image = imread(output);
		tem.clear();
		imgs.push_back(image);
	}

	double t1 = (double)cvGetTickCount();
	Stitcher stitcher = Stitcher::createDefault(false);
	Stitcher::Status status = stitcher.stitch(imgs, pano);
	double t2 = (double)cvGetTickCount();
	double t;
	t = (t2 - t1) / (cvGetTickFrequency() * 1000);//拼接处理时间
	cout << "图像拼接处理时间为: " << t << "ms" << endl;
	imgs.clear();
	imshow("resultMat1", pano);
	imwrite(out + "0.bmp", pano);
	waitKey(0);
	return 0;

}
相关标签: opencv