OpenCV 图像拼接总结

 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;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

scott198512

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值