opencv自带之图像拼接
程序员文章站
2022-05-16 10:37:20
...
看效果:
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;
}
上一篇: vue项目结构(详细教程)
下一篇: opencv(六):图像拼接