0.概述
对几张不同的图像进行拼接处理得到一张图像。
1.方法对比
2.代码实现
// png_stitcher.cpp
#include <iostream>
#include <stdio.h>
#include <opencv2/stitching.hpp>
#include <opencv2/opencv.hpp>
#include <fstream>
using namespace cv;
using namespace std;
int main()
{
cv::Scalar COLOR_RED(0, 0, 255);
cv::Scalar COLOR_BLUE(255, 0, 0);
cv::Scalar COLOR_GREEN(0, 255, 0);
cv::Scalar COLOR_PURPLE(128, 0, 128);
cv::Scalar COLOR_DARKGREEN(0, 100, 0);
cv::Scalar COLOR_WHITE(255, 255, 255);
vector<Mat> imgs;
// Mat image1,image2;
Mat image0 = imread("../png/images0.png");
Mat image1 = imread("../png/images1.png");
Mat image2 = imread("../png/images2.png");
Mat image3 = imread("../png/images3.png");
Mat image4 = imread("../png/images4.png");
if (image0.empty() || image1.empty()|| image2.empty()|| image3.empty()|| image4.empty())
{
cout << "Can't read image" << endl;
return -1;
}
resize(image0, image0, Size(600, 450), 0, 0, INTER_LINEAR);//图片是截取的,所以使用resize做了尺寸修改
resize(image1, image1, Size(600, 450), 0, 0, INTER_LINEAR);//图片是截取的,所以使用resize做了尺寸修改
resize(image2, image2, Size(600, 450), 0, 0, INTER_LINEAR);
resize(image3, image3, Size(600, 450), 0, 0, INTER_LINEAR);//图片是截取的,所以使用resize做了尺寸修改
resize(image4, image4, Size(600, 450), 0, 0, INTER_LINEAR);
imshow("原图0", image0);
imshow("原图1", image1);
imshow("原图2", image2);
imshow("原图3", image3);
imshow("原图4", image4);
imgs.push_back(image0);
imgs.push_back(image1);
imgs.push_back(image2);
imgs.push_back(image3);
imgs.push_back(image4);
Ptr<Stitcher> stitcher = Stitcher::create();//调用create方法
Mat pano;
Stitcher::Status status = stitcher->stitch(imgs, pano); // 使用stitch函数进行拼接
if (status != Stitcher::OK)
{
cout << "Can't stitch images, error code = " << int(status) << endl;
return -1;
}
// 显示结果图像
imshow("全景图像", pano);
waitKey(0);
return 0;
}