将多张图片进行粗暴拼接,没有融合重叠部分的方法
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];
}
}
思路,直接将多个mat的值赋给一个mat
在博客中头文件用尖括号<>会消失,用""
#include "glog/logging.h"
#include "opencv2/opencv.hpp"
//horizontal image concat
void HorizontalMatConcat(const std::vector& src, cv::Mat& dst){
}
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);
}
时间太赶没有调试,有问题可以反馈