图像拼接(类stitcher 用于图像拼接)

图像拼接类stitcher 

拼接类stitcher 的头文件为:#include "opencv2/stitching/stitcher.hpp"

1、Stitcher::createDefault

使用默认参数创建一个拼接器

C++: Stitcher Stitcher::createDefault(bool try_use_gpu=false)


2、Stitcher::estimateTransform

这些函数尝试匹配给定的图像和去估计每个摄像机的旋转

Note

 

Use the functions only if you’re aware of the stitching pipeline, otherwise use Stitcher::stitch().


注意:只有你熟悉拼接的流程情况使用这个函数,否则使用Stitcher::stitch()

C++:  Status  Stitcher:: estimateTransform (InputArray  images )

C++: Status Stitcher::estimateTransform(InputArray images,const std::vector<std::vector<Rect>>& rois)


3、Stitcher::stitch 这些函数用于拼接给定的图像
C++:  Status  Stitcher:: stitch (InputArray  images, OutputArray  pano )
C++:  Status  Stitcher:: stitch (InputArray  images, const std::vector<std::vector<Rect>>&  rois, OutputArray  pano ) Parameters:images –Input images(输入图像)
rois – Region of interest rectangles(感兴趣矩形区域) pano – Final pano

Returns:Status code.


简单示例

#include <iostream>
#include <fstream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/stitching/stitcher.hpp"
using namespace std;
using namespace cv;
bool try_use_gpu = false;
vector<Mat> imgs; //定义一个Mat类型的向量
string result_name = "result.jpg"; //输出图像的名字
int main(int argc, char* argv[])
{
	Mat img1 = imread("E:\\图片\\图像拼接\\1.jpg");//E:\\图片\\图像拼接\\1.jpg
	if (img1.empty())
	{
		cout << "img1 Can't read image '" << endl;
		return -1;
	}
	imshow("图1",img1);
	imgs.push_back(img1);
	Mat img2=imread("E:\\图片\\图像拼接\\2.jpg");
	if (img2.empty())
	{
		cout << "img2 Can't read image '" << endl;
		return -1;
	}
	imshow("图2",img2);
	imgs.push_back(img2);
	Mat img3=imread("E:\\图片\\图像拼接\\3.jpg");
	if (img3.empty())
	{
		cout << "img3 Can't read image '" << endl;
		return -1;
	}
	imshow("图3",img3);
	imgs.push_back(img3);
    	Mat pano;
    	Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
    	Stitcher::Status status = stitcher.stitch(imgs, pano);
    	if (status != Stitcher::OK)
    	{
        cout << "Can't stitch images, error code = " << int(status) << endl;
        return -1;
    	}
	imshow("拼接图",pano);
    	imwrite(result_name, pano);
	waitKey();
    	return 0;
}

运行结果

 

 



  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值