opencv自带之图像拼接

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_29540745/article/details/77880541

看效果:

vs2013+opencv3.0

#include <iostream>
#include <fstream>
#include<opencv2/opencv.hpp>
#include "opencv2/stitching.hpp"
#include "time.h"

using namespace std;
using namespace cv;

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


int main(int argc, char* argv[])
{
	Mat img = imread("1.jpg");
	resize(img,img, Size(500, 250), 0, 0, CV_INTER_LINEAR);
	imgs.push_back(img);
	img = imread("2.jpg");
	resize(img, img, Size(500, 250), 0, 0, CV_INTER_LINEAR);
	imgs.push_back(img);
	img = imread("3.jpg");
	resize(img, img, Size(500, 250), 0, 0, CV_INTER_LINEAR);
	imgs.push_back(img);
	double start = static_cast<double>(getTickCount());

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

	double time = ((double)getTickCount() - start) / getTickFrequency();

	cout << "用时" << time << "秒" << endl;
	if (status != Stitcher::OK)
	{
		cout << "Can't stitch images, error code = " << int(status) << endl;
		return -1;
	}
	resize(pano, pano, Size(750,250), 0, 0, CV_INTER_LINEAR);

	imshow("拼接图", pano);
	imwrite(result_name, pano);
	waitKey(0);
	return 0;
}









猜你喜欢

转载自blog.csdn.net/qq_29540745/article/details/77880541