失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 【OpenCV】3.4.0图像拼接Stitching模块介绍

【OpenCV】3.4.0图像拼接Stitching模块介绍

时间:2021-03-27 02:23:26

相关推荐

【OpenCV】3.4.0图像拼接Stitching模块介绍

Images stitching 是opencv3.4.0中的模块之一,使用此模块可以实现对图像的拼接。在此之前需要编译opencv3.4.0+contrib。具体编译方法可以点此链接。也可以直接下载我编译好的opencv340+contrib的文件直接配置,配置方法与opencv一样。

具体内容可以参考sitiching的官方帮助文档。

Image Stitching 模块下共包含七个子模块,分别为:

Features Finding and Images Matching 功能查找和图像匹配Rotation Estimation 轮换估计Autocalibration 自动校准Images Warping 图像变形Seam Estimation 接缝估计Exposure Compensation 曝光补偿Image Blenders 图像搅拌机

我们先来看一下cv::stitcher这个类,该类包含在头文件opencv2/stitching.hpp中,其所有的成员函数如下:

先来看一个简单的实例:

#include <iostream>#include <opencv2/core/core.hpp>#include <opencv2/highgui/highgui.hpp>#include <opencv2/imgproc/imgproc.hpp>#include <opencv2/stitching.hpp>#include "windows.h"using namespace std;using namespace cv;bool try_use_gpu = false;vector<Mat> imgs;string result_name = "dst1.jpg";int main(int argc, char * argv[]){Mat img1 = imread("33.jpg");Mat img2 = imread("34.jpg");imshow("p1", img1);imshow("p2", img2);long t0 = GetTickCount();if (img1.empty() || img2.empty()){cout << "Can't read image" << endl;return -1;}imgs.push_back(img1);imgs.push_back(img2);Stitcher stitcher = Stitcher::createDefault(try_use_gpu);// 使用stitch函数进行拼接Mat pano;Stitcher::Status status = stitcher.stitch(imgs, pano);if (status != Stitcher::OK){cout << "Can't stitch images, error code = " << int(status) << endl;return -1;}long t1 = GetTickCount();imwrite(result_name, pano);Mat pano2 = pano.clone();// 显示源图像,和结果图像imshow("全景图像", pano);cout << "Time: "<<t1 - t0 << endl;if (waitKey() == 27)return 0;}

通过结果可以看出直接使用stitching函数进行拼接是比较耗时的。这个简单的例子主要使用了两个函数,分别为:

stitch函数的返回值是一个状态,并将拼接完成的图片存在 pano中

如果觉得《【OpenCV】3.4.0图像拼接Stitching模块介绍》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。