索引地址:系列索引
所谓图像拼接,就是将几幅图像中的重复部分合并并生成一幅新的完整的图像。
最常见的应用就是长屏截图和全景拍摄。
测试代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/features2d/features2d.hpp> #include <opencv2/xfeatures2d/nonfree.hpp> #include <opencv2/calib3d/calib3d.hpp> #include <opencv2/stitching.hpp> #include <iostream> #include <vector> using namespace std; using namespace cv;
int main(int argc, char* argv[]) { cv::Mat image1 = imread("1.png"); cv::Mat image2 = imread("2.png"); cv::Mat image3 = imread("3.png"); if (!image1.data || !image2.data || !image3.data) return -1; vector<Mat> imgs; imgs.push_back(image1); imgs.push_back(image2); imgs.push_back(image3);
cv::Mat resultMat; cv::Ptr stitcher = Stitcher::create(Stitcher::PANORAMA); Stitcher::Status status = stitcher->stitch(imgs, resultMat); if (status != Stitcher::OK) { std::cout << "error" << std::endl; } cv::imshow("resultMat1", resultMat); cv::waitKey(0); return 0; }
|
原始图片为



拼接效果为

可以看到有部分内容被忽略了。