发布时间:2022-08-19 11:27
原图像如下图所示,第一张图像的右侧与第二张图像的左侧有重合区域,通过图像拼接将两张图合成一张图。使用OpenCV的Stitcher函数实现。
完整代码如下,亲测可用。
#include < stdio.h >
#include < opencv2\opencv.hpp >
#include < opencv2\stitching.hpp >
int main()
{
std::vector< cv::Mat > vImg;
cv::Mat rImg;
vImg.push_back(cv::imread("xiaoyuan1.bmp"));
vImg.push_back(cv::imread("xiaoyuan2.bmp"));
cv::Stitcher::Mode mode = cv::Stitcher::PANORAMA;
cv::Ptr stitcher = cv::Stitcher::create(mode);
unsigned long AAtime = 0, BBtime = 0; //check processing time
AAtime = cv::getTickCount(); //check processing time
cv::Mat mergeImage;
bool status = stitcher->stitch(vImg, mergeImage);
BBtime = cv::getTickCount(); //check processing time
printf("Time consuming: %.2lf sec \n", (BBtime - AAtime) / cv::getTickFrequency()); //check processing time
if (cv::Stitcher::OK == status)
cv::imshow("Stitching Result", mergeImage);
else
printf("Stitching fail.");
cv::waitKey(0);
}