【OpenCV】3.4.0影象拼接Stitching模組介紹
阿新 • • 發佈:2019-01-27
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中