openv版本: opencv249
vs :2010
qt : 4.85
#include "quanjing.h"
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/stitching/stitcher.hpp>
using namespace std;
using namespace cv;
bool try_use_gpu = false;
vector<Mat> imgs;
string result_name = "dst1.jpg";
#include <QApplication>
#include <QMessageBox>
using namespace cv;
quanjing::quanjing(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
connect(ui.pushButton,SIGNAL(clicked()),this,SLOT(btnClick()));
}
void quanjing::btnClick(){
cv::Mat image2 = cv::imread("C:/Users/TR/Desktop/quan/2.jpg");
cv::Mat image3 = cv::imread("C:/Users/TR/Desktop/quan/3.jpg");
cv::Mat image4 = cv::imread("C:/Users/TR/Desktop/quan/4.jpg");
cv::Mat image5 = cv::imread("C:/Users/TR/Desktop/quan/5.jpg");
imgs.push_back(image2);
imgs.push_back(image3);
imgs.push_back(image4);
imgs.push_back(image5);
Stitcher stitcher = Stitcher::createDefault(true);
// 使用stitch函数进行拼接
Mat pano;
Stitcher::Status status = stitcher.stitch(imgs, pano);
if (status != Stitcher::OK)
{
cout << "Can't stitch images, error code = " << int(status) << endl;
QMessageBox::warning(nullptr, "jing gao", QString("Can't stitch images, error code : %1").arg( int(status) ));
}
else
{
imwrite("D:/Test/QT/qt04/quanjing/quanjing/555.jpg", pano);
Mat pano2 = pano.clone();
// 显示源图像,和结果图像
imshow("全景图像1", pano2);
}
}
quanjing::~quanjing()
{
}
准备了四张图像
2 、3 、4三张 进行stitch,结果如下:
3 、4、5三张进行stitch,结果如下:
2、3、4、5 四张一起进行stitch,结果如下:
经过测试,有时候图像序列中某两个连续的出现stitch,错误图像以后的图像就不会再融合了
感觉 opencv的stitch进行图像融合,不太稳定,有时候说不出来为什么两个图像不能融合,肉眼都可以判断出是可以融合的
FR:徐海涛(hunkxu)