OpenCV 进行图像融合拼接

环境:

    运行环境:Win10 x64 

    OpenCV 版本: 4.5.1

源代码:

#include <iostream>
#include <vector>
#include <chrono>
#include <string>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/stitching.hpp>

int main()
{
	const int image_amount{ 5 };
	const std::string parent_dir{ "./image/test/" };
	
	std::vector<cv::Mat> imgs;
	for(int i = 0; i < image_amount - 1; i++)
		imgs.emplace_back(cv::imread(parent_dir + 'p' + std::to_string(i) + ".jpg"));

	cv::Mat res;
	auto stitcher = cv::Stitcher::create();
	auto start = std::chrono::steady_clock::now(); 

	auto status = stitcher->stitch(imgs, res);   // 使用 stitch 函数进行拼接

	auto end = std::chrono::steady_clock::now();
	auto elapsed_seconds = std::chrono::duration<double>(end - start);
	std::cout << "Elapsed time: " << elapsed_seconds.count() << " seconds.\n";

	if (status == cv::Stitcher::OK) {
		cv::imshow("Stitching Result", res);
		cv::imwrite(parent_dir + "result.jpg", res);
	} else {
		std::cout << "Can't stitch images, error code = " << int(status) << std::endl;
		return -1;
	}
	cv::waitKey();
}

素材: 

p0.jpg
p1.jpg
p2.jpg
p3.jpg
p4.jpg

运行结果: 

result.jpg
  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值