C++(opencv)简单拼接两幅图像

        原图像如下图所示,第一张图像的右侧与第二张图像的左侧有重合区域,通过图像拼接将两张图合成一张图。使用OpenCV的Stitcher函数实现。

           C++(opencv)简单拼接两幅图像_第1张图片C++(opencv)简单拼接两幅图像_第2张图片

          C++(opencv)简单拼接两幅图像_第3张图片

 完整代码如下,亲测可用。

#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);
}

 

 

 

 

 

你可能感兴趣的:(c++)