opencv图像拼接(粗暴)

将多张图片进行粗暴拼接,没有融合重叠部分的方法

思路,直接将多个mat的值赋给一个mat

在博客中头文件用尖括号<>会消失,用""
#include "glog/logging.h"
#include "opencv2/opencv.hpp"

//horizontal image concat 
void HorizontalMatConcat(const std::vector& src, cv::Mat& dst){
   CHECK_GT(src.size(),0) << "Concat image should be more than 0.";
   for(int check_i=0;check_i<(int)src.size()-1;++check_i){
      CHECK_EQ(src[check_i].rows,src[check_i+1].rows) << "Width of concat images should be the same.";
      CHECK_EQ(src[check_i].cols,src[check_i+1].cols) << "Height of concat images should be the same.";     
   }
   const int dst_image_width = (int)src.size()*src[0].cols;
   const int dst_image_height = src[0].rows;
   const int src_image_width = src[0].cols;
   for(int i=0;i
      int k=-1;
      for(int j=0;j
         if(j%src_image_width == 0 and k<(int)src.size()){
            k++;
         }
         dst.at(i,j)[0] = src[k].at(i,j%src_image_width)[0];
         dst.at(i,j)[1] = src[k].at(i,j%src_image_width)[1];
         dst.at(i,j)[2] = src[k].at(i,j%src_image_width)[2];
      }
   }
}


int main(int argc, char** argv){
const int image_height = 100;
const int image_width = 100;

cv::Mat image1 = imread("image1.jpg");
cv::Mat image2 = imread("image2.jpg");

cv::resize(image1, image1,cv::Size(image_width,image_height));
cv::resize(image2, image2,cv::Size(image_width,image_height));

std::vector images;
images.push_back(image1);
images.push_back(image2);

cv::Mat dst_image(image_height,images.size()*image_width,CV_8UC3);
HorizontalMatConcat(images,dst_image);
cv::imshow("dst_image",dst_image);
cv::waitKey(0);
}

时间太赶没有调试,有问题可以反馈
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值