您的位置:首页 > 运维架构

opencv自带之图像拼接

2017-09-07 13:55 253 查看
看效果:

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: