本文章已收录于:

作者同类文章
X
版权声明:本文为博主原创文章,未经博主允许不得转载。
开始尝试merge函数,具体如下:
定义四个矩阵A,B,C,D。得到矩阵combine。
- <span style="font-size:18px">#include<iostream>
- #include <core/core.hpp>
- #include <opencv2/imgproc/imgproc.hpp>
- #include <opencv2/highgui/highgui.hpp>
- using namespace std;
- using namespace cv;
- int main()
- {
- cv::Mat a = (cv::Mat_<int>(2,2)<<1,2,3,4);
- cv::Mat b = (cv::Mat_<int>(2,2)<<5,6,7,8);
- cv::Mat c = (cv::Mat_<int>(2,2)<<9,10,11,12);
- cv::Mat d = (cv::Mat_<int>(2,2)<<13,14,15,16);
- std::vector<cv::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=" <<combine<< endl;
- cout<<"Size of combine:"<<combine.size()<<endl;
- system("pause");
- return 0;
- }</span>
#include<iostream>
#include <core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
cv::Mat a = (cv::Mat_<int>(2,2)<<1,2,3,4);
cv::Mat b = (cv::Mat_<int>(2,2)<<5,6,7,8);
cv::Mat c = (cv::Mat_<int>(2,2)<<9,10,11,12);
cv::Mat d = (cv::Mat_<int>(2,2)<<13,14,15,16);
std::vector<cv::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=" <<combine<< endl;
cout<<"Size of combine:"<<combine.size()<<endl;
system("pause");
return 0;
}
结果如下:
显然,不是我们需要的结果。
尝试hconcat和vconcat函数,这两个函数OpenCV本身并没有。
具体实现如下:
- <span style="font-size:18px">#include <iostream>
- #include <core/core.hpp>
- #include <opencv2/imgproc/imgproc.hpp>
- #include <opencv2/highgui/highgui.hpp>
- using namespace std;
- using namespace cv;
- int main()
- {
- cv::Mat a = (cv::Mat_<int>(2,2)<<1,2,3,4);
- cv::Mat b = (cv::Mat_<int>(2,2)<<5,6,7,8);
- cv::Mat c = (cv::Mat_<int>(2,2)<<9,10,11,12);
- cv::Mat d = (cv::Mat_<int>(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<<"Combine=:"<<combine<<endl;
- system("pause");
- return 0;
- }</span>
#include <iostream>
#include <core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
cv::Mat a = (cv::Mat_<int>(2,2)<<1,2,3,4);
cv::Mat b = (cv::Mat_<int>(2,2)<<5,6,7,8);
cv::Mat c = (cv::Mat_<int>(2,2)<<9,10,11,12);
cv::Mat d = (cv::Mat_<int>(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<<"Combine=:"<<combine<<endl;
system("pause");
return 0;
}
结果:
图像拼接实现
- #include <iostream>
- #include <core/core.hpp>
- #include <opencv2/imgproc/imgproc.hpp>
- #include <opencv2/highgui/highgui.hpp>
- using namespace std;
- using namespace cv;
- int main()
- {
- //cv::Mat a = (cv::Mat_<int>(2,2)<<1,2,3,4);
- //cv::Mat b = (cv::Mat_<int>(2,2)<<5,6,7,8);
- //cv::Mat c = (cv::Mat_<int>(2,2)<<9,10,11,12);
- //cv::Mat d = (cv::Mat_<int>(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<<"Combine=:"<<combine<<endl;
- system("pause");
- return 0;
- }
#include <iostream>
#include <core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
//cv::Mat a = (cv::Mat_<int>(2,2)<<1,2,3,4);
//cv::Mat b = (cv::Mat_<int>(2,2)<<5,6,7,8);
//cv::Mat c = (cv::Mat_<int>(2,2)<<9,10,11,12);
//cv::Mat d = (cv::Mat_<int>(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<<"Combine=:"<<combine<<endl;
system("pause");
return 0;
}
图像结果显示如下:
-
顶
- 0
-
踩
- 0
- 上一篇我的优快云博客之旅
- 下一篇opencv保存图像自动命名
我的同类文章
http://blog.youkuaiyun.com
- •图像处理形态学椭圆形模板结构元素的设计与实现2015-08-25
- •OpenCV重复播放摄像头视频,循环播放摄像头(视频)文件,循环播放视频中某一段视频2014-12-02
- •OpenCV读取多幅图片,读取系列图片,读取文件夹中指定图像类型的系列图片2014-11-30
- •边缘检测——Sobel2014-11-24
- •利用OpenCV实现——目标跟踪方法(一)2014-08-30
- •OpenCV遍历文件夹中所有图像2014-03-10
- •OpenCV Viz 3D虚拟空间模块2015-04-30
- •OpenCV搜索文件夹中的图片并保存图片路径和信息2014-11-30
- •OpenCV图像几何变换——转置,镜像,倒置2014-11-30
- •直方图均衡化2014-11-02
- •保存OpenCV中Mat_<Vec3f>格式的图像2014-04-14