赞
踩
本文实例为大家分享了OpenCV实现多图像拼接成大图的具体代码,供大家参考,具体内容如下
开始尝试merge函数,具体如下:
定义四个矩阵A,B,C,D。得到矩阵combine。
#include
#include
#include
#include
using namespace std;
using namespace cv;
int main()
{
cv::Mat a = (cv::Mat_(2,2)<<1,2,3,4);
cv::Mat b = (cv::Mat_(2,2)<<5,6,7,8);
cv::Mat c = (cv::Mat_(2,2)<<9,10,11,12);
cv::Mat d = (cv::Mat_(2,2)<<13,14,15,16);
std::vector<:mat> v1;
v1.push_back(a);
v1.push_back(b);
v1.push_back(c);
v1.push_back(d);
cv::Mat combine;
cv::merge(v1, combine);
cout << "combine=" <
cout<
system("pause");
return 0;
}
结果如下:
显然,不是我们需要的结果。
尝试hconcat和vconcat函数,这两个函数opencv本身并没有。
具体实现如下:
#include
#include
#include
#include
using namespace std;
using namespace cv;
int main()
{
cv::Mat a = (cv::Mat_(2,2)<<1,2,3,4);
cv::Mat b = (cv::Mat_(2,2)<<5,6,7,8);
cv::Mat c = (cv::Mat_(2,2)<<9,10,11,12);
cv::Mat d = (cv::Mat_(2,2)<<13,14,15,16);
Mat combine,combine1,combine2;
hconcat(a,b,combine1);
hconcat(c,d,combine2);
vconcat(combine1,combine2,combine);
//namedWindow("Combine",CV_WINDOW_AUTOSIZE);
//imshow("Combine",combine);
cout<
system("pause");
return 0;
}
结果:
图像拼接实现
#include
#include
#include
#include
using namespace std;
using namespace cv;
int main()
{
//cv::Mat a = (cv::Mat_(2,2)<<1,2,3,4);
//cv::Mat b = (cv::Mat_(2,2)<<5,6,7,8);
//cv::Mat c = (cv::Mat_(2,2)<<9,10,11,12);
//cv::Mat d = (cv::Mat_(2,2)<<13,14,15,16);
Mat combine,combine1,combine2;
Mat a=imread("1.jpg");
Mat b=imread("2.jpg");
Mat c=imread("3.jpg");
Mat d=imread("4.jpg");
hconcat(a,b,combine1);
hconcat(c,d,combine2);
vconcat(combine1,combine2,combine);
namedWindow("Combine",CV_WINDOW_AUTOSIZE);
imshow("Combine",combine);
waitKey(0);
//cout<
system("pause");
return 0;
}
图像结果显示如下:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。